mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 452897 - Automatically provide the wrapper for JS
This changeset has no code changes - it just separates three classes that were all contained in one file into three files (with appropriate headers). This is being done to make the actual code changes for the bug simpler. rs=me
This commit is contained in:
parent
e9ee3f8f7d
commit
3c7e641f24
@ -62,18 +62,20 @@ REQUIRES = xpcom \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
mozStorageService.cpp \
|
||||
mozStorageConnection.cpp \
|
||||
mozStorageStatement.cpp \
|
||||
mozStorageStatementWrapper.cpp \
|
||||
mozStorageValueArray.cpp \
|
||||
mozStorageUnicodeFunctions.cpp \
|
||||
mozStorageRow.cpp \
|
||||
mozStorageResultSet.cpp \
|
||||
mozStorageService.cpp \
|
||||
mozStorageConnection.cpp \
|
||||
mozStorageStatement.cpp \
|
||||
mozStorageStatementWrapper.cpp \
|
||||
mozStorageStatementParams.cpp \
|
||||
mozStorageStatementRow.cpp \
|
||||
mozStorageValueArray.cpp \
|
||||
mozStorageUnicodeFunctions.cpp \
|
||||
mozStorageRow.cpp \
|
||||
mozStorageResultSet.cpp \
|
||||
mozStorageError.cpp \
|
||||
mozStorageBackground.cpp \
|
||||
mozStorageEvents.cpp \
|
||||
$(NULL)
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
$(SQLITE_CFLAGS)
|
||||
|
333
storage/src/mozStorageStatementParams.cpp
Normal file
333
storage/src/mozStorageStatementParams.cpp
Normal file
@ -0,0 +1,333 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: sw=4 ts=4 sts=4
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Oracle Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Oracle Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
|
||||
* Shawn Wilsher <me@shawnwilsher.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsMemory.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "mozStorageStatementParams.h"
|
||||
|
||||
#include "sqlite3.h"
|
||||
|
||||
/*************************************************************************
|
||||
****
|
||||
**** mozStorageStatementParams
|
||||
****
|
||||
*************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS2(mozStorageStatementParams, mozIStorageStatementParams, nsIXPCScriptable)
|
||||
|
||||
mozStorageStatementParams::mozStorageStatementParams(mozIStorageStatement *aStatement)
|
||||
: mStatement(aStatement)
|
||||
{
|
||||
NS_ASSERTION(mStatement != nsnull, "mStatement is null");
|
||||
mStatement->GetParameterCount(&mParamCount);
|
||||
}
|
||||
|
||||
/*
|
||||
* nsIXPCScriptable impl
|
||||
*/
|
||||
|
||||
/* readonly attribute string className; */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::GetClassName(char * *aClassName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aClassName);
|
||||
*aClassName = (char *) nsMemory::Clone("mozStorageStatementParams", 26);
|
||||
if (!*aClassName)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute PRUint32 scriptableFlags; */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::GetScriptableFlags(PRUint32 *aScriptableFlags)
|
||||
{
|
||||
*aScriptableFlags =
|
||||
nsIXPCScriptable::WANT_SETPROPERTY |
|
||||
nsIXPCScriptable::WANT_NEWRESOLVE |
|
||||
nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
/* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
int idx = JSVAL_TO_INT(id);
|
||||
|
||||
*_retval = JSValStorageStatementBinder (cx, mStatement, idx, *vp);
|
||||
} else if (JSVAL_IS_STRING(id)) {
|
||||
sqlite3_stmt *stmt = mStatement->GetNativeStatementPointer();
|
||||
|
||||
JSString *str = JSVAL_TO_STRING(id);
|
||||
nsCAutoString name(":");
|
||||
name.Append(NS_ConvertUTF16toUTF8(nsDependentString((PRUnichar *)::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str))));
|
||||
|
||||
// check to see if there's a parameter with this name
|
||||
if (sqlite3_bind_parameter_index(stmt, name.get()) == 0) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
*_retval = PR_TRUE;
|
||||
// You can use a named parameter more than once in a statement...
|
||||
int count = sqlite3_bind_parameter_count(stmt);
|
||||
for (int i = 0; (i < count) && (*_retval); i++) {
|
||||
// sqlite indices start at 1
|
||||
const char *pName = sqlite3_bind_parameter_name(stmt, i + 1);
|
||||
if (name.Equals(pName))
|
||||
*_retval = JSValStorageStatementBinder(cx, mStatement, i, *vp);
|
||||
}
|
||||
} else {
|
||||
*_retval = PR_FALSE;
|
||||
}
|
||||
|
||||
return (*_retval) ? NS_OK : NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::PreCreate(nsISupports *nativeObj, JSContext * cx,
|
||||
JSObject * globalObj, JSObject * *parentObj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Create(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 enum_op, jsval * statep, jsid *idp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp, PRBool *_retval)
|
||||
{
|
||||
int idx = -1;
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
idx = JSVAL_TO_INT(id);
|
||||
} else if (JSVAL_IS_STRING(id)) {
|
||||
JSString *str = JSVAL_TO_STRING(id);
|
||||
nsCAutoString name(":");
|
||||
name.Append(NS_ConvertUTF16toUTF8(nsDependentString((PRUnichar *)::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str))));
|
||||
|
||||
// check to see if there's a parameter with this name
|
||||
idx = sqlite3_bind_parameter_index(mStatement->GetNativeStatementPointer(), name.get());
|
||||
if (idx == 0) {
|
||||
// nope.
|
||||
fprintf (stderr, "********** mozStorageStatementWrapper: Couldn't find parameter %s\n", name.get());
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
} else {
|
||||
// set idx, so that the numbered property also gets defined
|
||||
idx = idx - 1;
|
||||
}
|
||||
|
||||
PRBool success = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str),
|
||||
JSVAL_VOID,
|
||||
nsnull, nsnull, 0);
|
||||
if (!success) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx == -1) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// is it out of range?
|
||||
if (idx < 0 || idx >= (int)mParamCount) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*_retval = ::JS_DefineElement(cx, obj, idx, JSVAL_VOID, nsnull, nsnull, 0);
|
||||
if (*_retval)
|
||||
*objp = obj;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Convert(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 type, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::CheckAccess(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, PRUint32 mode, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval val, PRBool *bp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Trace(nsIXPConnectWrappedNative *wrapper,
|
||||
JSTracer *trc, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Equality(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj, jsval val,
|
||||
PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::OuterObject(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj,
|
||||
JSObject **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::InnerObject(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj,
|
||||
JSObject **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::PostCreatePrototype(JSContext * cx, JSObject * proto)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
104
storage/src/mozStorageStatementParams.h
Normal file
104
storage/src/mozStorageStatementParams.h
Normal file
@ -0,0 +1,104 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Oracle Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Oracle Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _MOZSTORAGESTATEMENTPARAMS_H_
|
||||
#define _MOZSTORAGESTATEMENTPARAMS_H_
|
||||
|
||||
#include "mozIStorageStatement.h"
|
||||
#include "mozIStorageStatementWrapper.h"
|
||||
#include "nsIXPCScriptable.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "jsdate.h"
|
||||
|
||||
class mozStorageStatementParams : public mozIStorageStatementParams,
|
||||
public nsIXPCScriptable
|
||||
{
|
||||
public:
|
||||
mozStorageStatementParams(mozIStorageStatement *aStatement);
|
||||
|
||||
// interfaces
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_MOZISTORAGESTATEMENTPARAMS
|
||||
NS_DECL_NSIXPCSCRIPTABLE
|
||||
|
||||
protected:
|
||||
nsCOMPtr<mozIStorageStatement> mStatement;
|
||||
PRUint32 mParamCount;
|
||||
};
|
||||
|
||||
static PRBool
|
||||
JSValStorageStatementBinder (JSContext *cx,
|
||||
mozIStorageStatement *aStatement,
|
||||
int aIdx,
|
||||
jsval val)
|
||||
{
|
||||
if (JSVAL_IS_INT(val)) {
|
||||
int v = JSVAL_TO_INT(val);
|
||||
(void)aStatement->BindInt32Parameter(aIdx, v);
|
||||
} else if (JSVAL_IS_DOUBLE(val)) {
|
||||
double d = *JSVAL_TO_DOUBLE(val);
|
||||
(void)aStatement->BindDoubleParameter(aIdx, d);
|
||||
} else if (JSVAL_IS_STRING(val)) {
|
||||
JSString *str = JSVAL_TO_STRING(val);
|
||||
(void)aStatement->BindStringParameter(aIdx, nsDependentString(reinterpret_cast<PRUnichar*>(JS_GetStringChars(str)), JS_GetStringLength(str)));
|
||||
} else if (JSVAL_IS_BOOLEAN(val)) {
|
||||
(void)aStatement->BindInt32Parameter(aIdx, (val == JSVAL_TRUE) ? 1 : 0);
|
||||
} else if (JSVAL_IS_NULL(val)) {
|
||||
(void)aStatement->BindNullParameter(aIdx);
|
||||
} else if (JSVAL_IS_OBJECT(val)) {
|
||||
JSObject *obj = JSVAL_TO_OBJECT(val);
|
||||
// some special things
|
||||
if (js_DateIsValid (cx, obj)) {
|
||||
double msecd = js_DateGetMsecSinceEpoch(cx, obj);
|
||||
msecd *= 1000.0;
|
||||
PRInt64 msec;
|
||||
LL_D2L(msec, msecd);
|
||||
|
||||
(void)aStatement->BindInt64Parameter(aIdx, msec);
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
#endif /* _MOZSTORAGESTATEMENTPARAMS_H_ */
|
321
storage/src/mozStorageStatementRow.cpp
Normal file
321
storage/src/mozStorageStatementRow.cpp
Normal file
@ -0,0 +1,321 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: sw=4 ts=4 sts=4
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Oracle Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Oracle Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
|
||||
* Shawn Wilsher <me@shawnwilsher.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsMemory.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "mozStorageStatementRow.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "jsdate.h"
|
||||
|
||||
#include "sqlite3.h"
|
||||
|
||||
/*************************************************************************
|
||||
****
|
||||
**** mozStorageStatementRow
|
||||
****
|
||||
*************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS2(mozStorageStatementRow, mozIStorageStatementRow, nsIXPCScriptable)
|
||||
|
||||
mozStorageStatementRow::mozStorageStatementRow(mozIStorageStatement *aStatement,
|
||||
int aNumColumns,
|
||||
const nsStringArray *aColumnNames)
|
||||
: mStatement(aStatement),
|
||||
mNumColumns(aNumColumns),
|
||||
mColumnNames(aColumnNames)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* nsIXPCScriptable impl
|
||||
*/
|
||||
|
||||
/* readonly attribute string className; */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::GetClassName(char * *aClassName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aClassName);
|
||||
*aClassName = (char *) nsMemory::Clone("mozStorageStatementRow", 23);
|
||||
if (!*aClassName)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute PRUint32 scriptableFlags; */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::GetScriptableFlags(PRUint32 *aScriptableFlags)
|
||||
{
|
||||
*aScriptableFlags =
|
||||
nsIXPCScriptable::WANT_GETPROPERTY |
|
||||
nsIXPCScriptable::WANT_NEWRESOLVE |
|
||||
nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
if (JSVAL_IS_STRING(id)) {
|
||||
nsDependentString jsid((PRUnichar *)::JS_GetStringChars(JSVAL_TO_STRING(id)),
|
||||
::JS_GetStringLength(JSVAL_TO_STRING(id)));
|
||||
|
||||
for (int i = 0; i < mNumColumns; i++) {
|
||||
if (jsid.Equals(*(*mColumnNames)[i])) {
|
||||
int ctype = sqlite3_column_type(NativeStatement(), i);
|
||||
|
||||
if (ctype == SQLITE_INTEGER || ctype == SQLITE_FLOAT) {
|
||||
double dval = sqlite3_column_double(NativeStatement(), i);
|
||||
if (!JS_NewNumberValue(cx, dval, vp)) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
} else if (ctype == SQLITE_TEXT) {
|
||||
JSString *str = JS_NewUCStringCopyN(cx,
|
||||
(jschar*) sqlite3_column_text16(NativeStatement(), i),
|
||||
sqlite3_column_bytes16(NativeStatement(), i)/2);
|
||||
if (!str) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
} else if (ctype == SQLITE_BLOB) {
|
||||
JSString *str = JS_NewStringCopyN(cx,
|
||||
(char*) sqlite3_column_blob(NativeStatement(), i),
|
||||
sqlite3_column_bytes(NativeStatement(), i));
|
||||
if (!str) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
} else if (ctype == SQLITE_NULL) {
|
||||
*vp = JSVAL_NULL;
|
||||
} else {
|
||||
NS_ERROR("sqlite3_column_type returned unknown column type, what's going on?");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::PreCreate(nsISupports *nativeObj, JSContext * cx,
|
||||
JSObject * globalObj, JSObject * *parentObj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Create(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 enum_op, jsval * statep, jsid *idp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp, PRBool *_retval)
|
||||
{
|
||||
if (JSVAL_IS_STRING(id)) {
|
||||
JSString *str = JSVAL_TO_STRING(id);
|
||||
nsDependentString name((PRUnichar *)::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str));
|
||||
|
||||
for (int i = 0; i < mNumColumns; i++) {
|
||||
if (name.Equals(*(*mColumnNames)[i])) {
|
||||
*_retval = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str),
|
||||
JSVAL_VOID,
|
||||
nsnull, nsnull, 0);
|
||||
*objp = obj;
|
||||
return *_retval ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*_retval = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Convert(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 type, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::CheckAccess(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, PRUint32 mode, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval val, PRBool *bp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Trace(nsIXPConnectWrappedNative *wrapper,
|
||||
JSTracer * trc, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Equality(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj, jsval val,
|
||||
PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::OuterObject(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj,
|
||||
JSObject **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::InnerObject(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj,
|
||||
JSObject **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::PostCreatePrototype(JSContext * cx, JSObject * proto)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
74
storage/src/mozStorageStatementRow.h
Normal file
74
storage/src/mozStorageStatementRow.h
Normal file
@ -0,0 +1,74 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Oracle Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Oracle Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _MOZSTORAGESTATEMENTROW_H_
|
||||
#define _MOZSTORAGESTATEMENTROW_H_
|
||||
|
||||
#include "mozIStorageStatementWrapper.h"
|
||||
#include "nsIXPCScriptable.h"
|
||||
#include "mozIStorageStatement.h"
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
class mozStorageStatementRow : public mozIStorageStatementRow,
|
||||
public nsIXPCScriptable
|
||||
{
|
||||
public:
|
||||
mozStorageStatementRow(mozIStorageStatement *aStatement,
|
||||
int aNumColumns,
|
||||
const nsStringArray *aColumnNames);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// mozIStorageStatementRow interface (empty)
|
||||
NS_DECL_MOZISTORAGESTATEMENTROW
|
||||
|
||||
// nsIXPCScriptable interface
|
||||
NS_DECL_NSIXPCSCRIPTABLE
|
||||
protected:
|
||||
sqlite3_stmt* NativeStatement() {
|
||||
return mStatement->GetNativeStatementPointer();
|
||||
}
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> mStatement;
|
||||
int mNumColumns;
|
||||
const nsStringArray *mColumnNames;
|
||||
};
|
||||
|
||||
#endif /* _MOZSTORAGESTATEMENTROW_H_ */
|
@ -42,99 +42,11 @@
|
||||
#include "nsString.h"
|
||||
|
||||
#include "mozStorageStatementWrapper.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "jsdate.h"
|
||||
#include "mozStorageStatementParams.h"
|
||||
#include "mozStorageStatementRow.h"
|
||||
|
||||
#include "sqlite3.h"
|
||||
|
||||
/**
|
||||
** mozStorageStatementRow
|
||||
**/
|
||||
class mozStorageStatementRow : public mozIStorageStatementRow,
|
||||
public nsIXPCScriptable
|
||||
{
|
||||
public:
|
||||
mozStorageStatementRow(mozIStorageStatement *aStatement,
|
||||
int aNumColumns,
|
||||
const nsStringArray *aColumnNames);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// mozIStorageStatementRow interface (empty)
|
||||
NS_DECL_MOZISTORAGESTATEMENTROW
|
||||
|
||||
// nsIXPCScriptable interface
|
||||
NS_DECL_NSIXPCSCRIPTABLE
|
||||
protected:
|
||||
sqlite3_stmt* NativeStatement() {
|
||||
return mStatement->GetNativeStatementPointer();
|
||||
}
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> mStatement;
|
||||
int mNumColumns;
|
||||
const nsStringArray *mColumnNames;
|
||||
};
|
||||
|
||||
/**
|
||||
** mozStorageStatementParams
|
||||
**/
|
||||
class mozStorageStatementParams : public mozIStorageStatementParams,
|
||||
public nsIXPCScriptable
|
||||
{
|
||||
public:
|
||||
mozStorageStatementParams(mozIStorageStatement *aStatement);
|
||||
|
||||
// interfaces
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_MOZISTORAGESTATEMENTPARAMS
|
||||
NS_DECL_NSIXPCSCRIPTABLE
|
||||
|
||||
protected:
|
||||
nsCOMPtr<mozIStorageStatement> mStatement;
|
||||
PRUint32 mParamCount;
|
||||
};
|
||||
|
||||
static PRBool
|
||||
JSValStorageStatementBinder (JSContext *cx,
|
||||
mozIStorageStatement *aStatement,
|
||||
int aIdx,
|
||||
jsval val)
|
||||
{
|
||||
if (JSVAL_IS_INT(val)) {
|
||||
int v = JSVAL_TO_INT(val);
|
||||
(void)aStatement->BindInt32Parameter(aIdx, v);
|
||||
} else if (JSVAL_IS_DOUBLE(val)) {
|
||||
double d = *JSVAL_TO_DOUBLE(val);
|
||||
(void)aStatement->BindDoubleParameter(aIdx, d);
|
||||
} else if (JSVAL_IS_STRING(val)) {
|
||||
JSString *str = JSVAL_TO_STRING(val);
|
||||
(void)aStatement->BindStringParameter(aIdx, nsDependentString(reinterpret_cast<PRUnichar*>(JS_GetStringChars(str)), JS_GetStringLength(str)));
|
||||
} else if (JSVAL_IS_BOOLEAN(val)) {
|
||||
(void)aStatement->BindInt32Parameter(aIdx, (val == JSVAL_TRUE) ? 1 : 0);
|
||||
} else if (JSVAL_IS_NULL(val)) {
|
||||
(void)aStatement->BindNullParameter(aIdx);
|
||||
} else if (JSVAL_IS_OBJECT(val)) {
|
||||
JSObject *obj = JSVAL_TO_OBJECT(val);
|
||||
// some special things
|
||||
if (js_DateIsValid (cx, obj)) {
|
||||
double msecd = js_DateGetMsecSinceEpoch(cx, obj);
|
||||
msecd *= 1000.0;
|
||||
PRInt64 msec;
|
||||
LL_D2L(msec, msecd);
|
||||
|
||||
(void)aStatement->BindInt64Parameter(aIdx, msec);
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
****
|
||||
@ -481,562 +393,3 @@ mozStorageStatementWrapper::PostCreatePrototype(JSContext * cx,
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
****
|
||||
**** mozStorageStatementRow
|
||||
****
|
||||
*************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS2(mozStorageStatementRow, mozIStorageStatementRow, nsIXPCScriptable)
|
||||
|
||||
mozStorageStatementRow::mozStorageStatementRow(mozIStorageStatement *aStatement,
|
||||
int aNumColumns,
|
||||
const nsStringArray *aColumnNames)
|
||||
: mStatement(aStatement),
|
||||
mNumColumns(aNumColumns),
|
||||
mColumnNames(aColumnNames)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* nsIXPCScriptable impl
|
||||
*/
|
||||
|
||||
/* readonly attribute string className; */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::GetClassName(char * *aClassName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aClassName);
|
||||
*aClassName = (char *) nsMemory::Clone("mozStorageStatementRow", 23);
|
||||
if (!*aClassName)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute PRUint32 scriptableFlags; */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::GetScriptableFlags(PRUint32 *aScriptableFlags)
|
||||
{
|
||||
*aScriptableFlags =
|
||||
nsIXPCScriptable::WANT_GETPROPERTY |
|
||||
nsIXPCScriptable::WANT_NEWRESOLVE |
|
||||
nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
if (JSVAL_IS_STRING(id)) {
|
||||
nsDependentString jsid((PRUnichar *)::JS_GetStringChars(JSVAL_TO_STRING(id)),
|
||||
::JS_GetStringLength(JSVAL_TO_STRING(id)));
|
||||
|
||||
for (int i = 0; i < mNumColumns; i++) {
|
||||
if (jsid.Equals(*(*mColumnNames)[i])) {
|
||||
int ctype = sqlite3_column_type(NativeStatement(), i);
|
||||
|
||||
if (ctype == SQLITE_INTEGER || ctype == SQLITE_FLOAT) {
|
||||
double dval = sqlite3_column_double(NativeStatement(), i);
|
||||
if (!JS_NewNumberValue(cx, dval, vp)) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
} else if (ctype == SQLITE_TEXT) {
|
||||
JSString *str = JS_NewUCStringCopyN(cx,
|
||||
(jschar*) sqlite3_column_text16(NativeStatement(), i),
|
||||
sqlite3_column_bytes16(NativeStatement(), i)/2);
|
||||
if (!str) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
} else if (ctype == SQLITE_BLOB) {
|
||||
JSString *str = JS_NewStringCopyN(cx,
|
||||
(char*) sqlite3_column_blob(NativeStatement(), i),
|
||||
sqlite3_column_bytes(NativeStatement(), i));
|
||||
if (!str) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
} else if (ctype == SQLITE_NULL) {
|
||||
*vp = JSVAL_NULL;
|
||||
} else {
|
||||
NS_ERROR("sqlite3_column_type returned unknown column type, what's going on?");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::PreCreate(nsISupports *nativeObj, JSContext * cx,
|
||||
JSObject * globalObj, JSObject * *parentObj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Create(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 enum_op, jsval * statep, jsid *idp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp, PRBool *_retval)
|
||||
{
|
||||
if (JSVAL_IS_STRING(id)) {
|
||||
JSString *str = JSVAL_TO_STRING(id);
|
||||
nsDependentString name((PRUnichar *)::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str));
|
||||
|
||||
for (int i = 0; i < mNumColumns; i++) {
|
||||
if (name.Equals(*(*mColumnNames)[i])) {
|
||||
*_retval = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str),
|
||||
JSVAL_VOID,
|
||||
nsnull, nsnull, 0);
|
||||
*objp = obj;
|
||||
return *_retval ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*_retval = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Convert(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 type, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::CheckAccess(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, PRUint32 mode, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval val, PRBool *bp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Trace(nsIXPConnectWrappedNative *wrapper,
|
||||
JSTracer * trc, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::Equality(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj, jsval val,
|
||||
PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::OuterObject(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj,
|
||||
JSObject **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::InnerObject(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj,
|
||||
JSObject **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementRow::PostCreatePrototype(JSContext * cx, JSObject * proto)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
****
|
||||
**** mozStorageStatementParams
|
||||
****
|
||||
*************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS2(mozStorageStatementParams, mozIStorageStatementParams, nsIXPCScriptable)
|
||||
|
||||
mozStorageStatementParams::mozStorageStatementParams(mozIStorageStatement *aStatement)
|
||||
: mStatement(aStatement)
|
||||
{
|
||||
NS_ASSERTION(mStatement != nsnull, "mStatement is null");
|
||||
mStatement->GetParameterCount(&mParamCount);
|
||||
}
|
||||
|
||||
/*
|
||||
* nsIXPCScriptable impl
|
||||
*/
|
||||
|
||||
/* readonly attribute string className; */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::GetClassName(char * *aClassName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aClassName);
|
||||
*aClassName = (char *) nsMemory::Clone("mozStorageStatementParams", 26);
|
||||
if (!*aClassName)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute PRUint32 scriptableFlags; */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::GetScriptableFlags(PRUint32 *aScriptableFlags)
|
||||
{
|
||||
*aScriptableFlags =
|
||||
nsIXPCScriptable::WANT_SETPROPERTY |
|
||||
nsIXPCScriptable::WANT_NEWRESOLVE |
|
||||
nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
/* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
int idx = JSVAL_TO_INT(id);
|
||||
|
||||
*_retval = JSValStorageStatementBinder (cx, mStatement, idx, *vp);
|
||||
} else if (JSVAL_IS_STRING(id)) {
|
||||
sqlite3_stmt *stmt = mStatement->GetNativeStatementPointer();
|
||||
|
||||
JSString *str = JSVAL_TO_STRING(id);
|
||||
nsCAutoString name(":");
|
||||
name.Append(NS_ConvertUTF16toUTF8(nsDependentString((PRUnichar *)::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str))));
|
||||
|
||||
// check to see if there's a parameter with this name
|
||||
if (sqlite3_bind_parameter_index(stmt, name.get()) == 0) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
*_retval = PR_TRUE;
|
||||
// You can use a named parameter more than once in a statement...
|
||||
int count = sqlite3_bind_parameter_count(stmt);
|
||||
for (int i = 0; (i < count) && (*_retval); i++) {
|
||||
// sqlite indices start at 1
|
||||
const char *pName = sqlite3_bind_parameter_name(stmt, i + 1);
|
||||
if (name.Equals(pName))
|
||||
*_retval = JSValStorageStatementBinder(cx, mStatement, i, *vp);
|
||||
}
|
||||
} else {
|
||||
*_retval = PR_FALSE;
|
||||
}
|
||||
|
||||
return (*_retval) ? NS_OK : NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* void preCreate (in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::PreCreate(nsISupports *nativeObj, JSContext * cx,
|
||||
JSObject * globalObj, JSObject * *parentObj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void create (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Create(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void postCreate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool addProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool delProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 enum_op, jsval * statep, jsid *idp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp, PRBool *_retval)
|
||||
{
|
||||
int idx = -1;
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
idx = JSVAL_TO_INT(id);
|
||||
} else if (JSVAL_IS_STRING(id)) {
|
||||
JSString *str = JSVAL_TO_STRING(id);
|
||||
nsCAutoString name(":");
|
||||
name.Append(NS_ConvertUTF16toUTF8(nsDependentString((PRUnichar *)::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str))));
|
||||
|
||||
// check to see if there's a parameter with this name
|
||||
idx = sqlite3_bind_parameter_index(mStatement->GetNativeStatementPointer(), name.get());
|
||||
if (idx == 0) {
|
||||
// nope.
|
||||
fprintf (stderr, "********** mozStorageStatementWrapper: Couldn't find parameter %s\n", name.get());
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
} else {
|
||||
// set idx, so that the numbered property also gets defined
|
||||
idx = idx - 1;
|
||||
}
|
||||
|
||||
PRBool success = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
|
||||
::JS_GetStringLength(str),
|
||||
JSVAL_VOID,
|
||||
nsnull, nsnull, 0);
|
||||
if (!success) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx == -1) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// is it out of range?
|
||||
if (idx < 0 || idx >= (int)mParamCount) {
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*_retval = ::JS_DefineElement(cx, obj, idx, JSVAL_VOID, nsnull, nsnull, 0);
|
||||
if (*_retval)
|
||||
*objp = obj;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* PRBool convert (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 type, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Convert(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 type, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void finalize (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool checkAccess (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 mode, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::CheckAccess(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval id, PRUint32 mode, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, jsval val, PRBool *bp, PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void trace (in nsIXPConnectWrappedNative wrapper, in JSTracerPtr trc, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Trace(nsIXPConnectWrappedNative *wrapper,
|
||||
JSTracer *trc, JSObject * obj)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* PRBool equality(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::Equality(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj, jsval val,
|
||||
PRBool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* JSObjectPtr outerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::OuterObject(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj,
|
||||
JSObject **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* JSObjectPtr innerObject(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::InnerObject(nsIXPConnectWrappedNative *wrapper,
|
||||
JSContext *cx, JSObject *obj,
|
||||
JSObject **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void postCreatePrototype (in JSContextPtr cx, in JSObjectPtr proto); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatementParams::PostCreatePrototype(JSContext * cx, JSObject * proto)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user