1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/storage/src/mozStoragePrivateHelpers.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozStoragePrivateHelpers_h 1.11 +#define mozStoragePrivateHelpers_h 1.12 + 1.13 +/** 1.14 + * This file contains convenience methods for mozStorage. 1.15 + */ 1.16 + 1.17 +#include "sqlite3.h" 1.18 +#include "nsIVariant.h" 1.19 +#include "nsError.h" 1.20 +#include "nsAutoPtr.h" 1.21 +#include "js/TypeDecls.h" 1.22 + 1.23 +class mozIStorageCompletionCallback; 1.24 +class mozIStorageBaseStatement; 1.25 +class mozIStorageBindingParams; 1.26 +class nsIRunnable; 1.27 + 1.28 +namespace mozilla { 1.29 +namespace storage { 1.30 + 1.31 +//////////////////////////////////////////////////////////////////////////////// 1.32 +//// Macros 1.33 + 1.34 +#define ENSURE_INDEX_VALUE(aIndex, aCount) \ 1.35 + NS_ENSURE_TRUE(aIndex < aCount, NS_ERROR_INVALID_ARG) 1.36 + 1.37 +//////////////////////////////////////////////////////////////////////////////// 1.38 +//// Functions 1.39 + 1.40 +/** 1.41 + * Converts a SQLite return code to an nsresult return code. 1.42 + * 1.43 + * @param aSQLiteResultCode 1.44 + * The SQLite return code to convert. 1.45 + * @returns the corresponding nsresult code for aSQLiteResultCode. 1.46 + */ 1.47 +nsresult convertResultCode(int aSQLiteResultCode); 1.48 + 1.49 +/** 1.50 + * Checks the performance of a SQLite statement and logs a warning with 1.51 + * NS_WARNING. Currently this only checks the number of sort operations done 1.52 + * on a statement, and if more than zero have been done, the statement can be 1.53 + * made faster with the careful use of an index. 1.54 + * 1.55 + * @param aStatement 1.56 + * The sqlite3_stmt object to check. 1.57 + */ 1.58 +void checkAndLogStatementPerformance(sqlite3_stmt *aStatement); 1.59 + 1.60 +/** 1.61 + * Convert the provided JS::Value into a variant representation if possible. 1.62 + * 1.63 + * @param aCtx 1.64 + * The JSContext the value is from. 1.65 + * @param aValue 1.66 + * The JavaScript value to convert. All primitive types are supported, 1.67 + * but only Date objects are supported from the Date family. Date 1.68 + * objects are coerced to PRTime (nanoseconds since epoch) values. 1.69 + * @return the variant if conversion was successful, nullptr if conversion 1.70 + * failed. The caller is responsible for addref'ing if non-null. 1.71 + */ 1.72 +nsIVariant *convertJSValToVariant(JSContext *aCtx, JS::Value aValue); 1.73 + 1.74 +/** 1.75 + * Obtains an event that will notify a completion callback about completion. 1.76 + * 1.77 + * @param aCallback 1.78 + * The callback to be notified. 1.79 + * @return an nsIRunnable that can be dispatched to the calling thread. 1.80 + */ 1.81 +already_AddRefed<nsIRunnable> newCompletionEvent( 1.82 + mozIStorageCompletionCallback *aCallback 1.83 +); 1.84 + 1.85 +} // namespace storage 1.86 +} // namespace mozilla 1.87 + 1.88 +#endif // mozStoragePrivateHelpers_h