Bug 481045. <svg:use> shouldn't paint its kids. r+sr=roc
[mozilla-central.git] / storage / src / mozStorageStatementWrapper.cpp
blob06fe08f370a0d3a2391a28a9a4f0aef1bba54620
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: sw=4 ts=4 sts=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
14 * License.
16 * The Original Code is Oracle Corporation code.
18 * The Initial Developer of the Original Code is
19 * Oracle Corporation
20 * Portions created by the Initial Developer are Copyright (C) 2004
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
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 ***** */
41 #include "nsMemory.h"
42 #include "nsString.h"
44 #include "mozStorageStatementWrapper.h"
45 #include "mozStorageStatementParams.h"
46 #include "mozStorageStatementRow.h"
48 #include "sqlite3.h"
51 /*************************************************************************
52 ****
53 **** mozStorageStatementWrapper
54 ****
55 *************************************************************************/
57 NS_IMPL_ISUPPORTS2(mozStorageStatementWrapper, mozIStorageStatementWrapper, nsIXPCScriptable)
59 mozStorageStatementWrapper::mozStorageStatementWrapper()
60 : mStatement(nsnull)
64 mozStorageStatementWrapper::~mozStorageStatementWrapper()
66 mStatement = nsnull;
69 NS_IMETHODIMP
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)));
86 return NS_OK;
89 NS_IMETHODIMP
90 mozStorageStatementWrapper::GetStatement(mozIStorageStatement **aStatement)
92 NS_IF_ADDREF(*aStatement = mStatement);
93 return NS_OK;
96 NS_IMETHODIMP
97 mozStorageStatementWrapper::Reset()
99 if (!mStatement)
100 return NS_ERROR_FAILURE;
102 return mStatement->Reset();
105 NS_IMETHODIMP
106 mozStorageStatementWrapper::Step(PRBool *_retval)
108 if (!mStatement)
109 return NS_ERROR_FAILURE;
111 PRBool hasMore = PR_FALSE;
112 nsresult rv = mStatement->ExecuteStep(&hasMore);
113 if (NS_SUCCEEDED(rv) && !hasMore) {
114 *_retval = PR_FALSE;
115 mStatement->Reset();
116 return NS_OK;
119 *_retval = hasMore;
120 return rv;
123 NS_IMETHODIMP
124 mozStorageStatementWrapper::Execute()
126 if (!mStatement)
127 return NS_ERROR_FAILURE;
129 return mStatement->Execute();
132 NS_IMETHODIMP
133 mozStorageStatementWrapper::GetRow(mozIStorageStatementRow **aRow)
135 NS_ENSURE_ARG_POINTER(aRow);
137 if (!mStatement)
138 return NS_ERROR_FAILURE;
140 PRInt32 state;
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);
147 if (!row)
148 return NS_ERROR_OUT_OF_MEMORY;
149 mStatementRow = row;
152 NS_ADDREF(*aRow = mStatementRow);
153 return NS_OK;
156 NS_IMETHODIMP
157 mozStorageStatementWrapper::GetParams(mozIStorageStatementParams **aParams)
159 NS_ENSURE_ARG_POINTER(aParams);
161 if (!mStatementParams) {
162 mozStorageStatementParams *params = new mozStorageStatementParams(mStatement);
163 if (!params)
164 return NS_ERROR_OUT_OF_MEMORY;
165 mStatementParams = params;
168 NS_ADDREF(*aParams = mStatementParams);
169 return NS_OK;
172 /*** nsIXPCScriptable interface ***/
174 /* readonly attribute string className; */
175 NS_IMETHODIMP
176 mozStorageStatementWrapper::GetClassName(char * *aClassName)
178 NS_ENSURE_ARG_POINTER(aClassName);
179 *aClassName = (char *) nsMemory::Clone("mozStorageStatementWrapper", 27);
180 if (!*aClassName)
181 return NS_ERROR_OUT_OF_MEMORY;
182 return NS_OK;
185 /* readonly attribute PRUint32 scriptableFlags; */
186 NS_IMETHODIMP
187 mozStorageStatementWrapper::GetScriptableFlags(PRUint32 *aScriptableFlags)
189 *aScriptableFlags =
190 nsIXPCScriptable::WANT_CALL |
191 nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY |
192 nsIXPCScriptable::WANT_NEWRESOLVE |
193 nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE;
194 return NS_OK;
197 /* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
198 NS_IMETHODIMP
199 mozStorageStatementWrapper::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
200 JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
202 if (!mStatement) {
203 *_retval = PR_TRUE;
204 return NS_ERROR_FAILURE;
207 if (argc != mParamCount) {
208 *_retval = PR_FALSE;
209 return NS_ERROR_FAILURE;
212 // reset
213 mStatement->Reset();
215 // bind parameters
216 for (int i = 0; i < (int) argc; i++) {
217 if (!JSValStorageStatementBinder(cx, mStatement, i, argv[i])) {
218 *_retval = PR_FALSE;
219 return NS_ERROR_INVALID_ARG;
223 // if there are no results, we just execute
224 if (mResultColumnCount == 0)
225 mStatement->Execute();
227 *vp = JSVAL_TRUE;
228 *_retval = PR_TRUE;
229 return NS_OK;
232 /* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
233 NS_IMETHODIMP
234 mozStorageStatementWrapper::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
235 JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
237 *_retval = PR_FALSE;
238 return NS_OK;
242 /* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
243 NS_IMETHODIMP
244 mozStorageStatementWrapper::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
245 JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
247 *_retval = PR_FALSE;
248 return NS_OK;
251 /* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
252 NS_IMETHODIMP
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); */
260 NS_IMETHODIMP
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); */
267 NS_IMETHODIMP
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); */
274 NS_IMETHODIMP
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); */
282 NS_IMETHODIMP
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); */
290 NS_IMETHODIMP
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); */
298 NS_IMETHODIMP
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); */
306 NS_IMETHODIMP
307 mozStorageStatementWrapper::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
308 JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp, PRBool *_retval)
310 *_retval = PR_TRUE;
311 return NS_OK;
314 /* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
315 NS_IMETHODIMP
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); */
323 NS_IMETHODIMP
324 mozStorageStatementWrapper::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
325 JSObject * obj)
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); */
331 NS_IMETHODIMP
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); */
339 NS_IMETHODIMP
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); */
347 NS_IMETHODIMP
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); */
355 NS_IMETHODIMP
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); */
363 NS_IMETHODIMP
364 mozStorageStatementWrapper::Equality(nsIXPConnectWrappedNative *wrapper,
365 JSContext *cx, JSObject *obj, jsval val,
366 PRBool *_retval)
368 return NS_ERROR_NOT_IMPLEMENTED;
371 /* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
372 NS_IMETHODIMP
373 mozStorageStatementWrapper::OuterObject(nsIXPConnectWrappedNative *wrapper,
374 JSContext *cx, JSObject *obj,
375 JSObject **_retval)
377 return NS_ERROR_NOT_IMPLEMENTED;
380 /* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
381 NS_IMETHODIMP
382 mozStorageStatementWrapper::InnerObject(nsIXPConnectWrappedNative *wrapper,
383 JSContext *cx, JSObject *obj,
384 JSObject **_retval)
386 return NS_ERROR_NOT_IMPLEMENTED;
389 /* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
390 NS_IMETHODIMP
391 mozStorageStatementWrapper::PostCreatePrototype(JSContext * cx,
392 JSObject * proto)
394 return NS_OK;