mozStorageAsyncStatement.h (2897B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_storage_mozStorageAsyncStatement_h_ 8 #define mozilla_storage_mozStorageAsyncStatement_h_ 9 10 #include "nsString.h" 11 12 #include "nsTArray.h" 13 14 #include "mozStorageBindingParamsArray.h" 15 #include "mozStorageStatementData.h" 16 #include "mozIStorageAsyncStatement.h" 17 #include "StorageBaseStatementInternal.h" 18 19 namespace mozilla { 20 namespace storage { 21 22 class AsyncStatementJSHelper; 23 class AsyncStatementParamsHolder; 24 class Connection; 25 26 class AsyncStatement final : public mozIStorageAsyncStatement, 27 public StorageBaseStatementInternal { 28 public: 29 NS_DECL_THREADSAFE_ISUPPORTS 30 NS_DECL_MOZISTORAGEASYNCSTATEMENT 31 NS_DECL_MOZISTORAGEBASESTATEMENT 32 NS_DECL_MOZISTORAGEBINDINGPARAMS 33 NS_DECL_STORAGEBASESTATEMENTINTERNAL 34 35 AsyncStatement(); 36 37 /** 38 * Initializes the object on aDBConnection by preparing the SQL statement 39 * given by aSQLStatement. 40 * 41 * @param aDBConnection 42 * The Connection object this statement is associated with. 43 * @param aNativeConnection 44 * The native Sqlite connection this statement is associated with. 45 * @param aSQLStatement 46 * The SQL statement to prepare that this object will represent. 47 */ 48 nsresult initialize(Connection* aDBConnection, sqlite3* aNativeConnection, 49 const nsACString& aSQLStatement); 50 51 /** 52 * Obtains and transfers ownership of the array of parameters that are bound 53 * to this statment. This can be null. 54 */ 55 inline already_AddRefed<BindingParamsArray> bindingParamsArray() { 56 return mParamsArray.forget(); 57 } 58 59 private: 60 ~AsyncStatement(); 61 62 /** 63 * @return a pointer to the BindingParams object to use with our Bind* 64 * method. 65 */ 66 mozIStorageBindingParams* getParams(); 67 68 /** 69 * The SQL string as passed by the user. We store it because we create the 70 * async statement on-demand on the async thread. 71 */ 72 nsCString mSQLString; 73 74 /** 75 * Holds the array of parameters to bind to this statement when we execute 76 * it asynchronously. 77 */ 78 RefPtr<BindingParamsArray> mParamsArray; 79 80 /** 81 * Caches the JS 'params' helper for this statement. 82 */ 83 nsMainThreadPtrHandle<AsyncStatementParamsHolder> mStatementParamsHolder; 84 85 /** 86 * Have we been explicitly finalized by the user? 87 */ 88 bool mFinalized; 89 90 /** 91 * Required for access to private mStatementParamsHolder field by 92 * AsyncStatementJSHelper::getParams. 93 */ 94 friend class AsyncStatementJSHelper; 95 }; 96 97 } // namespace storage 98 } // namespace mozilla 99 100 #endif // mozilla_storage_mozStorageAsyncStatement_h_