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 NS_ENSURE_TRUE(mStatement
, NS_ERROR_NOT_INITIALIZED
);
105 if (JSVAL_IS_INT(id
)) {
106 int idx
= JSVAL_TO_INT(id
);
108 *_retval
= JSValStorageStatementBinder (cx
, mStatement
, idx
, *vp
);
109 } else if (JSVAL_IS_STRING(id
)) {
110 sqlite3_stmt
*stmt
= mStatement
->GetNativeStatementPointer();
112 JSString
*str
= JSVAL_TO_STRING(id
);
113 nsCAutoString
name(":");
114 name
.Append(NS_ConvertUTF16toUTF8(nsDependentString((PRUnichar
*)::JS_GetStringChars(str
),
115 ::JS_GetStringLength(str
))));
117 // check to see if there's a parameter with this name
118 if (sqlite3_bind_parameter_index(stmt
, name
.get()) == 0) {
120 return NS_ERROR_INVALID_ARG
;
124 // You can use a named parameter more than once in a statement...
125 int count
= sqlite3_bind_parameter_count(stmt
);
126 for (int i
= 0; (i
< count
) && (*_retval
); i
++) {
127 // sqlite indices start at 1
128 const char *pName
= sqlite3_bind_parameter_name(stmt
, i
+ 1);
129 if (name
.Equals(pName
))
130 *_retval
= JSValStorageStatementBinder(cx
, mStatement
, i
, *vp
);
136 return (*_retval
) ? NS_OK
: NS_ERROR_INVALID_ARG
;
139 /* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
141 mozStorageStatementParams::PreCreate(nsISupports
*nativeObj
, JSContext
* cx
,
142 JSObject
* globalObj
, JSObject
* *parentObj
)
144 return NS_ERROR_NOT_IMPLEMENTED
;
147 /* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
149 mozStorageStatementParams::Create(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
151 return NS_ERROR_NOT_IMPLEMENTED
;
154 /* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
156 mozStorageStatementParams::PostCreate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
158 return NS_ERROR_NOT_IMPLEMENTED
;
161 /* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
163 mozStorageStatementParams::AddProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
164 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
166 return NS_ERROR_NOT_IMPLEMENTED
;
169 /* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
171 mozStorageStatementParams::DelProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
172 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
174 return NS_ERROR_NOT_IMPLEMENTED
;
177 /* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
179 mozStorageStatementParams::Enumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
180 JSObject
* obj
, PRBool
*_retval
)
182 return NS_ERROR_NOT_IMPLEMENTED
;
185 /* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
187 mozStorageStatementParams::NewEnumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
188 JSObject
* obj
, PRUint32 enum_op
, jsval
* statep
, jsid
*idp
, PRBool
*_retval
)
190 return NS_ERROR_NOT_IMPLEMENTED
;
193 /* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
195 mozStorageStatementParams::NewResolve(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
196 JSObject
* obj
, jsval id
, PRUint32 flags
, JSObject
* *objp
, PRBool
*_retval
)
198 NS_ENSURE_TRUE(mStatement
, NS_ERROR_NOT_INITIALIZED
);
202 if (JSVAL_IS_INT(id
)) {
203 idx
= JSVAL_TO_INT(id
);
204 } else if (JSVAL_IS_STRING(id
)) {
205 JSString
*str
= JSVAL_TO_STRING(id
);
206 nsCAutoString
name(":");
207 name
.Append(NS_ConvertUTF16toUTF8(nsDependentString((PRUnichar
*)::JS_GetStringChars(str
),
208 ::JS_GetStringLength(str
))));
210 // check to see if there's a parameter with this name
211 idx
= sqlite3_bind_parameter_index(mStatement
->GetNativeStatementPointer(), name
.get());
214 fprintf (stderr
, "********** mozStorageStatementWrapper: Couldn't find parameter %s\n", name
.get());
218 // set idx, so that the numbered property also gets defined
222 PRBool success
= ::JS_DefineUCProperty(cx
, obj
, ::JS_GetStringChars(str
),
223 ::JS_GetStringLength(str
),
228 return NS_ERROR_FAILURE
;
234 return NS_ERROR_FAILURE
;
237 // is it out of range?
238 if (idx
< 0 || idx
>= (int)mParamCount
) {
243 *_retval
= ::JS_DefineElement(cx
, obj
, idx
, JSVAL_VOID
, nsnull
, nsnull
, 0);
249 /* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
251 mozStorageStatementParams::Convert(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
252 JSObject
* obj
, PRUint32 type
, jsval
* vp
, PRBool
*_retval
)
254 return NS_ERROR_NOT_IMPLEMENTED
;
257 /* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
259 mozStorageStatementParams::Finalize(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
262 return NS_ERROR_NOT_IMPLEMENTED
;
265 /* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
267 mozStorageStatementParams::CheckAccess(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
268 JSObject
* obj
, jsval id
, PRUint32 mode
, jsval
* vp
, PRBool
*_retval
)
270 return NS_ERROR_NOT_IMPLEMENTED
;
273 /* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
275 mozStorageStatementParams::Call(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
276 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
278 return NS_ERROR_NOT_IMPLEMENTED
;
281 /* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
283 mozStorageStatementParams::Construct(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
284 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
286 return NS_ERROR_NOT_IMPLEMENTED
;
289 /* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
291 mozStorageStatementParams::HasInstance(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
292 JSObject
* obj
, jsval val
, PRBool
*bp
, PRBool
*_retval
)
294 return NS_ERROR_NOT_IMPLEMENTED
;
297 /* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
299 mozStorageStatementParams::Trace(nsIXPConnectWrappedNative
*wrapper
,
300 JSTracer
*trc
, JSObject
* obj
)
302 return NS_ERROR_NOT_IMPLEMENTED
;
305 /* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
307 mozStorageStatementParams::Equality(nsIXPConnectWrappedNative
*wrapper
,
308 JSContext
*cx
, JSObject
*obj
, jsval val
,
311 return NS_ERROR_NOT_IMPLEMENTED
;
314 /* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
316 mozStorageStatementParams::OuterObject(nsIXPConnectWrappedNative
*wrapper
,
317 JSContext
*cx
, JSObject
*obj
,
320 return NS_ERROR_NOT_IMPLEMENTED
;
323 /* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
325 mozStorageStatementParams::InnerObject(nsIXPConnectWrappedNative
*wrapper
,
326 JSContext
*cx
, JSObject
*obj
,
329 return NS_ERROR_NOT_IMPLEMENTED
;
332 /* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
334 mozStorageStatementParams::PostCreatePrototype(JSContext
* cx
, JSObject
* proto
)