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
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"
25 class StatementJSHelper
;
27 class StatementParamsHolder
;
28 class StatementRowHolder
;
30 class Statement final
: public mozIStorageStatement
,
31 public mozIStorageValueArray
,
32 public StorageBaseStatementInternal
{
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
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
);
58 * Obtains the native statement pointer.
60 inline sqlite3_stmt
* nativeStatement() { return mDBStatement
; }
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();
73 sqlite3_stmt
* mDBStatement
;
75 uint32_t mResultColumnCount
;
76 nsTArray
<nsCString
> mColumnNames
;
80 * @return a pointer to the BindingParams object to use with our Bind*
83 mozIStorageBindingParams
* getParams();
86 * Holds the array of parameters to bind to this statement when we execute
89 RefPtr
<BindingParamsArray
> mParamsArray
;
92 * The following two members are only used with the JS helper. They cache
93 * the row and params objects.
95 nsMainThreadPtrHandle
<StatementParamsHolder
> mStatementParamsHolder
;
96 nsMainThreadPtrHandle
<StatementRowHolder
> mStatementRowHolder
;
99 * Internal version of finalize that allows us to tell it if it is being
100 * called from the destructor so it can know not to dispatch events that
101 * require a reference to us.
103 * @param aDestructing
104 * Is the destructor calling?
106 nsresult
internalFinalize(bool aDestructing
);
108 friend class StatementJSHelper
;
111 inline nsISupports
* ToSupports(Statement
* p
) {
112 return NS_ISUPPORTS_CAST(mozIStorageStatement
*, p
);
115 } // namespace storage
116 } // namespace mozilla
118 #endif // mozStorageStatement_h