storage/src/mozStorageAsyncStatement.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:b7c1c51e0df0
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 struct sqlite3_stmt;
23
24 namespace mozilla {
25 namespace storage {
26
27 class AsyncStatementJSHelper;
28 class Connection;
29
30 class AsyncStatement MOZ_FINAL : public mozIStorageAsyncStatement
31 , public StorageBaseStatementInternal
32 {
33 public:
34 NS_DECL_THREADSAFE_ISUPPORTS
35 NS_DECL_MOZISTORAGEASYNCSTATEMENT
36 NS_DECL_MOZISTORAGEBASESTATEMENT
37 NS_DECL_MOZISTORAGEBINDINGPARAMS
38 NS_DECL_STORAGEBASESTATEMENTINTERNAL
39
40 AsyncStatement();
41
42 /**
43 * Initializes the object on aDBConnection by preparing the SQL statement
44 * given by aSQLStatement.
45 *
46 * @param aDBConnection
47 * The Connection object this statement is associated with.
48 * @param aNativeConnection
49 * The native Sqlite connection this statement is associated with.
50 * @param aSQLStatement
51 * The SQL statement to prepare that this object will represent.
52 */
53 nsresult initialize(Connection *aDBConnection,
54 sqlite3 *aNativeConnection,
55 const nsACString &aSQLStatement);
56
57 /**
58 * Obtains and transfers ownership of the array of parameters that are bound
59 * to this statment. This can be null.
60 */
61 inline already_AddRefed<BindingParamsArray> bindingParamsArray()
62 {
63 return mParamsArray.forget();
64 }
65
66
67 private:
68 ~AsyncStatement();
69
70 /**
71 * Clean up the references JS helpers hold to us. For cycle-avoidance reasons
72 * they do not hold reference-counted references to us, so it is important
73 * we do this.
74 */
75 void cleanupJSHelpers();
76
77 /**
78 * @return a pointer to the BindingParams object to use with our Bind*
79 * method.
80 */
81 mozIStorageBindingParams *getParams();
82
83 /**
84 * The SQL string as passed by the user. We store it because we create the
85 * async statement on-demand on the async thread.
86 */
87 nsCString mSQLString;
88
89 /**
90 * Holds the array of parameters to bind to this statement when we execute
91 * it asynchronously.
92 */
93 nsRefPtr<BindingParamsArray> mParamsArray;
94
95 /**
96 * Caches the JS 'params' helper for this statement.
97 */
98 nsCOMPtr<nsIXPConnectJSObjectHolder> mStatementParamsHolder;
99
100 /**
101 * Have we been explicitly finalized by the user?
102 */
103 bool mFinalized;
104
105 /**
106 * Required for access to private mStatementParamsHolder field by
107 * AsyncStatementJSHelper::getParams.
108 */
109 friend class AsyncStatementJSHelper;
110 };
111
112 } // storage
113 } // mozilla
114
115 #endif // mozilla_storage_mozStorageAsyncStatement_h_

mercurial