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"
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"
26 class StatementJSHelper
;
28 class StatementParamsHolder
;
29 class StatementRowHolder
;
31 class Statement final
: public mozIStorageStatement
32 , public mozIStorageValueArray
33 , public StorageBaseStatementInternal
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
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
);
62 * Obtains the native statement pointer.
64 inline sqlite3_stmt
*nativeStatement() { return mDBStatement
; }
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();
78 sqlite3_stmt
*mDBStatement
;
80 uint32_t mResultColumnCount
;
81 nsTArray
<nsCString
> mColumnNames
;
85 * @return a pointer to the BindingParams object to use with our Bind*
88 mozIStorageBindingParams
*getParams();
91 * Holds the array of parameters to bind to this statement when we execute
94 RefPtr
<BindingParamsArray
> mParamsArray
;
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
;
117 ToSupports(Statement
* p
)
119 return NS_ISUPPORTS_CAST(mozIStorageStatement
*, p
);
122 } // namespace storage
123 } // namespace mozilla
125 #endif // mozStorageStatement_h