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