Bug 456330. Fix translation to account for top/left padding. r=vlad
[mozilla-central.git] / storage / src / mozStorageStatementRow.cpp
blob90b14d47953617994bc93b7cceb565a548741d7c
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 if (JSVAL_IS_STRING(id)) {
96 nsDependentCString jsid(::JS_GetStringBytes(JSVAL_TO_STRING(id)));
98 PRUint32 idx;
99 nsresult rv = mStatement->GetColumnIndex(jsid, &idx);
100 NS_ENSURE_SUCCESS(rv, rv);
101 int ctype = sqlite3_column_type(NativeStatement(), idx);
103 if (ctype == SQLITE_INTEGER || ctype == SQLITE_FLOAT) {
104 double dval = sqlite3_column_double(NativeStatement(), idx);
105 if (!JS_NewNumberValue(cx, dval, vp)) {
106 *_retval = PR_FALSE;
107 return NS_OK;
109 } else if (ctype == SQLITE_TEXT) {
110 JSString *str = JS_NewUCStringCopyN(cx,
111 (jschar*) sqlite3_column_text16(NativeStatement(), idx),
112 sqlite3_column_bytes16(NativeStatement(), idx)/2);
113 if (!str) {
114 *_retval = PR_FALSE;
115 return NS_OK;
117 *vp = STRING_TO_JSVAL(str);
118 } else if (ctype == SQLITE_BLOB) {
119 JSString *str = JS_NewStringCopyN(cx,
120 (char*) sqlite3_column_blob(NativeStatement(), idx),
121 sqlite3_column_bytes(NativeStatement(), idx));
122 if (!str) {
123 *_retval = PR_FALSE;
124 return NS_OK;
126 } else if (ctype == SQLITE_NULL) {
127 *vp = JSVAL_NULL;
128 } else {
129 NS_ERROR("sqlite3_column_type returned unknown column type, what's going on?");
133 return NS_OK;
137 /* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
138 NS_IMETHODIMP
139 mozStorageStatementRow::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
140 JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
142 return NS_ERROR_NOT_IMPLEMENTED;
145 /* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
146 NS_IMETHODIMP
147 mozStorageStatementRow::PreCreate(nsISupports *nativeObj, JSContext * cx,
148 JSObject * globalObj, JSObject * *parentObj)
150 return NS_ERROR_NOT_IMPLEMENTED;
153 /* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
154 NS_IMETHODIMP
155 mozStorageStatementRow::Create(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
157 return NS_ERROR_NOT_IMPLEMENTED;
160 /* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
161 NS_IMETHODIMP
162 mozStorageStatementRow::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
164 return NS_ERROR_NOT_IMPLEMENTED;
167 /* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
168 NS_IMETHODIMP
169 mozStorageStatementRow::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
170 JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
172 return NS_ERROR_NOT_IMPLEMENTED;
175 /* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
176 NS_IMETHODIMP
177 mozStorageStatementRow::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
178 JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
180 return NS_ERROR_NOT_IMPLEMENTED;
183 /* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
184 NS_IMETHODIMP
185 mozStorageStatementRow::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
186 JSObject * obj, PRBool *_retval)
188 return NS_ERROR_NOT_IMPLEMENTED;
191 /* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
192 NS_IMETHODIMP
193 mozStorageStatementRow::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
194 JSObject * obj, PRUint32 enum_op, jsval * statep, jsid *idp, PRBool *_retval)
196 return NS_ERROR_NOT_IMPLEMENTED;
199 /* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
200 NS_IMETHODIMP
201 mozStorageStatementRow::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
202 JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp, PRBool *_retval)
204 if (JSVAL_IS_STRING(id)) {
205 JSString *str = JSVAL_TO_STRING(id);
206 nsDependentCString name(::JS_GetStringBytes(str));
208 PRUint32 idx;
209 nsresult rv = mStatement->GetColumnIndex(name, &idx);
210 NS_ENSURE_SUCCESS(rv, rv);
212 *_retval = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
213 ::JS_GetStringLength(str),
214 JSVAL_VOID,
215 nsnull, nsnull, 0);
216 *objp = obj;
217 return *_retval ? NS_OK : NS_ERROR_FAILURE;
220 *_retval = PR_TRUE;
221 return NS_OK;
224 /* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
225 NS_IMETHODIMP
226 mozStorageStatementRow::Convert(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
227 JSObject * obj, PRUint32 type, jsval * vp, PRBool *_retval)
229 return NS_ERROR_NOT_IMPLEMENTED;
232 /* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
233 NS_IMETHODIMP
234 mozStorageStatementRow::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
235 JSObject * obj)
237 return NS_ERROR_NOT_IMPLEMENTED;
240 /* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
241 NS_IMETHODIMP
242 mozStorageStatementRow::CheckAccess(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
243 JSObject * obj, jsval id, PRUint32 mode, jsval * vp, PRBool *_retval)
245 return NS_ERROR_NOT_IMPLEMENTED;
248 /* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
249 NS_IMETHODIMP
250 mozStorageStatementRow::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
251 JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
253 return NS_ERROR_NOT_IMPLEMENTED;
256 /* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
257 NS_IMETHODIMP
258 mozStorageStatementRow::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
259 JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
261 return NS_ERROR_NOT_IMPLEMENTED;
264 /* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
265 NS_IMETHODIMP
266 mozStorageStatementRow::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
267 JSObject * obj, jsval val, PRBool *bp, PRBool *_retval)
269 return NS_ERROR_NOT_IMPLEMENTED;
272 /* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
273 NS_IMETHODIMP
274 mozStorageStatementRow::Trace(nsIXPConnectWrappedNative *wrapper,
275 JSTracer * trc, JSObject * obj)
277 return NS_ERROR_NOT_IMPLEMENTED;
280 /* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
281 NS_IMETHODIMP
282 mozStorageStatementRow::Equality(nsIXPConnectWrappedNative *wrapper,
283 JSContext *cx, JSObject *obj, jsval val,
284 PRBool *_retval)
286 return NS_ERROR_NOT_IMPLEMENTED;
289 /* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
290 NS_IMETHODIMP
291 mozStorageStatementRow::OuterObject(nsIXPConnectWrappedNative *wrapper,
292 JSContext *cx, JSObject *obj,
293 JSObject **_retval)
295 return NS_ERROR_NOT_IMPLEMENTED;
298 /* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
299 NS_IMETHODIMP
300 mozStorageStatementRow::InnerObject(nsIXPConnectWrappedNative *wrapper,
301 JSContext *cx, JSObject *obj,
302 JSObject **_retval)
304 return NS_ERROR_NOT_IMPLEMENTED;
307 /* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
308 NS_IMETHODIMP
309 mozStorageStatementRow::PostCreatePrototype(JSContext * cx, JSObject * proto)
311 return NS_OK;