2007-06-12 22:01:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: sw=4 ts=4 sts=4
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
2004-10-09 00:04:10 +00:00
|
|
|
* 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>
|
2007-06-12 22:01:05 +00:00
|
|
|
* Shawn Wilsher <me@shawnwilsher.com>
|
2007-11-13 08:26:45 +00:00
|
|
|
* John Zhang <jzhang@aptana.com>
|
2004-10-09 00:04:10 +00:00
|
|
|
*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
2004-12-03 16:56:57 +00:00
|
|
|
#include "nsMemory.h"
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2004-10-09 14:33:01 +00:00
|
|
|
#include "mozStorageConnection.h"
|
2004-10-09 00:04:10 +00:00
|
|
|
#include "mozStorageStatement.h"
|
|
|
|
#include "mozStorageValueArray.h"
|
2007-06-12 22:01:05 +00:00
|
|
|
#include "mozStorage.h"
|
2004-10-09 00:04:10 +00:00
|
|
|
|
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
extern PRLogModuleInfo* gStorageLog;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
** mozStorageStatementRowEnumerator
|
|
|
|
**/
|
|
|
|
class mozStorageStatementRowEnumerator : public nsISimpleEnumerator {
|
|
|
|
public:
|
|
|
|
// this expects a statement that has NOT had step called on it yet
|
|
|
|
mozStorageStatementRowEnumerator (sqlite3_stmt *aDBStatement);
|
|
|
|
|
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsISimpleEnumerator interface
|
|
|
|
NS_DECL_NSISIMPLEENUMERATOR
|
|
|
|
|
|
|
|
private:
|
|
|
|
~mozStorageStatementRowEnumerator ();
|
|
|
|
protected:
|
|
|
|
sqlite3_stmt *mDBStatement;
|
|
|
|
PRBool mHasMore;
|
|
|
|
PRBool mDidStep;
|
|
|
|
|
|
|
|
void DoRealStep();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
** mozStorageStatement
|
|
|
|
**/
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(mozStorageStatement, mozIStorageStatement, mozIStorageValueArray)
|
|
|
|
|
|
|
|
mozStorageStatement::mozStorageStatement()
|
2004-12-03 16:56:57 +00:00
|
|
|
: mDBConnection (nsnull), mDBStatement(nsnull), mColumnNames(nsnull), mExecuting(PR_FALSE)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::Initialize(mozIStorageConnection *aDBConnection, const nsACString & aSQLStatement)
|
|
|
|
{
|
|
|
|
int srv;
|
|
|
|
|
2005-04-17 21:00:50 +00:00
|
|
|
// we can't do this if we're mid-execute
|
|
|
|
if (mExecuting) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2004-10-09 00:04:10 +00:00
|
|
|
sqlite3 *db = nsnull;
|
2004-10-09 14:33:01 +00:00
|
|
|
// XXX - need to implement a private iid to QI for here, to make sure
|
|
|
|
// we have a real mozStorageConnection
|
2007-07-08 07:08:04 +00:00
|
|
|
mozStorageConnection *msc = static_cast<mozStorageConnection*>(aDBConnection);
|
2004-10-09 14:33:01 +00:00
|
|
|
db = msc->GetNativeConnection();
|
|
|
|
NS_ENSURE_TRUE(db != nsnull, NS_ERROR_NULL_POINTER);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2005-04-17 21:00:50 +00:00
|
|
|
// clean up old goop
|
|
|
|
if (mDBStatement) {
|
|
|
|
sqlite3_finalize(mDBStatement);
|
|
|
|
mDBStatement = nsnull;
|
|
|
|
}
|
|
|
|
|
2005-03-24 19:59:59 +00:00
|
|
|
int nRetries = 0;
|
|
|
|
|
|
|
|
while (nRetries < 2) {
|
2007-07-11 22:20:39 +00:00
|
|
|
srv = sqlite3_prepare_v2(db, nsPromiseFlatCString(aSQLStatement).get(),
|
|
|
|
aSQLStatement.Length(), &mDBStatement, NULL);
|
2005-03-24 22:58:30 +00:00
|
|
|
if ((srv == SQLITE_SCHEMA && nRetries != 0) ||
|
|
|
|
(srv != SQLITE_SCHEMA && srv != SQLITE_OK))
|
|
|
|
{
|
2005-03-24 19:59:59 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
PR_LOG(gStorageLog, PR_LOG_ERROR, ("Sqlite statement prepare error: %d '%s'", srv, sqlite3_errmsg(db)));
|
|
|
|
PR_LOG(gStorageLog, PR_LOG_ERROR, ("Statement was: '%s'", nsPromiseFlatCString(aSQLStatement).get()));
|
|
|
|
#endif
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2005-03-24 22:58:30 +00:00
|
|
|
if (srv == SQLITE_OK)
|
|
|
|
break;
|
|
|
|
|
2005-03-24 19:59:59 +00:00
|
|
|
nRetries++;
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mDBConnection = aDBConnection;
|
2008-06-04 16:55:44 +00:00
|
|
|
mStatementString.Assign (aSQLStatement);
|
2004-10-09 00:04:10 +00:00
|
|
|
mParamCount = sqlite3_bind_parameter_count (mDBStatement);
|
|
|
|
mResultColumnCount = sqlite3_column_count (mDBStatement);
|
2005-04-17 21:00:50 +00:00
|
|
|
mColumnNames.Clear();
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-07-19 16:30:17 +00:00
|
|
|
for (PRUint32 i = 0; i < mResultColumnCount; i++) {
|
|
|
|
const char *name = sqlite3_column_name(mDBStatement, i);
|
|
|
|
mColumnNames.AppendCString(nsDependentCString(name));
|
2004-12-03 16:56:57 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 01:56:14 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// We want to try and test for LIKE and that consumers are using
|
|
|
|
// escapeStringForLIKE instead of just trusting user input. The idea to
|
|
|
|
// check to see if they are binding a parameter after like instead of just
|
|
|
|
// using a string. We only do this in debug builds because it's expensive!
|
|
|
|
const nsCaseInsensitiveCStringComparator c;
|
|
|
|
nsACString::const_iterator start, end, e;
|
|
|
|
aSQLStatement.BeginReading(start);
|
|
|
|
aSQLStatement.EndReading(end);
|
|
|
|
e = end;
|
|
|
|
while (FindInReadable(NS_LITERAL_CSTRING(" LIKE"), start, e, c)) {
|
|
|
|
// We have a LIKE in here, so we perform our tests
|
|
|
|
// FindInReadable moves the iterator, so we have to get a new one for
|
|
|
|
// each test we perform.
|
|
|
|
nsACString::const_iterator s1, s2, s3;
|
|
|
|
s1 = s2 = s3 = start;
|
|
|
|
|
|
|
|
if (!(FindInReadable(NS_LITERAL_CSTRING(" LIKE ?"), s1, end, c) ||
|
|
|
|
FindInReadable(NS_LITERAL_CSTRING(" LIKE :"), s2, end, c) ||
|
|
|
|
FindInReadable(NS_LITERAL_CSTRING(" LIKE @"), s3, end, c))) {
|
|
|
|
// At this point, we didn't find a LIKE statement followed by ?, :,
|
|
|
|
// or @, all of which are valid characters for binding a parameter.
|
|
|
|
// We will warn the consumer that they may not be safely using LIKE.
|
|
|
|
NS_WARNING("Unsafe use of LIKE detected! Please ensure that you "
|
|
|
|
"are using mozIStorageConnection::escapeStringForLIKE "
|
|
|
|
"and that you are binding that result to the statement "
|
|
|
|
"to prevent SQL injection attacks.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// resetting start and e
|
|
|
|
start = e;
|
|
|
|
e = end;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-10-09 00:04:10 +00:00
|
|
|
// doing a sqlite3_prepare sets up the execution engine
|
|
|
|
// for that statement; doing a create_function after that
|
|
|
|
// results in badness, because there's a selected statement.
|
|
|
|
// use this hack to clear it out -- this may be a bug.
|
|
|
|
sqlite3_exec (db, "", 0, 0, 0);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozStorageStatement::~mozStorageStatement()
|
|
|
|
{
|
2007-09-19 03:26:51 +00:00
|
|
|
(void)Finalize();
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mozIStorageStatement clone (); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::Clone(mozIStorageStatement **_retval)
|
|
|
|
{
|
|
|
|
mozStorageStatement *mss = new mozStorageStatement();
|
2007-06-12 22:01:05 +00:00
|
|
|
if (!mss)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2008-06-04 16:55:44 +00:00
|
|
|
nsresult rv = mss->Initialize (mDBConnection, mStatementString);
|
2007-06-12 22:01:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
NS_ADDREF(*_retval = mss);
|
2004-10-09 00:04:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-09-19 03:26:51 +00:00
|
|
|
/* void finalize(); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::Finalize()
|
|
|
|
{
|
|
|
|
if (mDBStatement) {
|
|
|
|
int srv = sqlite3_finalize(mDBStatement);
|
|
|
|
mDBStatement = NULL;
|
|
|
|
return ConvertResultCode(srv);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-10-09 00:04:10 +00:00
|
|
|
/* readonly attribute unsigned long parameterCount; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetParameterCount(PRUint32 *aParameterCount)
|
|
|
|
{
|
2004-12-03 16:56:57 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aParameterCount);
|
|
|
|
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2004-12-03 16:56:57 +00:00
|
|
|
*aParameterCount = mParamCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AUTF8String getParameterName(in unsigned long aParamIndex); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetParameterName(PRUint32 aParamIndex, nsACString & _retval)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
// We have to check this index because sqlite3_bind_parameter_name returns
|
|
|
|
// NULL if an error occurs, or if a column is unnamed. Since we handle
|
|
|
|
// unnamed columns, we won't be able to tell if it is an error not without
|
|
|
|
// checking ourselves.
|
2004-12-03 16:56:57 +00:00
|
|
|
if (aParamIndex < 0 || aParamIndex >= mParamCount)
|
2007-06-12 22:01:05 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2004-12-03 16:56:57 +00:00
|
|
|
|
|
|
|
const char *pname = sqlite3_bind_parameter_name(mDBStatement, aParamIndex + 1);
|
|
|
|
if (pname == NULL) {
|
|
|
|
// this thing had no name, so fake one
|
|
|
|
nsCAutoString pname(":");
|
|
|
|
pname.AppendInt(aParamIndex);
|
|
|
|
_retval.Assign(pname);
|
|
|
|
} else {
|
|
|
|
_retval.Assign(nsDependentCString(pname));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-15 18:03:20 +00:00
|
|
|
/* unsigned long getParameterIndex(in AUTF8String aParameterName); */
|
2005-04-17 21:00:50 +00:00
|
|
|
NS_IMETHODIMP
|
2007-07-15 18:03:20 +00:00
|
|
|
mozStorageStatement::GetParameterIndex(const nsACString &aName,
|
|
|
|
PRUint32 *_retval)
|
2005-04-17 21:00:50 +00:00
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2005-04-17 21:00:50 +00:00
|
|
|
|
2007-07-15 18:03:20 +00:00
|
|
|
int ind = sqlite3_bind_parameter_index(mDBStatement,
|
|
|
|
nsPromiseFlatCString(aName).get());
|
|
|
|
if (ind == 0) // Named parameter not found
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-06-18 23:42:23 +00:00
|
|
|
|
2007-07-15 18:03:20 +00:00
|
|
|
*_retval = ind - 1; // SQLite indexes are 1-based, we are 0-based
|
2007-06-18 23:42:23 +00:00
|
|
|
|
2005-04-17 21:00:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-03 16:56:57 +00:00
|
|
|
/* readonly attribute unsigned long columnCount; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetColumnCount(PRUint32 *aColumnCount)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aColumnCount);
|
|
|
|
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2004-12-03 16:56:57 +00:00
|
|
|
*aColumnCount = mResultColumnCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AUTF8String getColumnName(in unsigned long aColumnIndex); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetColumnName(PRUint32 aColumnIndex, nsACString & _retval)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
// We have to check this index because sqlite3_column_name returns
|
|
|
|
// NULL if an error occurs, or if a column is unnamed.
|
2004-12-03 16:56:57 +00:00
|
|
|
if (aColumnIndex < 0 || aColumnIndex >= mResultColumnCount)
|
2007-06-12 22:01:05 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2004-12-03 16:56:57 +00:00
|
|
|
|
|
|
|
const char *cname = sqlite3_column_name(mDBStatement, aColumnIndex);
|
|
|
|
_retval.Assign(nsDependentCString(cname));
|
|
|
|
|
|
|
|
return NS_OK;
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 16:30:17 +00:00
|
|
|
/* unsigned long getColumnIndex(in AUTF8String aName); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetColumnIndex(const nsACString &aName, PRUint32 *_retval)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2007-07-19 16:30:17 +00:00
|
|
|
|
|
|
|
// Surprisingly enough, SQLite doesn't provide an API for this. We have to
|
|
|
|
// determine it ourselves sadly.
|
|
|
|
for (PRUint32 i = 0; i < mResultColumnCount; i++) {
|
|
|
|
if (mColumnNames[i]->Equals(aName)) {
|
|
|
|
*_retval = i;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2004-10-09 00:04:10 +00:00
|
|
|
/* void reset (); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::Reset()
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2008-06-04 16:55:44 +00:00
|
|
|
PR_LOG(gStorageLog, PR_LOG_DEBUG, ("Resetting statement: '%s'", nsPromiseFlatCString(mStatementString).get()));
|
2005-04-26 22:28:06 +00:00
|
|
|
|
2004-10-09 00:04:10 +00:00
|
|
|
sqlite3_reset(mDBStatement);
|
2005-06-10 01:31:48 +00:00
|
|
|
sqlite3_clear_bindings(mDBStatement);
|
|
|
|
|
2004-12-03 16:56:57 +00:00
|
|
|
mExecuting = PR_FALSE;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void bindUTF8StringParameter (in unsigned long aParamIndex, in AUTF8String aValue); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::BindUTF8StringParameter(PRUint32 aParamIndex, const nsACString & aValue)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
int srv = sqlite3_bind_text (mDBStatement, aParamIndex + 1,
|
|
|
|
nsPromiseFlatCString(aValue).get(),
|
|
|
|
aValue.Length(), SQLITE_TRANSIENT);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
return ConvertResultCode(srv);
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void bindStringParameter (in unsigned long aParamIndex, in AString aValue); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::BindStringParameter(PRUint32 aParamIndex, const nsAString & aValue)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
int srv = sqlite3_bind_text16 (mDBStatement, aParamIndex + 1,
|
|
|
|
nsPromiseFlatString(aValue).get(),
|
|
|
|
aValue.Length() * 2, SQLITE_TRANSIENT);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
return ConvertResultCode(srv);
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void bindDoubleParameter (in unsigned long aParamIndex, in double aValue); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::BindDoubleParameter(PRUint32 aParamIndex, double aValue)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
int srv = sqlite3_bind_double (mDBStatement, aParamIndex + 1, aValue);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
return ConvertResultCode(srv);
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void bindInt32Parameter (in unsigned long aParamIndex, in long aValue); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::BindInt32Parameter(PRUint32 aParamIndex, PRInt32 aValue)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
int srv = sqlite3_bind_int (mDBStatement, aParamIndex + 1, aValue);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
return ConvertResultCode(srv);
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void bindInt64Parameter (in unsigned long aParamIndex, in long long aValue); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::BindInt64Parameter(PRUint32 aParamIndex, PRInt64 aValue)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
int srv = sqlite3_bind_int64 (mDBStatement, aParamIndex + 1, aValue);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
return ConvertResultCode(srv);
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void bindNullParameter (in unsigned long aParamIndex); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::BindNullParameter(PRUint32 aParamIndex)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
int srv = sqlite3_bind_null (mDBStatement, aParamIndex + 1);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
return ConvertResultCode(srv);
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* void bindBlobParameter (in unsigned long aParamIndex, [array, const, size_is (aValueSize)] in octet aValue, in unsigned long aValueSize); */
|
2004-10-09 00:04:10 +00:00
|
|
|
NS_IMETHODIMP
|
2005-11-15 00:35:50 +00:00
|
|
|
mozStorageStatement::BindBlobParameter(PRUint32 aParamIndex, const PRUint8 *aValue, PRUint32 aValueSize)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
int srv = sqlite3_bind_blob (mDBStatement, aParamIndex + 1, aValue,
|
|
|
|
aValueSize, SQLITE_TRANSIENT);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
return ConvertResultCode(srv);
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void execute (); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::Execute()
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
PRBool ret;
|
2005-05-27 20:14:09 +00:00
|
|
|
nsresult rv = ExecuteStep(&ret);
|
2007-06-12 22:01:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-05-27 20:14:09 +00:00
|
|
|
return Reset();
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean executeStep (); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::ExecuteStep(PRBool *_retval)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2005-04-17 21:00:50 +00:00
|
|
|
nsresult rv;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-07-11 22:20:39 +00:00
|
|
|
int srv = sqlite3_step (mDBStatement);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-07-10 16:58:17 +00:00
|
|
|
#ifdef PR_LOGGING
|
2007-07-11 22:20:39 +00:00
|
|
|
if (srv != SQLITE_ROW && srv != SQLITE_DONE)
|
|
|
|
{
|
|
|
|
nsCAutoString errStr;
|
|
|
|
mDBConnection->GetLastErrorString(errStr);
|
|
|
|
PR_LOG(gStorageLog, PR_LOG_DEBUG, ("mozStorageStatement::ExecuteStep error: %s", errStr.get()));
|
|
|
|
}
|
2007-07-10 16:58:17 +00:00
|
|
|
#endif
|
2007-07-10 17:23:36 +00:00
|
|
|
|
2007-07-11 22:20:39 +00:00
|
|
|
// SQLITE_ROW and SQLITE_DONE are non-errors
|
|
|
|
if (srv == SQLITE_ROW) {
|
|
|
|
// we got a row back
|
|
|
|
mExecuting = PR_TRUE;
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
} else if (srv == SQLITE_DONE) {
|
|
|
|
// statement is done (no row returned)
|
|
|
|
mExecuting = PR_FALSE;
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
} else if (srv == SQLITE_BUSY || srv == SQLITE_MISUSE) {
|
|
|
|
mExecuting = PR_FALSE;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
} else if (mExecuting == PR_TRUE) {
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
PR_LOG(gStorageLog, PR_LOG_ERROR, ("SQLite error after mExecuting was true!"));
|
|
|
|
#endif
|
|
|
|
mExecuting = PR_FALSE;
|
2005-04-17 21:00:50 +00:00
|
|
|
}
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2007-07-11 22:20:39 +00:00
|
|
|
return ConvertResultCode(srv);
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
2004-12-03 16:56:57 +00:00
|
|
|
/* [noscript,notxpcom] sqlite3stmtptr getNativeStatementPointer(); */
|
|
|
|
sqlite3_stmt*
|
|
|
|
mozStorageStatement::GetNativeStatementPointer()
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
2004-12-03 16:56:57 +00:00
|
|
|
return mDBStatement;
|
|
|
|
}
|
2004-10-09 00:04:10 +00:00
|
|
|
|
2004-12-03 16:56:57 +00:00
|
|
|
/* readonly attribute long state; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetState(PRInt32 *_retval)
|
|
|
|
{
|
|
|
|
if (!mDBConnection || !mDBStatement) {
|
|
|
|
*_retval = MOZ_STORAGE_STATEMENT_INVALID;
|
|
|
|
} else if (mExecuting) {
|
|
|
|
*_retval = MOZ_STORAGE_STATEMENT_EXECUTING;
|
|
|
|
} else {
|
|
|
|
*_retval = MOZ_STORAGE_STATEMENT_READY;
|
|
|
|
}
|
2004-10-09 00:04:10 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
*** mozIStorageValueArray
|
|
|
|
***/
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* readonly attribute unsigned long numEntries; */
|
2004-10-09 00:04:10 +00:00
|
|
|
NS_IMETHODIMP
|
2005-11-15 00:35:50 +00:00
|
|
|
mozStorageStatement::GetNumEntries(PRUint32 *aLength)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
|
|
|
*aLength = mResultColumnCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* long getTypeOfIndex (in unsigned long aIndex); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetTypeOfIndex(PRUint32 aIndex, PRInt32 *_retval)
|
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
if (aIndex < 0 || aIndex >= mResultColumnCount)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
if (!mExecuting)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
|
|
|
int t = sqlite3_column_type (mDBStatement, aIndex);
|
|
|
|
switch (t) {
|
|
|
|
case SQLITE_INTEGER:
|
|
|
|
*_retval = VALUE_TYPE_INTEGER;
|
|
|
|
break;
|
|
|
|
case SQLITE_FLOAT:
|
|
|
|
*_retval = VALUE_TYPE_FLOAT;
|
|
|
|
break;
|
|
|
|
case SQLITE_TEXT:
|
|
|
|
*_retval = VALUE_TYPE_TEXT;
|
|
|
|
break;
|
|
|
|
case SQLITE_BLOB:
|
|
|
|
*_retval = VALUE_TYPE_BLOB;
|
|
|
|
break;
|
|
|
|
case SQLITE_NULL:
|
|
|
|
*_retval = VALUE_TYPE_NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// ???
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* long getInt32 (in unsigned long aIndex); */
|
2004-10-09 00:04:10 +00:00
|
|
|
NS_IMETHODIMP
|
2005-11-15 00:35:50 +00:00
|
|
|
mozStorageStatement::GetInt32(PRUint32 aIndex, PRInt32 *_retval)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
if (aIndex < 0 || aIndex >= mResultColumnCount)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2004-12-03 16:56:57 +00:00
|
|
|
if (!mExecuting)
|
2007-06-12 22:01:05 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
|
|
|
*_retval = sqlite3_column_int (mDBStatement, aIndex);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* long long getInt64 (in unsigned long aIndex); */
|
2004-10-09 00:04:10 +00:00
|
|
|
NS_IMETHODIMP
|
2005-11-15 00:35:50 +00:00
|
|
|
mozStorageStatement::GetInt64(PRUint32 aIndex, PRInt64 *_retval)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
if (aIndex < 0 || aIndex >= mResultColumnCount)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2004-12-03 16:56:57 +00:00
|
|
|
if (!mExecuting)
|
2007-06-12 22:01:05 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
|
|
|
*_retval = sqlite3_column_int64 (mDBStatement, aIndex);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* double getDouble (in unsigned long aIndex); */
|
2004-10-09 00:04:10 +00:00
|
|
|
NS_IMETHODIMP
|
2005-11-15 00:35:50 +00:00
|
|
|
mozStorageStatement::GetDouble(PRUint32 aIndex, double *_retval)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
if (aIndex < 0 || aIndex >= mResultColumnCount)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2004-12-03 16:56:57 +00:00
|
|
|
if (!mExecuting)
|
2007-06-12 22:01:05 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
|
|
|
*_retval = sqlite3_column_double (mDBStatement, aIndex);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* AUTF8String getUTF8String (in unsigned long aIndex); */
|
2004-10-09 00:04:10 +00:00
|
|
|
NS_IMETHODIMP
|
2005-11-15 00:35:50 +00:00
|
|
|
mozStorageStatement::GetUTF8String(PRUint32 aIndex, nsACString & _retval)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
// Get type of Index will check aIndex for us, so we don't have to.
|
2006-02-07 23:10:16 +00:00
|
|
|
PRInt32 t;
|
|
|
|
nsresult rv = GetTypeOfIndex (aIndex, &t);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (t == VALUE_TYPE_NULL) {
|
|
|
|
// null columns get IsVoid set to distinguish them from empty strings
|
|
|
|
_retval.Truncate(0);
|
|
|
|
_retval.SetIsVoid(PR_TRUE);
|
|
|
|
} else {
|
|
|
|
int slen = sqlite3_column_bytes (mDBStatement, aIndex);
|
|
|
|
const unsigned char *cstr = sqlite3_column_text (mDBStatement, aIndex);
|
|
|
|
_retval.Assign ((char *) cstr, slen);
|
|
|
|
}
|
2004-10-09 00:04:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* AString getString (in unsigned long aIndex); */
|
2004-10-09 00:04:10 +00:00
|
|
|
NS_IMETHODIMP
|
2005-11-15 00:35:50 +00:00
|
|
|
mozStorageStatement::GetString(PRUint32 aIndex, nsAString & _retval)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
// Get type of Index will check aIndex for us, so we don't have to.
|
2006-02-07 23:10:16 +00:00
|
|
|
PRInt32 t;
|
|
|
|
nsresult rv = GetTypeOfIndex (aIndex, &t);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (t == VALUE_TYPE_NULL) {
|
|
|
|
// null columns get IsVoid set to distinguish them from empty strings
|
|
|
|
_retval.Truncate(0);
|
|
|
|
_retval.SetIsVoid(PR_TRUE);
|
|
|
|
} else {
|
|
|
|
int slen = sqlite3_column_bytes16 (mDBStatement, aIndex);
|
|
|
|
const void *text = sqlite3_column_text16 (mDBStatement, aIndex);
|
2007-07-08 07:08:04 +00:00
|
|
|
const PRUnichar *wstr = static_cast<const PRUnichar *>(text);
|
2006-02-07 23:10:16 +00:00
|
|
|
_retval.Assign (wstr, slen/2);
|
|
|
|
}
|
2004-10-09 00:04:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* void getBlob (in unsigned long aIndex, out unsigned long aDataSize, [array, size_is (aDataSize)] out octet aData); */
|
2004-10-09 00:04:10 +00:00
|
|
|
NS_IMETHODIMP
|
2005-11-15 00:35:50 +00:00
|
|
|
mozStorageStatement::GetBlob(PRUint32 aIndex, PRUint32 *aDataSize, PRUint8 **aData)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
2007-09-21 18:13:47 +00:00
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-06-12 22:01:05 +00:00
|
|
|
if (aIndex < 0 || aIndex >= mResultColumnCount)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2004-12-03 16:56:57 +00:00
|
|
|
if (!mExecuting)
|
2007-06-12 22:01:05 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2004-10-09 00:04:10 +00:00
|
|
|
|
|
|
|
int blobsize = sqlite3_column_bytes (mDBStatement, aIndex);
|
2005-12-07 20:52:33 +00:00
|
|
|
if (blobsize == 0) {
|
|
|
|
// empty column
|
|
|
|
*aData = nsnull;
|
|
|
|
*aDataSize = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-10-09 00:04:10 +00:00
|
|
|
const void *blob = sqlite3_column_blob (mDBStatement, aIndex);
|
|
|
|
|
|
|
|
void *blobcopy = nsMemory::Clone(blob, blobsize);
|
|
|
|
if (blobcopy == NULL)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aData = (PRUint8*) blobcopy;
|
|
|
|
*aDataSize = blobsize;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* [noscript] void getSharedUTF8String(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out string aResult); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetSharedUTF8String(PRUint32 aIndex, PRUint32 *aLength, const char **_retval)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
|
|
|
if (aLength) {
|
|
|
|
int slen = sqlite3_column_bytes (mDBStatement, aIndex);
|
|
|
|
*aLength = slen;
|
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
*_retval = (const char *) sqlite3_column_text (mDBStatement, aIndex);
|
|
|
|
return NS_OK;
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* [noscript] void getSharedString(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out wstring aResult); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetSharedString(PRUint32 aIndex, PRUint32 *aLength, const PRUnichar **_retval)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
|
|
|
if (aLength) {
|
|
|
|
int slen = sqlite3_column_bytes16 (mDBStatement, aIndex);
|
|
|
|
*aLength = slen;
|
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
*_retval = (const PRUnichar *) sqlite3_column_text16 (mDBStatement, aIndex);
|
|
|
|
return NS_OK;
|
2004-10-09 00:04:10 +00:00
|
|
|
}
|
|
|
|
|
2005-11-15 00:35:50 +00:00
|
|
|
/* [noscript] void getSharedBlob(in unsigned long aIndex, out unsigned long aLength, [shared,retval] out octetPtr aResult); */
|
2004-10-09 00:04:10 +00:00
|
|
|
NS_IMETHODIMP
|
2005-11-15 00:35:50 +00:00
|
|
|
mozStorageStatement::GetSharedBlob(PRUint32 aIndex, PRUint32 *aDataSize, const PRUint8 **aData)
|
2004-10-09 00:04:10 +00:00
|
|
|
{
|
|
|
|
*aDataSize = sqlite3_column_bytes (mDBStatement, aIndex);
|
2005-11-15 00:35:50 +00:00
|
|
|
*aData = (const PRUint8*) sqlite3_column_blob (mDBStatement, aIndex);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean getIsNull (in unsigned long aIndex); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetIsNull(PRUint32 aIndex, PRBool *_retval)
|
|
|
|
{
|
2007-06-12 22:01:05 +00:00
|
|
|
// Get type of Index will check aIndex for us, so we don't have to.
|
2004-10-09 00:04:10 +00:00
|
|
|
PRInt32 t;
|
|
|
|
nsresult rv = GetTypeOfIndex (aIndex, &t);
|
2007-06-12 22:01:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-10-09 00:04:10 +00:00
|
|
|
|
|
|
|
if (t == VALUE_TYPE_NULL)
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
else
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-08-10 22:57:02 +00:00
|
|
|
|
|
|
|
/* AString escapeStringForLIKE(in AString aValue, in char aEscapeChar); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::EscapeStringForLIKE(const nsAString & aValue,
|
|
|
|
const PRUnichar aEscapeChar,
|
|
|
|
nsAString &aEscapedString)
|
|
|
|
{
|
|
|
|
const PRUnichar MATCH_ALL('%');
|
|
|
|
const PRUnichar MATCH_ONE('_');
|
|
|
|
|
|
|
|
aEscapedString.Truncate(0);
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < aValue.Length(); i++) {
|
|
|
|
if (aValue[i] == aEscapeChar || aValue[i] == MATCH_ALL ||
|
|
|
|
aValue[i] == MATCH_ONE)
|
|
|
|
aEscapedString += aEscapeChar;
|
|
|
|
aEscapedString += aValue[i];
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-11-13 08:26:45 +00:00
|
|
|
|
|
|
|
/* AString getColumnDecltype(in unsigned long aParamIndex); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageStatement::GetColumnDecltype(PRUint32 aParamIndex,
|
|
|
|
nsACString& aDeclType)
|
|
|
|
{
|
|
|
|
if (!mDBConnection || !mDBStatement)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
if (aParamIndex < 0 || aParamIndex >= mResultColumnCount)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
const char *declType = sqlite3_column_decltype(mDBStatement, aParamIndex);
|
|
|
|
aDeclType.Assign(declType);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|