Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
mozStorageStatementWrapper.cpp File Reference
#include "nsMemory.h"
#include "nsString.h"
#include "mozStorageStatementWrapper.h"
#include "jsapi.h"
#include "jsdate.h"
#include "sqlite3.h"

Go to the source code of this file.

Classes

class  mozStorageStatementRow
 mozStorageStatementRow More...
class  mozStorageStatementParams
 mozStorageStatementParams More...

Functions

static PRBool JSValStorageStatementBinder (JSContext *cx, mozIStorageStatement *aStatement, int *aParamIndexes, int aNumIndexes, jsval val)

Function Documentation

static PRBool JSValStorageStatementBinder ( JSContext cx,
mozIStorageStatement aStatement,
int aParamIndexes,
int  aNumIndexes,
jsval  val 
) [static]

Definition at line 98 of file mozStorageStatementWrapper.cpp.

{
    int i;
    if (JSVAL_IS_INT(val)) {
        int v = JSVAL_TO_INT(val);
        for (i = 0; i < aNumIndexes; i++)
            aStatement->BindInt32Parameter(aParamIndexes[i], v);
    } else if (JSVAL_IS_DOUBLE(val)) {
        double d = *JSVAL_TO_DOUBLE(val);
        for (i = 0; i < aNumIndexes; i++)
            aStatement->BindDoubleParameter(aParamIndexes[i], d);
    } else if (JSVAL_IS_STRING(val)) {
        JSString *str = JSVAL_TO_STRING(val);
        for (i = 0; i < aNumIndexes; i++)
            aStatement->BindStringParameter(aParamIndexes[i], nsDependentString(NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(str)), JS_GetStringLength(str)));
    } else if (JSVAL_IS_BOOLEAN(val)) {
        if (val == JSVAL_TRUE) {
            for (i = 0; i < aNumIndexes; i++)
                aStatement->BindInt32Parameter(aParamIndexes[i], 1);
        } else {
            for (i = 0; i < aNumIndexes; i++)
                aStatement->BindInt32Parameter(aParamIndexes[i], 0);
        }
    } else if (JSVAL_IS_NULL(val)) {
        for (i = 0; i < aNumIndexes; i++)
            aStatement->BindNullParameter(aParamIndexes[i]);
    } 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);

            for (i = 0; i < aNumIndexes; i++)
                aStatement->BindInt64Parameter(aParamIndexes[i], msec);
        } else {
            return PR_FALSE;
        }
    } else {
        return PR_FALSE;
    }

    return PR_TRUE;
}

Here is the call graph for this function: