2009-05-08 17:29:56 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-06-12 15:01:05 -07:00
|
|
|
|
2010-06-01 05:38:00 -07:00
|
|
|
#ifndef mozStoragePrivateHelpers_h
|
|
|
|
#define mozStoragePrivateHelpers_h
|
2008-10-30 15:50:00 -07:00
|
|
|
|
2007-06-12 15:01:05 -07:00
|
|
|
/**
|
|
|
|
* This file contains convenience methods for mozStorage.
|
|
|
|
*/
|
|
|
|
|
2009-05-08 17:29:57 -07:00
|
|
|
#include "sqlite3.h"
|
|
|
|
#include "nsIVariant.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2009-11-09 09:58:34 -08:00
|
|
|
#include "nsAutoPtr.h"
|
2009-07-22 15:31:03 -07:00
|
|
|
|
2009-11-09 09:58:34 -08:00
|
|
|
class mozIStorageCompletionCallback;
|
2010-03-24 00:32:40 -07:00
|
|
|
class mozIStorageBaseStatement;
|
|
|
|
class mozIStorageBindingParams;
|
2009-11-09 09:58:34 -08:00
|
|
|
class nsIRunnable;
|
2009-05-08 17:29:56 -07:00
|
|
|
|
2013-08-17 15:50:18 -07:00
|
|
|
namespace JS {
|
|
|
|
class Value;
|
|
|
|
}
|
|
|
|
|
2009-05-08 17:29:56 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace storage {
|
|
|
|
|
2009-05-08 17:29:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Macros
|
|
|
|
|
|
|
|
#define ENSURE_INDEX_VALUE(aIndex, aCount) \
|
|
|
|
NS_ENSURE_TRUE(aIndex < aCount, NS_ERROR_INVALID_ARG)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Functions
|
|
|
|
|
2007-06-12 15:01:05 -07:00
|
|
|
/**
|
|
|
|
* Converts a SQLite return code to an nsresult return code.
|
|
|
|
*
|
2009-03-12 11:30:15 -07:00
|
|
|
* @param aSQLiteResultCode
|
|
|
|
* The SQLite return code to convert.
|
|
|
|
* @returns the corresponding nsresult code for aSQLiteResultCode.
|
2007-06-12 15:01:05 -07:00
|
|
|
*/
|
2009-05-08 17:29:56 -07:00
|
|
|
nsresult convertResultCode(int aSQLiteResultCode);
|
2007-06-12 15:01:05 -07:00
|
|
|
|
2009-03-12 11:30:15 -07:00
|
|
|
/**
|
|
|
|
* Checks the performance of a SQLite statement and logs a warning with
|
|
|
|
* NS_WARNING. Currently this only checks the number of sort operations done
|
|
|
|
* on a statement, and if more than zero have been done, the statement can be
|
|
|
|
* made faster with the careful use of an index.
|
|
|
|
*
|
|
|
|
* @param aStatement
|
|
|
|
* The sqlite3_stmt object to check.
|
|
|
|
*/
|
2009-05-08 17:29:56 -07:00
|
|
|
void checkAndLogStatementPerformance(sqlite3_stmt *aStatement);
|
2007-06-12 15:01:05 -07:00
|
|
|
|
2009-07-22 15:31:03 -07:00
|
|
|
/**
|
2013-08-17 15:50:18 -07:00
|
|
|
* Convert the provided JS::Value into a variant representation if possible.
|
2009-07-22 15:31:03 -07:00
|
|
|
*
|
2009-11-09 09:58:34 -08:00
|
|
|
* @param aCtx
|
2010-03-24 00:32:40 -07:00
|
|
|
* The JSContext the value is from.
|
2009-11-09 09:58:34 -08:00
|
|
|
* @param aValue
|
2010-03-24 00:32:40 -07:00
|
|
|
* The JavaScript value to convert. All primitive types are supported,
|
|
|
|
* but only Date objects are supported from the Date family. Date
|
|
|
|
* objects are coerced to PRTime (nanoseconds since epoch) values.
|
2012-07-30 07:20:58 -07:00
|
|
|
* @return the variant if conversion was successful, nullptr if conversion
|
2010-03-24 00:32:40 -07:00
|
|
|
* failed. The caller is responsible for addref'ing if non-null.
|
2009-11-09 09:58:34 -08:00
|
|
|
*/
|
2013-08-17 15:50:18 -07:00
|
|
|
nsIVariant *convertJSValToVariant(JSContext *aCtx, JS::Value aValue);
|
2009-11-09 09:58:34 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains an event that will notify a completion callback about completion.
|
|
|
|
*
|
|
|
|
* @param aCallback
|
|
|
|
* The callback to be notified.
|
|
|
|
* @return an nsIRunnable that can be dispatched to the calling thread.
|
2009-07-22 15:31:03 -07:00
|
|
|
*/
|
2010-03-24 00:32:40 -07:00
|
|
|
already_AddRefed<nsIRunnable> newCompletionEvent(
|
|
|
|
mozIStorageCompletionCallback *aCallback
|
|
|
|
);
|
2009-07-22 15:31:03 -07:00
|
|
|
|
2009-05-08 17:29:56 -07:00
|
|
|
} // namespace storage
|
|
|
|
} // namespace mozilla
|
2007-06-12 15:01:05 -07:00
|
|
|
|
2010-06-01 05:38:00 -07:00
|
|
|
#endif // mozStoragePrivateHelpers_h
|