Bug 1473870 [wpt PR 11496] - Update webidl2 to v13.0.3, a=testonly
[gecko.git] / storage / mozStorageStatement.h
blob87c165a1247d7573a4bc9dd245b188a2f338ac70
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/. */
7 #ifndef mozStorageStatement_h
8 #define mozStorageStatement_h
10 #include "nsAutoPtr.h"
11 #include "nsString.h"
13 #include "nsTArray.h"
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"
22 struct sqlite3_stmt;
24 namespace mozilla {
25 namespace storage {
26 class StatementJSHelper;
27 class Connection;
28 class StatementParamsHolder;
29 class StatementRowHolder;
31 class Statement final : public mozIStorageStatement
32 , public mozIStorageValueArray
33 , public StorageBaseStatementInternal
35 public:
36 NS_DECL_THREADSAFE_ISUPPORTS
37 NS_DECL_MOZISTORAGESTATEMENT
38 NS_DECL_MOZISTORAGEBASESTATEMENT
39 NS_DECL_MOZISTORAGEBINDINGPARAMS
40 // NS_DECL_MOZISTORAGEVALUEARRAY (methods in mozIStorageStatement)
41 NS_DECL_STORAGEBASESTATEMENTINTERNAL
43 Statement();
45 /**
46 * Initializes the object on aDBConnection by preparing the SQL statement
47 * given by aSQLStatement.
49 * @param aDBConnection
50 * The Connection object this statement is associated with.
51 * @param aNativeConnection
52 * The native Sqlite connection this statement is associated with.
53 * @param aSQLStatement
54 * The SQL statement to prepare that this object will represent.
56 nsresult initialize(Connection *aDBConnection,
57 sqlite3* aNativeConnection,
58 const nsACString &aSQLStatement);
61 /**
62 * Obtains the native statement pointer.
64 inline sqlite3_stmt *nativeStatement() { return mDBStatement; }
66 /**
67 * Obtains and transfers ownership of the array of parameters that are bound
68 * to this statment. This can be null.
70 inline already_AddRefed<BindingParamsArray> bindingParamsArray()
72 return mParamsArray.forget();
75 private:
76 ~Statement();
78 sqlite3_stmt *mDBStatement;
79 uint32_t mParamCount;
80 uint32_t mResultColumnCount;
81 nsTArray<nsCString> mColumnNames;
82 bool mExecuting;
84 /**
85 * @return a pointer to the BindingParams object to use with our Bind*
86 * method.
88 mozIStorageBindingParams *getParams();
90 /**
91 * Holds the array of parameters to bind to this statement when we execute
92 * it asynchronously.
94 RefPtr<BindingParamsArray> mParamsArray;
96 /**
97 * The following two members are only used with the JS helper. They cache
98 * the row and params objects.
100 nsMainThreadPtrHandle<StatementParamsHolder> mStatementParamsHolder;
101 nsMainThreadPtrHandle<StatementRowHolder> mStatementRowHolder;
104 * Internal version of finalize that allows us to tell it if it is being
105 * called from the destructor so it can know not to dispatch events that
106 * require a reference to us.
108 * @param aDestructing
109 * Is the destructor calling?
111 nsresult internalFinalize(bool aDestructing);
113 friend class StatementJSHelper;
116 inline nsISupports*
117 ToSupports(Statement* p)
119 return NS_ISUPPORTS_CAST(mozIStorageStatement*, p);
122 } // namespace storage
123 } // namespace mozilla
125 #endif // mozStorageStatement_h