Bug 1762395 [wpt PR 33447] - Update idlharness.js tests for new File System standard...
[gecko.git] / storage / mozStorageStatement.h
blobe472a804c2d0236193cec8ce1ac281260bff2a28
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 "nsString.h"
12 #include "nsTArray.h"
14 #include "mozStorageBindingParamsArray.h"
15 #include "mozStorageStatementData.h"
16 #include "mozIStorageStatement.h"
17 #include "mozIStorageValueArray.h"
18 #include "StorageBaseStatementInternal.h"
19 #include "mozilla/Attributes.h"
21 struct sqlite3_stmt;
23 namespace mozilla {
24 namespace storage {
25 class StatementJSHelper;
26 class Connection;
27 class StatementParamsHolder;
28 class StatementRowHolder;
30 class Statement final : public mozIStorageStatement,
31 public mozIStorageValueArray,
32 public StorageBaseStatementInternal {
33 public:
34 NS_DECL_THREADSAFE_ISUPPORTS
35 NS_DECL_MOZISTORAGESTATEMENT
36 NS_DECL_MOZISTORAGEBASESTATEMENT
37 NS_DECL_MOZISTORAGEBINDINGPARAMS
38 // NS_DECL_MOZISTORAGEVALUEARRAY (methods in mozIStorageStatement)
39 NS_DECL_STORAGEBASESTATEMENTINTERNAL
41 Statement();
43 /**
44 * Initializes the object on aDBConnection by preparing the SQL statement
45 * given by aSQLStatement.
47 * @param aDBConnection
48 * The Connection object this statement is associated with.
49 * @param aNativeConnection
50 * The native Sqlite connection this statement is associated with.
51 * @param aSQLStatement
52 * The SQL statement to prepare that this object will represent.
54 nsresult initialize(Connection* aDBConnection, sqlite3* aNativeConnection,
55 const nsACString& aSQLStatement);
57 /**
58 * Obtains the native statement pointer.
60 inline sqlite3_stmt* nativeStatement() { return mDBStatement; }
62 /**
63 * Obtains and transfers ownership of the array of parameters that are bound
64 * to this statment. This can be null.
66 inline already_AddRefed<BindingParamsArray> bindingParamsArray() {
67 return mParamsArray.forget();
70 private:
71 ~Statement();
73 sqlite3_stmt* mDBStatement;
74 uint32_t mParamCount;
75 uint32_t mResultColumnCount;
76 nsTArray<nsCString> mColumnNames;
77 bool mExecuting;
79 // Tracks whether the status for this statement has been recorded since it was
80 // last reset or created.
81 bool mQueryStatusRecorded;
82 // Tracks whether this statement has been executed since it was last reset or
83 // created.
84 bool mHasExecuted;
86 /**
87 * @return a pointer to the BindingParams object to use with our Bind*
88 * method.
90 mozIStorageBindingParams* getParams();
92 /**
93 * Records a query status result in telemetry. If a result has already been
94 * recorded for this statement then this does nothing. Otherwise the result
95 * is recorded if it is an error or if this is the final result.
97 void MaybeRecordQueryStatus(int srv, bool isResetting = false);
99 /**
100 * Holds the array of parameters to bind to this statement when we execute
101 * it asynchronously.
103 RefPtr<BindingParamsArray> mParamsArray;
106 * The following two members are only used with the JS helper. They cache
107 * the row and params objects.
109 nsMainThreadPtrHandle<StatementParamsHolder> mStatementParamsHolder;
110 nsMainThreadPtrHandle<StatementRowHolder> mStatementRowHolder;
113 * Internal version of finalize that allows us to tell it if it is being
114 * called from the destructor so it can know not to dispatch events that
115 * require a reference to us.
117 * @param aDestructing
118 * Is the destructor calling?
120 nsresult internalFinalize(bool aDestructing);
122 friend class StatementJSHelper;
125 inline nsISupports* ToSupports(Statement* p) {
126 return NS_ISUPPORTS_CAST(mozIStorageStatement*, p);
129 } // namespace storage
130 } // namespace mozilla
132 #endif // mozStorageStatement_h