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 "mozStorageStatementParams.h"
48 /*************************************************************************
50 **** mozStorageStatementParams
52 *************************************************************************/
54 NS_IMPL_ISUPPORTS2(mozStorageStatementParams
, mozIStorageStatementParams
, nsIXPCScriptable
)
56 mozStorageStatementParams::mozStorageStatementParams(mozIStorageStatement
*aStatement
)
57 : mStatement(aStatement
)
59 NS_ASSERTION(mStatement
!= nsnull
, "mStatement is null");
60 mStatement
->GetParameterCount(&mParamCount
);
64 * nsIXPCScriptable impl
67 /* readonly attribute string className; */
69 mozStorageStatementParams::GetClassName(char * *aClassName
)
71 NS_ENSURE_ARG_POINTER(aClassName
);
72 *aClassName
= (char *) nsMemory::Clone("mozStorageStatementParams", 26);
74 return NS_ERROR_OUT_OF_MEMORY
;
78 /* readonly attribute PRUint32 scriptableFlags; */
80 mozStorageStatementParams::GetScriptableFlags(PRUint32
*aScriptableFlags
)
83 nsIXPCScriptable::WANT_SETPROPERTY
|
84 nsIXPCScriptable::WANT_NEWRESOLVE
|
85 nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
;
89 /* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
91 mozStorageStatementParams::GetProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
92 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
94 return NS_ERROR_NOT_IMPLEMENTED
;
98 /* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
100 mozStorageStatementParams::SetProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
101 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
103 if (JSVAL_IS_INT(id
)) {
104 int idx
= JSVAL_TO_INT(id
);
106 *_retval
= JSValStorageStatementBinder (cx
, mStatement
, idx
, *vp
);
107 } else if (JSVAL_IS_STRING(id
)) {
108 sqlite3_stmt
*stmt
= mStatement
->GetNativeStatementPointer();
110 JSString
*str
= JSVAL_TO_STRING(id
);
111 nsCAutoString
name(":");
112 name
.Append(NS_ConvertUTF16toUTF8(nsDependentString((PRUnichar
*)::JS_GetStringChars(str
),
113 ::JS_GetStringLength(str
))));
115 // check to see if there's a parameter with this name
116 if (sqlite3_bind_parameter_index(stmt
, name
.get()) == 0) {
118 return NS_ERROR_INVALID_ARG
;
122 // You can use a named parameter more than once in a statement...
123 int count
= sqlite3_bind_parameter_count(stmt
);
124 for (int i
= 0; (i
< count
) && (*_retval
); i
++) {
125 // sqlite indices start at 1
126 const char *pName
= sqlite3_bind_parameter_name(stmt
, i
+ 1);
127 if (name
.Equals(pName
))
128 *_retval
= JSValStorageStatementBinder(cx
, mStatement
, i
, *vp
);
134 return (*_retval
) ? NS_OK
: NS_ERROR_INVALID_ARG
;
137 /* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
139 mozStorageStatementParams::PreCreate(nsISupports
*nativeObj
, JSContext
* cx
,
140 JSObject
* globalObj
, JSObject
* *parentObj
)
142 return NS_ERROR_NOT_IMPLEMENTED
;
145 /* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
147 mozStorageStatementParams::Create(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
149 return NS_ERROR_NOT_IMPLEMENTED
;
152 /* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
154 mozStorageStatementParams::PostCreate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
156 return NS_ERROR_NOT_IMPLEMENTED
;
159 /* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
161 mozStorageStatementParams::AddProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
162 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
164 return NS_ERROR_NOT_IMPLEMENTED
;
167 /* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
169 mozStorageStatementParams::DelProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
170 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
172 return NS_ERROR_NOT_IMPLEMENTED
;
175 /* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
177 mozStorageStatementParams::Enumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
178 JSObject
* obj
, PRBool
*_retval
)
180 return NS_ERROR_NOT_IMPLEMENTED
;
183 /* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
185 mozStorageStatementParams::NewEnumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
186 JSObject
* obj
, PRUint32 enum_op
, jsval
* statep
, jsid
*idp
, PRBool
*_retval
)
188 return NS_ERROR_NOT_IMPLEMENTED
;
191 /* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
193 mozStorageStatementParams::NewResolve(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
194 JSObject
* obj
, jsval id
, PRUint32 flags
, JSObject
* *objp
, PRBool
*_retval
)
198 if (JSVAL_IS_INT(id
)) {
199 idx
= JSVAL_TO_INT(id
);
200 } else if (JSVAL_IS_STRING(id
)) {
201 JSString
*str
= JSVAL_TO_STRING(id
);
202 nsCAutoString
name(":");
203 name
.Append(NS_ConvertUTF16toUTF8(nsDependentString((PRUnichar
*)::JS_GetStringChars(str
),
204 ::JS_GetStringLength(str
))));
206 // check to see if there's a parameter with this name
207 idx
= sqlite3_bind_parameter_index(mStatement
->GetNativeStatementPointer(), name
.get());
210 fprintf (stderr
, "********** mozStorageStatementWrapper: Couldn't find parameter %s\n", name
.get());
214 // set idx, so that the numbered property also gets defined
218 PRBool success
= ::JS_DefineUCProperty(cx
, obj
, ::JS_GetStringChars(str
),
219 ::JS_GetStringLength(str
),
224 return NS_ERROR_FAILURE
;
230 return NS_ERROR_FAILURE
;
233 // is it out of range?
234 if (idx
< 0 || idx
>= (int)mParamCount
) {
239 *_retval
= ::JS_DefineElement(cx
, obj
, idx
, JSVAL_VOID
, nsnull
, nsnull
, 0);
245 /* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
247 mozStorageStatementParams::Convert(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
248 JSObject
* obj
, PRUint32 type
, jsval
* vp
, PRBool
*_retval
)
250 return NS_ERROR_NOT_IMPLEMENTED
;
253 /* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
255 mozStorageStatementParams::Finalize(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
258 return NS_ERROR_NOT_IMPLEMENTED
;
261 /* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
263 mozStorageStatementParams::CheckAccess(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
264 JSObject
* obj
, jsval id
, PRUint32 mode
, jsval
* vp
, PRBool
*_retval
)
266 return NS_ERROR_NOT_IMPLEMENTED
;
269 /* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
271 mozStorageStatementParams::Call(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
272 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
274 return NS_ERROR_NOT_IMPLEMENTED
;
277 /* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
279 mozStorageStatementParams::Construct(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
280 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
282 return NS_ERROR_NOT_IMPLEMENTED
;
285 /* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
287 mozStorageStatementParams::HasInstance(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
288 JSObject
* obj
, jsval val
, PRBool
*bp
, PRBool
*_retval
)
290 return NS_ERROR_NOT_IMPLEMENTED
;
293 /* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
295 mozStorageStatementParams::Trace(nsIXPConnectWrappedNative
*wrapper
,
296 JSTracer
*trc
, JSObject
* obj
)
298 return NS_ERROR_NOT_IMPLEMENTED
;
301 /* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
303 mozStorageStatementParams::Equality(nsIXPConnectWrappedNative
*wrapper
,
304 JSContext
*cx
, JSObject
*obj
, jsval val
,
307 return NS_ERROR_NOT_IMPLEMENTED
;
310 /* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
312 mozStorageStatementParams::OuterObject(nsIXPConnectWrappedNative
*wrapper
,
313 JSContext
*cx
, JSObject
*obj
,
316 return NS_ERROR_NOT_IMPLEMENTED
;
319 /* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
321 mozStorageStatementParams::InnerObject(nsIXPConnectWrappedNative
*wrapper
,
322 JSContext
*cx
, JSObject
*obj
,
325 return NS_ERROR_NOT_IMPLEMENTED
;
328 /* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
330 mozStorageStatementParams::PostCreatePrototype(JSContext
* cx
, JSObject
* proto
)