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