storage/src/mozStorageStatement.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:b828819adb36
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 mozStorageStatement_h
8 #define mozStorageStatement_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 "mozIStorageStatement.h"
18 #include "mozIStorageValueArray.h"
19 #include "StorageBaseStatementInternal.h"
20 #include "mozilla/Attributes.h"
21
22 class nsIXPConnectJSObjectHolder;
23 struct sqlite3_stmt;
24
25 namespace mozilla {
26 namespace storage {
27 class StatementJSHelper;
28 class Connection;
29
30 class Statement MOZ_FINAL : public mozIStorageStatement
31 , public mozIStorageValueArray
32 , public StorageBaseStatementInternal
33 {
34 public:
35 NS_DECL_THREADSAFE_ISUPPORTS
36 NS_DECL_MOZISTORAGESTATEMENT
37 NS_DECL_MOZISTORAGEBASESTATEMENT
38 NS_DECL_MOZISTORAGEBINDINGPARAMS
39 // NS_DECL_MOZISTORAGEVALUEARRAY (methods in mozIStorageStatement)
40 NS_DECL_STORAGEBASESTATEMENTINTERNAL
41
42 Statement();
43
44 /**
45 * Initializes the object on aDBConnection by preparing the SQL statement
46 * given by aSQLStatement.
47 *
48 * @param aDBConnection
49 * The Connection object this statement is associated with.
50 * @param aNativeConnection
51 * The native Sqlite connection this statement is associated with.
52 * @param aSQLStatement
53 * The SQL statement to prepare that this object will represent.
54 */
55 nsresult initialize(Connection *aDBConnection,
56 sqlite3* aNativeConnection,
57 const nsACString &aSQLStatement);
58
59
60 /**
61 * Obtains the native statement pointer.
62 */
63 inline sqlite3_stmt *nativeStatement() { return mDBStatement; }
64
65 /**
66 * Obtains and transfers ownership of the array of parameters that are bound
67 * to this statment. This can be null.
68 */
69 inline already_AddRefed<BindingParamsArray> bindingParamsArray()
70 {
71 return mParamsArray.forget();
72 }
73
74 private:
75 ~Statement();
76
77 sqlite3_stmt *mDBStatement;
78 uint32_t mParamCount;
79 uint32_t mResultColumnCount;
80 nsTArray<nsCString> mColumnNames;
81 bool mExecuting;
82
83 /**
84 * @return a pointer to the BindingParams object to use with our Bind*
85 * method.
86 */
87 mozIStorageBindingParams *getParams();
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 * The following two members are only used with the JS helper. They cache
97 * the row and params objects.
98 */
99 nsCOMPtr<nsIXPConnectJSObjectHolder> mStatementParamsHolder;
100 nsCOMPtr<nsIXPConnectJSObjectHolder> mStatementRowHolder;
101
102 /**
103 * Internal version of finalize that allows us to tell it if it is being
104 * called from the destructor so it can know not to dispatch events that
105 * require a reference to us.
106 *
107 * @param aDestructing
108 * Is the destructor calling?
109 */
110 nsresult internalFinalize(bool aDestructing);
111
112 friend class StatementJSHelper;
113 };
114
115 } // storage
116 } // mozilla
117
118 #endif // mozStorageStatement_h

mercurial