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 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Oracle Corporation code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Oracle Corporation
20 : * Portions created by the Initial Developer are Copyright (C) 2004
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef mozStorageStatement_h
41 : #define mozStorageStatement_h
42 :
43 : #include "nsAutoPtr.h"
44 : #include "nsString.h"
45 :
46 : #include "nsTArray.h"
47 :
48 : #include "mozStorageBindingParamsArray.h"
49 : #include "mozStorageStatementData.h"
50 : #include "mozIStorageStatement.h"
51 : #include "mozIStorageValueArray.h"
52 : #include "StorageBaseStatementInternal.h"
53 :
54 : class nsIXPConnectJSObjectHolder;
55 : struct sqlite3_stmt;
56 :
57 : namespace mozilla {
58 : namespace storage {
59 : class StatementJSHelper;
60 : class Connection;
61 :
62 : class Statement : public mozIStorageStatement
63 : , public mozIStorageValueArray
64 : , public StorageBaseStatementInternal
65 : {
66 : public:
67 : NS_DECL_ISUPPORTS
68 : NS_DECL_MOZISTORAGESTATEMENT
69 : NS_DECL_MOZISTORAGEBASESTATEMENT
70 : NS_DECL_MOZISTORAGEBINDINGPARAMS
71 : // NS_DECL_MOZISTORAGEVALUEARRAY (methods in mozIStorageStatement)
72 : NS_DECL_STORAGEBASESTATEMENTINTERNAL
73 :
74 : Statement();
75 :
76 : /**
77 : * Initializes the object on aDBConnection by preparing the SQL statement
78 : * given by aSQLStatement.
79 : *
80 : * @param aDBConnection
81 : * The Connection object this statement is associated with.
82 : * @param aSQLStatement
83 : * The SQL statement to prepare that this object will represent.
84 : */
85 : nsresult initialize(Connection *aDBConnection,
86 : const nsACString &aSQLStatement);
87 :
88 :
89 : /**
90 : * Obtains the native statement pointer.
91 : */
92 46 : inline sqlite3_stmt *nativeStatement() { return mDBStatement; }
93 :
94 : /**
95 : * Obtains and transfers ownership of the array of parameters that are bound
96 : * to this statment. This can be null.
97 : */
98 16240 : inline already_AddRefed<BindingParamsArray> bindingParamsArray()
99 : {
100 16240 : return mParamsArray.forget();
101 : }
102 :
103 : private:
104 : ~Statement();
105 :
106 : sqlite3_stmt *mDBStatement;
107 : PRUint32 mParamCount;
108 : PRUint32 mResultColumnCount;
109 : nsTArray<nsCString> mColumnNames;
110 : bool mExecuting;
111 :
112 : /**
113 : * @return a pointer to the BindingParams object to use with our Bind*
114 : * method.
115 : */
116 : mozIStorageBindingParams *getParams();
117 :
118 : /**
119 : * Holds the array of parameters to bind to this statement when we execute
120 : * it asynchronously.
121 : */
122 : nsRefPtr<BindingParamsArray> mParamsArray;
123 :
124 : /**
125 : * The following two members are only used with the JS helper. They cache
126 : * the row and params objects.
127 : */
128 : nsCOMPtr<nsIXPConnectJSObjectHolder> mStatementParamsHolder;
129 : nsCOMPtr<nsIXPConnectJSObjectHolder> mStatementRowHolder;
130 :
131 : /**
132 : * Internal version of finalize that allows us to tell it if it is being
133 : * called from the destructor so it can know not to dispatch events that
134 : * require a reference to us.
135 : *
136 : * @param aDestructing
137 : * Is the destructor calling?
138 : */
139 : nsresult internalFinalize(bool aDestructing);
140 :
141 : friend class StatementJSHelper;
142 : };
143 :
144 : } // storage
145 : } // mozilla
146 :
147 : #endif // mozStorageStatement_h
|