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"
45 #include "mozStorageStatementParams.h"
46 #include "mozStorageStatementRow.h"
51 /*************************************************************************
53 **** mozStorageStatementWrapper
55 *************************************************************************/
57 NS_IMPL_ISUPPORTS2(mozStorageStatementWrapper
, mozIStorageStatementWrapper
, nsIXPCScriptable
)
59 mozStorageStatementWrapper::mozStorageStatementWrapper()
64 mozStorageStatementWrapper::~mozStorageStatementWrapper()
70 mozStorageStatementWrapper::Initialize(mozIStorageStatement
*aStatement
)
72 NS_ASSERTION(mStatement
== nsnull
, "mozStorageStatementWrapper is already initialized");
73 NS_ENSURE_ARG_POINTER(aStatement
);
75 mStatement
= static_cast<mozStorageStatement
*>(aStatement
);
77 // fetch various things we care about
78 mStatement
->GetParameterCount(&mParamCount
);
79 mStatement
->GetColumnCount(&mResultColumnCount
);
81 for (unsigned int i
= 0; i
< mResultColumnCount
; i
++) {
82 const void *name
= sqlite3_column_name16 (NativeStatement(), i
);
83 mColumnNames
.AppendElement(nsDependentString(static_cast<const PRUnichar
*>(name
)));
90 mozStorageStatementWrapper::GetStatement(mozIStorageStatement
**aStatement
)
92 NS_IF_ADDREF(*aStatement
= mStatement
);
97 mozStorageStatementWrapper::Reset()
100 return NS_ERROR_FAILURE
;
102 return mStatement
->Reset();
106 mozStorageStatementWrapper::Step(PRBool
*_retval
)
109 return NS_ERROR_FAILURE
;
111 PRBool hasMore
= PR_FALSE
;
112 nsresult rv
= mStatement
->ExecuteStep(&hasMore
);
113 if (NS_SUCCEEDED(rv
) && !hasMore
) {
124 mozStorageStatementWrapper::Execute()
127 return NS_ERROR_FAILURE
;
129 return mStatement
->Execute();
133 mozStorageStatementWrapper::GetRow(mozIStorageStatementRow
**aRow
)
135 NS_ENSURE_ARG_POINTER(aRow
);
138 return NS_ERROR_FAILURE
;
141 mStatement
->GetState(&state
);
142 if (state
!= mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING
)
143 return NS_ERROR_FAILURE
;
145 if (!mStatementRow
) {
146 mozStorageStatementRow
*row
= new mozStorageStatementRow(mStatement
);
148 return NS_ERROR_OUT_OF_MEMORY
;
152 NS_ADDREF(*aRow
= mStatementRow
);
157 mozStorageStatementWrapper::GetParams(mozIStorageStatementParams
**aParams
)
159 NS_ENSURE_ARG_POINTER(aParams
);
161 if (!mStatementParams
) {
162 mozStorageStatementParams
*params
= new mozStorageStatementParams(mStatement
);
164 return NS_ERROR_OUT_OF_MEMORY
;
165 mStatementParams
= params
;
168 NS_ADDREF(*aParams
= mStatementParams
);
172 /*** nsIXPCScriptable interface ***/
174 /* readonly attribute string className; */
176 mozStorageStatementWrapper::GetClassName(char * *aClassName
)
178 NS_ENSURE_ARG_POINTER(aClassName
);
179 *aClassName
= (char *) nsMemory::Clone("mozStorageStatementWrapper", 27);
181 return NS_ERROR_OUT_OF_MEMORY
;
185 /* readonly attribute PRUint32 scriptableFlags; */
187 mozStorageStatementWrapper::GetScriptableFlags(PRUint32
*aScriptableFlags
)
190 nsIXPCScriptable::WANT_CALL
|
191 nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY
|
192 nsIXPCScriptable::WANT_NEWRESOLVE
|
193 nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
;
197 /* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
199 mozStorageStatementWrapper::Call(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
200 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
204 return NS_ERROR_FAILURE
;
207 if (argc
!= mParamCount
) {
209 return NS_ERROR_FAILURE
;
216 for (int i
= 0; i
< (int) argc
; i
++) {
217 if (!JSValStorageStatementBinder(cx
, mStatement
, i
, argv
[i
])) {
219 return NS_ERROR_INVALID_ARG
;
223 // if there are no results, we just execute
224 if (mResultColumnCount
== 0)
225 mStatement
->Execute();
232 /* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
234 mozStorageStatementWrapper::GetProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
235 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
242 /* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
244 mozStorageStatementWrapper::SetProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
245 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
251 /* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
253 mozStorageStatementWrapper::PreCreate(nsISupports
*nativeObj
, JSContext
* cx
,
254 JSObject
* globalObj
, JSObject
* *parentObj
)
256 return NS_ERROR_NOT_IMPLEMENTED
;
259 /* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
261 mozStorageStatementWrapper::Create(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
263 return NS_ERROR_NOT_IMPLEMENTED
;
266 /* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
268 mozStorageStatementWrapper::PostCreate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
, JSObject
* obj
)
270 return NS_ERROR_NOT_IMPLEMENTED
;
273 /* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
275 mozStorageStatementWrapper::AddProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
276 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
278 return NS_ERROR_NOT_IMPLEMENTED
;
281 /* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
283 mozStorageStatementWrapper::DelProperty(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
284 JSObject
* obj
, jsval id
, jsval
* vp
, PRBool
*_retval
)
286 return NS_ERROR_NOT_IMPLEMENTED
;
289 /* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
291 mozStorageStatementWrapper::Enumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
292 JSObject
* obj
, PRBool
*_retval
)
294 return NS_ERROR_NOT_IMPLEMENTED
;
297 /* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
299 mozStorageStatementWrapper::NewEnumerate(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
300 JSObject
* obj
, PRUint32 enum_op
, jsval
* statep
, jsid
*idp
, PRBool
*_retval
)
302 return NS_ERROR_NOT_IMPLEMENTED
;
305 /* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
307 mozStorageStatementWrapper::NewResolve(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
308 JSObject
* obj
, jsval id
, PRUint32 flags
, JSObject
* *objp
, PRBool
*_retval
)
314 /* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
316 mozStorageStatementWrapper::Convert(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
317 JSObject
* obj
, PRUint32 type
, jsval
* vp
, PRBool
*_retval
)
319 return NS_ERROR_NOT_IMPLEMENTED
;
322 /* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
324 mozStorageStatementWrapper::Finalize(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
327 return NS_ERROR_NOT_IMPLEMENTED
;
330 /* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
332 mozStorageStatementWrapper::CheckAccess(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
333 JSObject
* obj
, jsval id
, PRUint32 mode
, jsval
* vp
, PRBool
*_retval
)
335 return NS_ERROR_NOT_IMPLEMENTED
;
338 /* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
340 mozStorageStatementWrapper::Construct(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
341 JSObject
* obj
, PRUint32 argc
, jsval
* argv
, jsval
* vp
, PRBool
*_retval
)
343 return NS_ERROR_NOT_IMPLEMENTED
;
346 /* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
348 mozStorageStatementWrapper::HasInstance(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
349 JSObject
* obj
, jsval val
, PRBool
*bp
, PRBool
*_retval
)
351 return NS_ERROR_NOT_IMPLEMENTED
;
354 /* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
356 mozStorageStatementWrapper::Trace(nsIXPConnectWrappedNative
*wrapper
,
357 JSTracer
*trc
, JSObject
*obj
)
359 return NS_ERROR_NOT_IMPLEMENTED
;
362 /* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
364 mozStorageStatementWrapper::Equality(nsIXPConnectWrappedNative
*wrapper
,
365 JSContext
*cx
, JSObject
*obj
, jsval val
,
368 return NS_ERROR_NOT_IMPLEMENTED
;
371 /* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
373 mozStorageStatementWrapper::OuterObject(nsIXPConnectWrappedNative
*wrapper
,
374 JSContext
*cx
, JSObject
*obj
,
377 return NS_ERROR_NOT_IMPLEMENTED
;
380 /* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
382 mozStorageStatementWrapper::InnerObject(nsIXPConnectWrappedNative
*wrapper
,
383 JSContext
*cx
, JSObject
*obj
,
386 return NS_ERROR_NOT_IMPLEMENTED
;
389 /* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
391 mozStorageStatementWrapper::PostCreatePrototype(JSContext
* cx
,