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 "mozStorageStatementRow.h"
51 /*************************************************************************
53 **** mozStorageStatementRow
55 *************************************************************************/
57 NS_IMPL_ISUPPORTS2(mozStorageStatementRow
, mozIStorageStatementRow
, nsIXPCScriptable
)
59 mozStorageStatementRow::mozStorageStatementRow(mozStorageStatement
*aStatement
)
60 : mStatement(aStatement
)
65 * nsIXPCScriptable impl
68 /* readonly attribute string className; */
70 mozStorageStatementRow::GetClassName(char * *aClassName
)
72 NS_ENSURE_ARG_POINTER(aClassName
);
73 *aClassName
= (char *) nsMemory::Clone("mozStorageStatementRow", 23);
75 return NS_ERROR_OUT_OF_MEMORY
;
79 /* readonly attribute PRUint32 scriptableFlags; */
81 mozStorageStatementRow::GetScriptableFlags(PRUint32
*aScriptableFlags
)
84 nsIXPCScriptable::WANT_GETPROPERTY
|
85 nsIXPCScriptable::WANT_NEWRESOLVE
|
86 nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
;
90 /* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
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
)));
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
)) {
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);
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
));
128 } else if (ctype
== SQLITE_NULL
) {
131 NS_ERROR("sqlite3_column_type returned unknown column type, what's going on?");
139 /* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
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); */
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); */
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); */
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); */
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); */
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); */
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); */
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); */
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
));
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
),
221 return *_retval
? NS_OK
: NS_ERROR_FAILURE
;
228 /* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
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); */
238 mozStorageStatementRow::Finalize(nsIXPConnectWrappedNative
*wrapper
, JSContext
* cx
,
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); */
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); */
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); */
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); */
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); */
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); */
286 mozStorageStatementRow::Equality(nsIXPConnectWrappedNative
*wrapper
,
287 JSContext
*cx
, JSObject
*obj
, jsval val
,
290 return NS_ERROR_NOT_IMPLEMENTED
;
293 /* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
295 mozStorageStatementRow::OuterObject(nsIXPConnectWrappedNative
*wrapper
,
296 JSContext
*cx
, JSObject
*obj
,
299 return NS_ERROR_NOT_IMPLEMENTED
;
302 /* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
304 mozStorageStatementRow::InnerObject(nsIXPConnectWrappedNative
*wrapper
,
305 JSContext
*cx
, JSObject
*obj
,
308 return NS_ERROR_NOT_IMPLEMENTED
;
311 /* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
313 mozStorageStatementRow::PostCreatePrototype(JSContext
* cx
, JSObject
* proto
)