1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Oracle Corporation code.
18 * The Initial Developer of the Original Code is
20 * Portions created by the Initial Developer are Copyright (C) 2004
21 * the Initial Developer. All Rights Reserved.
24 * Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
25 * Shawn Wilsher <me@shawnwilsher.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
44 #include "mozStorageStatementWrapper.h"
52 ** mozStorageStatementRow
54 class mozStorageStatementRow
: public mozIStorageStatementRow
,
55 public nsIXPCScriptable
58 mozStorageStatementRow(mozIStorageStatement
*aStatement
,
60 const nsStringArray
*aColumnNames
);
62 // nsISupports interface
65 // mozIStorageStatementRow interface (empty)
66 NS_DECL_MOZISTORAGESTATEMENTROW
68 // nsIXPCScriptable interface
69 NS_DECL_NSIXPCSCRIPTABLE
71 sqlite3_stmt
* NativeStatement() {
72 return mStatement
->GetNativeStatementPointer();
75 nsCOMPtr
<mozIStorageStatement
> mStatement
;
77 const nsStringArray
*mColumnNames
;
81 ** mozStorageStatementParams
83 class mozStorageStatementParams
: public mozIStorageStatementParams
,
84 public nsIXPCScriptable
87 mozStorageStatementParams(mozIStorageStatement
*aStatement
);
91 NS_DECL_MOZISTORAGESTATEMENTPARAMS
92 NS_DECL_NSIXPCSCRIPTABLE
95 nsCOMPtr
<mozIStorageStatement
> mStatement
;
100 JSValStorageStatementBinder (JSContext
*cx
,
101 mozIStorageStatement
*aStatement
,
105 if (JSVAL_IS_INT(val
)) {
106 int v
= JSVAL_TO_INT(val
);
107 (void)aStatement
->BindInt32Parameter(aIdx
, v
);
108 } else if (JSVAL_IS_DOUBLE(val
)) {
109 double d
= *JSVAL_TO_DOUBLE(val
);
110 (void)aStatement
->BindDoubleParameter(aIdx
, d
);
111 } else if (JSVAL_IS_STRING(val
)) {
112 JSString
*str
= JSVAL_TO_STRING(val
);
113 (void)aStatement
->BindStringParameter(aIdx
, nsDependentString(reinterpret_cast<PRUnichar
*>(JS_GetStringChars(str
)), JS_GetStringLength(str
)));
114 } else if (JSVAL_IS_BOOLEAN(val
)) {
115 (void)aStatement
->BindInt32Parameter(aIdx
, (val
== JSVAL_TRUE
) ? 1 : 0);
116 } else if (JSVAL_IS_NULL(val
)) {
117 (void)aStatement
->BindNullParameter(aIdx
);
118 } else if (JSVAL_IS_OBJECT(val
)) {
119 JSObject
*obj
= JSVAL_TO_OBJECT(val
);
120 // some special things
121 if (js_DateIsValid (cx
, obj
)) {
122 double msecd
= js_DateGetMsecSinceEpoch(cx
, obj
);
127 (void)aStatement
->BindInt64Parameter(aIdx
, msec
);
139 /*************************************************************************
141 **** mozStorageStatementWrapper
143 *************************************************************************/
145 NS_IMPL_ISUPPORTS2(mozStorageStatementWrapper
, mozIStorageStatementWrapper
, nsIXPCScriptable
)
147 mozStorageStatementWrapper::mozStorageStatementWrapper()
152 mozStorageStatementWrapper::~mozStorageStatementWrapper()
158 mozStorageStatementWrapper::Initialize(mozIStorageStatement
*aStatement
)
160 NS_ASSERTION(mStatement
== nsnull
, "mozStorageStatementWrapper is already initialized");
161 NS_ENSURE_ARG_POINTER(aStatement
);
163 mStatement
= aStatement
;
165 // fetch various things we care about
166 mStatement
->GetParameterCount(&mParamCount
);
167 mStatement
->GetColumnCount(&mResultColumnCount
);
169 for (unsigned int i
= 0; i
< mResultColumnCount
; i
++) {
170 const void *name
= sqlite3_column_name16 (NativeStatement(), i
);
171 mColumnNames
.AppendString(nsDependentString(static_cast<const PRUnichar
*>(name
)));
178 mozStorageStatementWrapper::GetStatement(mozIStorageStatement
**aStatement
)
180 NS_IF_ADDREF(*aStatement
= mStatement
);
185 mozStorageStatementWrapper::Reset()
188 return NS_ERROR_FAILURE
;
190 return mStatement
->Reset();
194 mozStorageStatementWrapper::Step(PRBool
*_retval
)
197 return NS_ERROR_FAILURE
;
199 PRBool hasMore
= PR_FALSE
;
200 nsresult rv
= mStatement
->ExecuteStep(&hasMore
);
201 if (NS_SUCCEEDED(rv
) && !hasMore
) {
212 mozStorageStatementWrapper::Execute()
215 return NS_ERROR_FAILURE
;
217 return mStatement
->Execute();
221 mozStorageStatementWrapper::GetRow(mozIStorageStatementRow
**aRow
)
223 NS_ENSURE_ARG_POINTER(aRow
);
226 return NS_ERROR_FAILURE
;
229 mStatement
->GetState(&state
);
230 if (state
!= mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING
)
231 return NS_ERROR_FAILURE
;
233 if (!mStatementRow
) {
234 mozStorageStatementRow
*row
= new mozStorageStatementRow(mStatement
, mResultColumnCount
, &mColumnNames
);
236 return NS_ERROR_OUT_OF_MEMORY
;
240 NS_ADDREF(*aRow
= mStatementRow
);
245 mozStorageStatementWrapper::GetParams(mozIStorageStatementParams
**aParams
)
247 NS_ENSURE_ARG_POINTER(aParams
);
249 if (!mStatementParams
) {
250 mozStorageStatementParams
*params
= new mozStorageStatementParams(mStatement
);
252 return NS_ERROR_OUT_OF_MEMORY
;
253 mStatementParams
= params
;
256 NS_ADDREF(*aParams
= mStatementParams
);
260 /*** nsIXPCScriptable interface ***/
262 /* readonly attribute string className; */
264 mozStorageStatementWrapper::GetClassName(char * *aClassName
)
266 NS_ENSURE_ARG_POINTER(aClassName
);
267 *aClassName
= (char *) nsMemory::Clone("mozStorageStatementWrapper", 27);
269 return NS_ERROR_OUT_OF_MEMORY
;
273 /* readonly attribute PRUint32 scriptableFlags; */
275 mozStorageStatementWrapper::GetScriptableFlags(PRUint32
*aScriptableFlags
)
278 nsIXPCScriptable::WANT_CALL
|
279 nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY
|
280 nsIXPCScriptable::WANT_NEWRESOLVE
|
281 nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
;
285 /* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
287 mozStorageStatementWrapper::Call(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
288 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
292 return NS_ERROR_FAILURE
;
295 if (argc
!= mParamCount
) {
297 return NS_ERROR_FAILURE
;
304 for (int i
= 0; i
< (int) argc
; i
++) {
305 if (!JSValStorageStatementBinder(cx
, mStatement
, i
, argv
[i
])) {
307 return NS_ERROR_INVALID_ARG
;
311 // if there are no results, we just execute
312 if (mResultColumnCount
== 0)
313 mStatement
->Execute();
320 /* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
322 mozStorageStatementWrapper::GetProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
323 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
330 /* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
332 mozStorageStatementWrapper::SetProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
333 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
339 /* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
341 mozStorageStatementWrapper::PreCreate(nsISupports
*nativeObj
, JSContext
* cx
,
342 JSObject
* globalObj
, JSObject
* *parentObj
)
344 return NS_ERROR_NOT_IMPLEMENTED
;
347 /* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
349 mozStorageStatementWrapper::Create(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
351 return NS_ERROR_NOT_IMPLEMENTED
;
354 /* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
356 mozStorageStatementWrapper::PostCreate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
358 return NS_ERROR_NOT_IMPLEMENTED
;
361 /* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
363 mozStorageStatementWrapper::AddProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
364 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
366 return NS_ERROR_NOT_IMPLEMENTED
;
369 /* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
371 mozStorageStatementWrapper::DelProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
372 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
374 return NS_ERROR_NOT_IMPLEMENTED
;
377 /* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
379 mozStorageStatementWrapper::Enumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
380 JSObject
* obj
, PRBool
*_retval
)
382 return NS_ERROR_NOT_IMPLEMENTED
;
385 /* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
387 mozStorageStatementWrapper::NewEnumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
388 JSObject
* obj
, PRUint32 enum_op
, jsval
* statep
, jsid
*idp
, PRBool
*_retval
)
390 return NS_ERROR_NOT_IMPLEMENTED
;
393 /* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
395 mozStorageStatementWrapper::NewResolve(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
396 JSObject
* obj
, jsval id
, PRUint32 flags
, JSObject
* *objp
, PRBool
*_retval
)
402 /* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
404 mozStorageStatementWrapper::Convert(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
405 JSObject
* obj
, PRUint32 type
, jsval
* vp
, PRBool
*_retval
)
407 return NS_ERROR_NOT_IMPLEMENTED
;
410 /* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
412 mozStorageStatementWrapper::Finalize(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
415 return NS_ERROR_NOT_IMPLEMENTED
;
418 /* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
420 mozStorageStatementWrapper::CheckAccess(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
421 JSObject
* obj
, jsval id
, PRUint32 mode
, jsval
* vp
, PRBool
*_retval
)
423 return NS_ERROR_NOT_IMPLEMENTED
;
426 /* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
428 mozStorageStatementWrapper::Construct(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
429 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
431 return NS_ERROR_NOT_IMPLEMENTED
;
434 /* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
436 mozStorageStatementWrapper::HasInstance(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
437 JSObject
* obj
, jsval val
, PRBool
*bp
, PRBool
*_retval
)
439 return NS_ERROR_NOT_IMPLEMENTED
;
442 /* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
444 mozStorageStatementWrapper::Trace(nsIXPConnectWrappedNative
*wrapper
,
445 JSTracer
*trc
, JSObject
*obj
)
447 return NS_ERROR_NOT_IMPLEMENTED
;
450 /* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
452 mozStorageStatementWrapper::Equality(nsIXPConnectWrappedNative
*wrapper
,
453 JSContext
*cx
, JSObject
*obj
, jsval val
,
456 return NS_ERROR_NOT_IMPLEMENTED
;
459 /* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
461 mozStorageStatementWrapper::OuterObject(nsIXPConnectWrappedNative
*wrapper
,
462 JSContext
*cx
, JSObject
*obj
,
465 return NS_ERROR_NOT_IMPLEMENTED
;
468 /* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
470 mozStorageStatementWrapper::InnerObject(nsIXPConnectWrappedNative
*wrapper
,
471 JSContext
*cx
, JSObject
*obj
,
474 return NS_ERROR_NOT_IMPLEMENTED
;
477 /*************************************************************************
479 **** mozStorageStatementRow
481 *************************************************************************/
483 NS_IMPL_ISUPPORTS2(mozStorageStatementRow
, mozIStorageStatementRow
, nsIXPCScriptable
)
485 mozStorageStatementRow::mozStorageStatementRow(mozIStorageStatement
*aStatement
,
487 const nsStringArray
*aColumnNames
)
488 : mStatement(aStatement
),
489 mNumColumns(aNumColumns
),
490 mColumnNames(aColumnNames
)
495 * nsIXPCScriptable impl
498 /* readonly attribute string className; */
500 mozStorageStatementRow::GetClassName(char * *aClassName
)
502 NS_ENSURE_ARG_POINTER(aClassName
);
503 *aClassName
= (char *) nsMemory::Clone("mozStorageStatementRow", 23);
505 return NS_ERROR_OUT_OF_MEMORY
;
509 /* readonly attribute PRUint32 scriptableFlags; */
511 mozStorageStatementRow::GetScriptableFlags(PRUint32
*aScriptableFlags
)
514 nsIXPCScriptable::WANT_GETPROPERTY
|
515 nsIXPCScriptable::WANT_NEWRESOLVE
|
516 nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
;
520 /* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
522 mozStorageStatementRow::GetProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
523 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
527 if (JSVAL_IS_STRING(id
)) {
528 nsDependentString
jsid((PRUnichar
*)::JS_GetStringChars(JSVAL_TO_STRING(id
)),
529 ::JS_GetStringLength(JSVAL_TO_STRING(id
)));
531 for (int i
= 0; i
< mNumColumns
; i
++) {
532 if (jsid
.Equals(*(*mColumnNames
)[i
])) {
533 int ctype
= sqlite3_column_type(NativeStatement(), i
);
535 if (ctype
== SQLITE_INTEGER
|| ctype
== SQLITE_FLOAT
) {
536 double dval
= sqlite3_column_double(NativeStatement(), i
);
537 if (!JS_NewNumberValue(cx
, dval
, vp
)) {
539 return NS_ERROR_OUT_OF_MEMORY
;
541 } else if (ctype
== SQLITE_TEXT
) {
542 JSString
*str
= JS_NewUCStringCopyN(cx
,
543 (jschar
*) sqlite3_column_text16(NativeStatement(), i
),
544 sqlite3_column_bytes16(NativeStatement(), i
)/2);
547 return NS_ERROR_OUT_OF_MEMORY
;
549 *vp
= STRING_TO_JSVAL(str
);
550 } else if (ctype
== SQLITE_BLOB
) {
551 JSString
*str
= JS_NewStringCopyN(cx
,
552 (char*) sqlite3_column_blob(NativeStatement(), i
),
553 sqlite3_column_bytes(NativeStatement(), i
));
556 return NS_ERROR_OUT_OF_MEMORY
;
558 } else if (ctype
== SQLITE_NULL
) {
561 NS_ERROR("sqlite3_column_type returned unknown column type, what's going on?");
574 /* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
576 mozStorageStatementRow::SetProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
577 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
579 return NS_ERROR_NOT_IMPLEMENTED
;
582 /* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
584 mozStorageStatementRow::PreCreate(nsISupports
*nativeObj
, JSContext
* cx
,
585 JSObject
* globalObj
, JSObject
* *parentObj
)
587 return NS_ERROR_NOT_IMPLEMENTED
;
590 /* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
592 mozStorageStatementRow::Create(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
594 return NS_ERROR_NOT_IMPLEMENTED
;
597 /* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
599 mozStorageStatementRow::PostCreate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
601 return NS_ERROR_NOT_IMPLEMENTED
;
604 /* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
606 mozStorageStatementRow::AddProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
607 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
609 return NS_ERROR_NOT_IMPLEMENTED
;
612 /* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
614 mozStorageStatementRow::DelProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
615 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
617 return NS_ERROR_NOT_IMPLEMENTED
;
620 /* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
622 mozStorageStatementRow::Enumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
623 JSObject
* obj
, PRBool
*_retval
)
625 return NS_ERROR_NOT_IMPLEMENTED
;
628 /* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
630 mozStorageStatementRow::NewEnumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
631 JSObject
* obj
, PRUint32 enum_op
, jsval
* statep
, jsid
*idp
, PRBool
*_retval
)
633 return NS_ERROR_NOT_IMPLEMENTED
;
636 /* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
638 mozStorageStatementRow::NewResolve(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
639 JSObject
* obj
, jsval id
, PRUint32 flags
, JSObject
* *objp
, PRBool
*_retval
)
641 if (JSVAL_IS_STRING(id
)) {
642 JSString
*str
= JSVAL_TO_STRING(id
);
643 nsDependentString
name((PRUnichar
*)::JS_GetStringChars(str
),
644 ::JS_GetStringLength(str
));
646 for (int i
= 0; i
< mNumColumns
; i
++) {
647 if (name
.Equals(*(*mColumnNames
)[i
])) {
648 *_retval
= ::JS_DefineUCProperty(cx
, obj
, ::JS_GetStringChars(str
),
649 ::JS_GetStringLength(str
),
653 return *_retval
? NS_OK
: NS_ERROR_FAILURE
;
662 /* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
664 mozStorageStatementRow::Convert(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
665 JSObject
* obj
, PRUint32 type
, jsval
* vp
, PRBool
*_retval
)
667 return NS_ERROR_NOT_IMPLEMENTED
;
670 /* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
672 mozStorageStatementRow::Finalize(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
675 return NS_ERROR_NOT_IMPLEMENTED
;
678 /* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
680 mozStorageStatementRow::CheckAccess(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
681 JSObject
* obj
, jsval id
, PRUint32 mode
, jsval
* vp
, PRBool
*_retval
)
683 return NS_ERROR_NOT_IMPLEMENTED
;
686 /* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
688 mozStorageStatementRow::Call(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
689 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
691 return NS_ERROR_NOT_IMPLEMENTED
;
694 /* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
696 mozStorageStatementRow::Construct(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
697 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
699 return NS_ERROR_NOT_IMPLEMENTED
;
702 /* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
704 mozStorageStatementRow::HasInstance(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
705 JSObject
* obj
, jsval val
, PRBool
*bp
, PRBool
*_retval
)
707 return NS_ERROR_NOT_IMPLEMENTED
;
710 /* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
712 mozStorageStatementRow::Trace(nsIXPConnectWrappedNative
*wrapper
,
713 JSTracer
* trc
, JSObject
* obj
)
715 return NS_ERROR_NOT_IMPLEMENTED
;
718 /* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
720 mozStorageStatementRow::Equality(nsIXPConnectWrappedNative
*wrapper
,
721 JSContext
*cx
, JSObject
*obj
, jsval val
,
724 return NS_ERROR_NOT_IMPLEMENTED
;
727 /* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
729 mozStorageStatementRow::OuterObject(nsIXPConnectWrappedNative
*wrapper
,
730 JSContext
*cx
, JSObject
*obj
,
733 return NS_ERROR_NOT_IMPLEMENTED
;
736 /* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
738 mozStorageStatementRow::InnerObject(nsIXPConnectWrappedNative
*wrapper
,
739 JSContext
*cx
, JSObject
*obj
,
742 return NS_ERROR_NOT_IMPLEMENTED
;
745 /*************************************************************************
747 **** mozStorageStatementParams
749 *************************************************************************/
751 NS_IMPL_ISUPPORTS2(mozStorageStatementParams
, mozIStorageStatementParams
, nsIXPCScriptable
)
753 mozStorageStatementParams::mozStorageStatementParams(mozIStorageStatement
*aStatement
)
754 : mStatement(aStatement
)
756 NS_ASSERTION(mStatement
!= nsnull
, "mStatement is null");
757 mStatement
->GetParameterCount(&mParamCount
);
761 * nsIXPCScriptable impl
764 /* readonly attribute string className; */
766 mozStorageStatementParams::GetClassName(char * *aClassName
)
768 NS_ENSURE_ARG_POINTER(aClassName
);
769 *aClassName
= (char *) nsMemory::Clone("mozStorageStatementParams", 26);
771 return NS_ERROR_OUT_OF_MEMORY
;
775 /* readonly attribute PRUint32 scriptableFlags; */
777 mozStorageStatementParams::GetScriptableFlags(PRUint32
*aScriptableFlags
)
780 nsIXPCScriptable::WANT_SETPROPERTY
|
781 nsIXPCScriptable::WANT_NEWRESOLVE
|
782 nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
;
786 /* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
788 mozStorageStatementParams::GetProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
789 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
791 return NS_ERROR_NOT_IMPLEMENTED
;
795 /* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
797 mozStorageStatementParams::SetProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
798 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
800 if (JSVAL_IS_INT(id
)) {
801 int idx
= JSVAL_TO_INT(id
);
803 *_retval
= JSValStorageStatementBinder (cx
, mStatement
, idx
, *vp
);
804 } else if (JSVAL_IS_STRING(id
)) {
805 sqlite3_stmt
*stmt
= mStatement
->GetNativeStatementPointer();
807 JSString
*str
= JSVAL_TO_STRING(id
);
808 nsCAutoString
name(":");
809 name
.Append(NS_ConvertUTF16toUTF8(nsDependentString((PRUnichar
*)::JS_GetStringChars(str
),
810 ::JS_GetStringLength(str
))));
812 // check to see if there's a parameter with this name
813 if (sqlite3_bind_parameter_index(stmt
, name
.get()) == 0) {
815 return NS_ERROR_INVALID_ARG
;
819 // You can use a named parameter more than once in a statement...
820 int count
= sqlite3_bind_parameter_count(stmt
);
821 for (int i
= 0; (i
< count
) && (*_retval
); i
++) {
822 // sqlite indices start at 1
823 const char *pName
= sqlite3_bind_parameter_name(stmt
, i
+ 1);
824 if (name
.Equals(pName
))
825 *_retval
= JSValStorageStatementBinder(cx
, mStatement
, i
, *vp
);
831 return (*_retval
) ? NS_OK
: NS_ERROR_INVALID_ARG
;
834 /* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
836 mozStorageStatementParams::PreCreate(nsISupports
*nativeObj
, JSContext
* cx
,
837 JSObject
* globalObj
, JSObject
* *parentObj
)
839 return NS_ERROR_NOT_IMPLEMENTED
;
842 /* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
844 mozStorageStatementParams::Create(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
846 return NS_ERROR_NOT_IMPLEMENTED
;
849 /* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
851 mozStorageStatementParams::PostCreate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
853 return NS_ERROR_NOT_IMPLEMENTED
;
856 /* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
858 mozStorageStatementParams::AddProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
859 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
861 return NS_ERROR_NOT_IMPLEMENTED
;
864 /* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
866 mozStorageStatementParams::DelProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
867 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
869 return NS_ERROR_NOT_IMPLEMENTED
;
872 /* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
874 mozStorageStatementParams::Enumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
875 JSObject
* obj
, PRBool
*_retval
)
877 return NS_ERROR_NOT_IMPLEMENTED
;
880 /* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
882 mozStorageStatementParams::NewEnumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
883 JSObject
* obj
, PRUint32 enum_op
, jsval
* statep
, jsid
*idp
, PRBool
*_retval
)
885 return NS_ERROR_NOT_IMPLEMENTED
;
888 /* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
890 mozStorageStatementParams::NewResolve(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
891 JSObject
* obj
, jsval id
, PRUint32 flags
, JSObject
* *objp
, PRBool
*_retval
)
895 if (JSVAL_IS_INT(id
)) {
896 idx
= JSVAL_TO_INT(id
);
897 } else if (JSVAL_IS_STRING(id
)) {
898 JSString
*str
= JSVAL_TO_STRING(id
);
899 nsCAutoString
name(":");
900 name
.Append(NS_ConvertUTF16toUTF8(nsDependentString((PRUnichar
*)::JS_GetStringChars(str
),
901 ::JS_GetStringLength(str
))));
903 // check to see if there's a parameter with this name
904 idx
= sqlite3_bind_parameter_index(mStatement
->GetNativeStatementPointer(), name
.get());
907 fprintf (stderr
, "********** mozStorageStatementWrapper: Couldn't find parameter %s\n", name
.get());
911 // set idx, so that the numbered property also gets defined
915 PRBool success
= ::JS_DefineUCProperty(cx
, obj
, ::JS_GetStringChars(str
),
916 ::JS_GetStringLength(str
),
921 return NS_ERROR_FAILURE
;
927 return NS_ERROR_FAILURE
;
930 // is it out of range?
931 if (idx
< 0 || idx
>= (int)mParamCount
) {
936 *_retval
= ::JS_DefineElement(cx
, obj
, idx
, JSVAL_VOID
, nsnull
, nsnull
, 0);
942 /* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
944 mozStorageStatementParams::Convert(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
945 JSObject
* obj
, PRUint32 type
, jsval
* vp
, PRBool
*_retval
)
947 return NS_ERROR_NOT_IMPLEMENTED
;
950 /* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
952 mozStorageStatementParams::Finalize(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
955 return NS_ERROR_NOT_IMPLEMENTED
;
958 /* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
960 mozStorageStatementParams::CheckAccess(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
961 JSObject
* obj
, jsval id
, PRUint32 mode
, jsval
* vp
, PRBool
*_retval
)
963 return NS_ERROR_NOT_IMPLEMENTED
;
966 /* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
968 mozStorageStatementParams::Call(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
969 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
971 return NS_ERROR_NOT_IMPLEMENTED
;
974 /* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
976 mozStorageStatementParams::Construct(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
977 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
979 return NS_ERROR_NOT_IMPLEMENTED
;
982 /* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
984 mozStorageStatementParams::HasInstance(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
985 JSObject
* obj
, jsval val
, PRBool
*bp
, PRBool
*_retval
)
987 return NS_ERROR_NOT_IMPLEMENTED
;
990 /* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
992 mozStorageStatementParams::Trace(nsIXPConnectWrappedNative
*wrapper
,
993 JSTracer
*trc
, JSObject
* obj
)
995 return NS_ERROR_NOT_IMPLEMENTED
;
998 /* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
1000 mozStorageStatementParams::Equality(nsIXPConnectWrappedNative
*wrapper
,
1001 JSContext
*cx
, JSObject
*obj
, jsval val
,
1004 return NS_ERROR_NOT_IMPLEMENTED
;
1007 /* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
1009 mozStorageStatementParams::OuterObject(nsIXPConnectWrappedNative
*wrapper
,
1010 JSContext
*cx
, JSObject
*obj
,
1013 return NS_ERROR_NOT_IMPLEMENTED
;
1016 /* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
1018 mozStorageStatementParams::InnerObject(nsIXPConnectWrappedNative
*wrapper
,
1019 JSContext
*cx
, JSObject
*obj
,
1022 return NS_ERROR_NOT_IMPLEMENTED
;