Bug 481045. <svg:use> shouldn't paint its kids. r+sr=roc
[mozilla-central.git] / storage / src / mozStorageStatementRow.cpp
blobffeadccaa1349e44ece6ccb8312c6ac898f62570
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 "mozStorageStatementRow.h"
46 #include "jsapi.h"
47 #include "jsdate.h"
49 #include "sqlite3.h"
51 /*************************************************************************
52 ****
53 **** mozStorageStatementRow
54 ****
55 *************************************************************************/
57 NS_IMPL_ISUPPORTS2(mozStorageStatementRow, mozIStorageStatementRow, nsIXPCScriptable)
59 mozStorageStatementRow::mozStorageStatementRow(mozStorageStatement *aStatement)
60 : mStatement(aStatement)
65 * nsIXPCScriptable impl
68 /* readonly attribute string className; */
69 NS_IMETHODIMP
70 mozStorageStatementRow::GetClassName(char * *aClassName)
72 NS_ENSURE_ARG_POINTER(aClassName);
73 *aClassName = (char *) nsMemory::Clone("mozStorageStatementRow", 23);
74 if (!*aClassName)
75 return NS_ERROR_OUT_OF_MEMORY;
76 return NS_OK;
79 /* readonly attribute PRUint32 scriptableFlags; */
80 NS_IMETHODIMP
81 mozStorageStatementRow::GetScriptableFlags(PRUint32 *aScriptableFlags)
83 *aScriptableFlags =
84 nsIXPCScriptable::WANT_GETPROPERTY |
85 nsIXPCScriptable::WANT_NEWRESOLVE |
86 nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE;
87 return NS_OK;
90 /* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
91 NS_IMETHODIMP
92 mozStorageStatementRow::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
93 JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
95 NS_ENSURE_TRUE(mStatement, NS_ERROR_NOT_INITIALIZED);
97 if (JSVAL_IS_STRING(id)) {
98 nsDependentCString jsid(::JS_GetStringBytes(JSVAL_TO_STRING(id)));
100 PRUint32 idx;
101 nsresult rv = mStatement->GetColumnIndex(jsid, &idx);
102 NS_ENSURE_SUCCESS(rv, rv);
103 int ctype = sqlite3_column_type(NativeStatement(), idx);
105 if (ctype == SQLITE_INTEGER || ctype == SQLITE_FLOAT) {
106 double dval = sqlite3_column_double(NativeStatement(), idx);
107 if (!JS_NewNumberValue(cx, dval, vp)) {
108 *_retval = PR_FALSE;
109 return NS_OK;
111 } else if (ctype == SQLITE_TEXT) {
112 JSString *str = JS_NewUCStringCopyN(cx,
113 (jschar*) sqlite3_column_text16(NativeStatement(), idx),
114 sqlite3_column_bytes16(NativeStatement(), idx)/2);
115 if (!str) {
116 *_retval = PR_FALSE;
117 return NS_OK;
119 *vp = STRING_TO_JSVAL(str);
120 } else if (ctype == SQLITE_BLOB) {
121 JSString *str = JS_NewStringCopyN(cx,
122 (char*) sqlite3_column_blob(NativeStatement(), idx),
123 sqlite3_column_bytes(NativeStatement(), idx));
124 if (!str) {
125 *_retval = PR_FALSE;
126 return NS_OK;
128 } else if (ctype == SQLITE_NULL) {
129 *vp = JSVAL_NULL;
130 } else {
131 NS_ERROR("sqlite3_column_type returned unknown column type, what's going on?");
135 return NS_OK;
139 /* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
140 NS_IMETHODIMP
141 mozStorageStatementRow::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
142 JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
144 return NS_ERROR_NOT_IMPLEMENTED;
147 /* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
148 NS_IMETHODIMP
149 mozStorageStatementRow::PreCreate(nsISupports *nativeObj, JSContext * cx,
150 JSObject * globalObj, JSObject * *parentObj)
152 return NS_ERROR_NOT_IMPLEMENTED;
155 /* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
156 NS_IMETHODIMP
157 mozStorageStatementRow::Create(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
159 return NS_ERROR_NOT_IMPLEMENTED;
162 /* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
163 NS_IMETHODIMP
164 mozStorageStatementRow::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
166 return NS_ERROR_NOT_IMPLEMENTED;
169 /* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
170 NS_IMETHODIMP
171 mozStorageStatementRow::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
172 JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
174 return NS_ERROR_NOT_IMPLEMENTED;
177 /* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
178 NS_IMETHODIMP
179 mozStorageStatementRow::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
180 JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
182 return NS_ERROR_NOT_IMPLEMENTED;
185 /* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
186 NS_IMETHODIMP
187 mozStorageStatementRow::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
188 JSObject * obj, PRBool *_retval)
190 return NS_ERROR_NOT_IMPLEMENTED;
193 /* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
194 NS_IMETHODIMP
195 mozStorageStatementRow::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
196 JSObject * obj, PRUint32 enum_op, jsval * statep, jsid *idp, PRBool *_retval)
198 return NS_ERROR_NOT_IMPLEMENTED;
201 /* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
202 NS_IMETHODIMP
203 mozStorageStatementRow::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
204 JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp, PRBool *_retval)
206 NS_ENSURE_TRUE(mStatement, NS_ERROR_NOT_INITIALIZED);
208 if (JSVAL_IS_STRING(id)) {
209 JSString *str = JSVAL_TO_STRING(id);
210 nsDependentCString name(::JS_GetStringBytes(str));
212 PRUint32 idx;
213 nsresult rv = mStatement->GetColumnIndex(name, &idx);
214 NS_ENSURE_SUCCESS(rv, rv);
216 *_retval = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
217 ::JS_GetStringLength(str),
218 JSVAL_VOID,
219 nsnull, nsnull, 0);
220 *objp = obj;
221 return *_retval ? NS_OK : NS_ERROR_FAILURE;
224 *_retval = PR_TRUE;
225 return NS_OK;
228 /* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
229 NS_IMETHODIMP
230 mozStorageStatementRow::Convert(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
231 JSObject * obj, PRUint32 type, jsval * vp, PRBool *_retval)
233 return NS_ERROR_NOT_IMPLEMENTED;
236 /* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
237 NS_IMETHODIMP
238 mozStorageStatementRow::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
239 JSObject * obj)
241 return NS_ERROR_NOT_IMPLEMENTED;
244 /* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
245 NS_IMETHODIMP
246 mozStorageStatementRow::CheckAccess(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
247 JSObject * obj, jsval id, PRUint32 mode, jsval * vp, PRBool *_retval)
249 return NS_ERROR_NOT_IMPLEMENTED;
252 /* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
253 NS_IMETHODIMP
254 mozStorageStatementRow::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
255 JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
257 return NS_ERROR_NOT_IMPLEMENTED;
260 /* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
261 NS_IMETHODIMP
262 mozStorageStatementRow::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
263 JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
265 return NS_ERROR_NOT_IMPLEMENTED;
268 /* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
269 NS_IMETHODIMP
270 mozStorageStatementRow::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
271 JSObject * obj, jsval val, PRBool *bp, PRBool *_retval)
273 return NS_ERROR_NOT_IMPLEMENTED;
276 /* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
277 NS_IMETHODIMP
278 mozStorageStatementRow::Trace(nsIXPConnectWrappedNative *wrapper,
279 JSTracer * trc, JSObject * obj)
281 return NS_ERROR_NOT_IMPLEMENTED;
284 /* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
285 NS_IMETHODIMP
286 mozStorageStatementRow::Equality(nsIXPConnectWrappedNative *wrapper,
287 JSContext *cx, JSObject *obj, jsval val,
288 PRBool *_retval)
290 return NS_ERROR_NOT_IMPLEMENTED;
293 /* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
294 NS_IMETHODIMP
295 mozStorageStatementRow::OuterObject(nsIXPConnectWrappedNative *wrapper,
296 JSContext *cx, JSObject *obj,
297 JSObject **_retval)
299 return NS_ERROR_NOT_IMPLEMENTED;
302 /* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
303 NS_IMETHODIMP
304 mozStorageStatementRow::InnerObject(nsIXPConnectWrappedNative *wrapper,
305 JSContext *cx, JSObject *obj,
306 JSObject **_retval)
308 return NS_ERROR_NOT_IMPLEMENTED;
311 /* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
312 NS_IMETHODIMP
313 mozStorageStatementRow::PostCreatePrototype(JSContext * cx, JSObject * proto)
315 return NS_OK;