Line data Source code
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 "nsAutoPtr.h"
11 : #include "nsString.h"
12 :
13 : #include "nsTArray.h"
14 :
15 : #include "mozStorageBindingParamsArray.h"
16 : #include "mozStorageStatementData.h"
17 : #include "mozIStorageAsyncStatement.h"
18 : #include "StorageBaseStatementInternal.h"
19 : #include "mozilla/Attributes.h"
20 :
21 : class nsIXPConnectJSObjectHolder;
22 :
23 : namespace mozilla {
24 : namespace storage {
25 :
26 : class AsyncStatementJSHelper;
27 : class Connection;
28 :
29 : class AsyncStatement final : public mozIStorageAsyncStatement
30 : , public StorageBaseStatementInternal
31 : {
32 : public:
33 : NS_DECL_THREADSAFE_ISUPPORTS
34 : NS_DECL_MOZISTORAGEASYNCSTATEMENT
35 : NS_DECL_MOZISTORAGEBASESTATEMENT
36 : NS_DECL_MOZISTORAGEBINDINGPARAMS
37 : NS_DECL_STORAGEBASESTATEMENTINTERNAL
38 :
39 : AsyncStatement();
40 :
41 : /**
42 : * Initializes the object on aDBConnection by preparing the SQL statement
43 : * given by aSQLStatement.
44 : *
45 : * @param aDBConnection
46 : * The Connection object this statement is associated with.
47 : * @param aNativeConnection
48 : * The native Sqlite connection this statement is associated with.
49 : * @param aSQLStatement
50 : * The SQL statement to prepare that this object will represent.
51 : */
52 : nsresult initialize(Connection *aDBConnection,
53 : sqlite3 *aNativeConnection,
54 : const nsACString &aSQLStatement);
55 :
56 : /**
57 : * Obtains and transfers ownership of the array of parameters that are bound
58 : * to this statment. This can be null.
59 : */
60 11 : inline already_AddRefed<BindingParamsArray> bindingParamsArray()
61 : {
62 11 : return mParamsArray.forget();
63 : }
64 :
65 :
66 : private:
67 : ~AsyncStatement();
68 :
69 : /**
70 : * @return a pointer to the BindingParams object to use with our Bind*
71 : * method.
72 : */
73 : mozIStorageBindingParams *getParams();
74 :
75 : /**
76 : * The SQL string as passed by the user. We store it because we create the
77 : * async statement on-demand on the async thread.
78 : */
79 : nsCString mSQLString;
80 :
81 : /**
82 : * Holds the array of parameters to bind to this statement when we execute
83 : * it asynchronously.
84 : */
85 : RefPtr<BindingParamsArray> mParamsArray;
86 :
87 : /**
88 : * Caches the JS 'params' helper for this statement.
89 : */
90 : nsMainThreadPtrHandle<nsIXPConnectJSObjectHolder> mStatementParamsHolder;
91 :
92 : /**
93 : * Have we been explicitly finalized by the user?
94 : */
95 : bool mFinalized;
96 :
97 : /**
98 : * Required for access to private mStatementParamsHolder field by
99 : * AsyncStatementJSHelper::getParams.
100 : */
101 : friend class AsyncStatementJSHelper;
102 : };
103 :
104 : } // namespace storage
105 : } // namespace mozilla
106 :
107 : #endif // mozilla_storage_mozStorageAsyncStatement_h_
|