Bug 628949 - Update visible region / glass regions after we paint. r=roc a=2.0.
[mozilla-central.git] / storage / src / mozStorageStatementData.h
blob38fad062bd35820eb5cf33d940b2d179cf6d56a8
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 sts=2 et
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Mozilla Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2009
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Shawn Wilsher <me@shawnwilsher.com> (Original Author)
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.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef mozStorageStatementData_h
41 #define mozStorageStatementData_h
43 #include "sqlite3.h"
45 #include "nsAutoPtr.h"
46 #include "nsTArray.h"
48 #include "mozStorageBindingParamsArray.h"
49 #include "mozIStorageBaseStatement.h"
50 #include "mozStorageConnection.h"
51 #include "StorageBaseStatementInternal.h"
53 struct sqlite3_stmt;
55 namespace mozilla {
56 namespace storage {
58 class StatementData
60 public:
61 StatementData(sqlite3_stmt *aStatement,
62 already_AddRefed<BindingParamsArray> aParamsArray,
63 StorageBaseStatementInternal *aStatementOwner)
64 : mStatement(aStatement)
65 , mParamsArray(aParamsArray)
66 , mStatementOwner(aStatementOwner)
69 StatementData(const StatementData &aSource)
70 : mStatement(aSource.mStatement)
71 , mParamsArray(aSource.mParamsArray)
72 , mStatementOwner(aSource.mStatementOwner)
75 StatementData()
79 /**
80 * Return the sqlite statement, fetching it from the storage statement. In
81 * the case of AsyncStatements this may actually create the statement
83 inline int getSqliteStatement(sqlite3_stmt **_stmt)
85 if (!mStatement) {
86 int rc = mStatementOwner->getAsyncStatement(&mStatement);
87 NS_ENSURE_TRUE(rc == SQLITE_OK, rc);
89 *_stmt = mStatement;
90 return SQLITE_OK;
93 operator BindingParamsArray *() const { return mParamsArray; }
95 /**
96 * Provide the ability to coerce back to a sqlite3 * connection for purposes
97 * of getting an error message out of it.
99 operator sqlite3 *() const
101 return mStatementOwner->getOwner()->GetNativeConnection();
105 * NULLs out our sqlite3_stmt (it is held by the owner) after reseting it and
106 * clear all bindings to it. This is expected to occur on the async thread.
108 * We do not clear mParamsArray out because we only want to release
109 * mParamsArray on the calling thread because of XPCVariant addref/release
110 * thread-safety issues. The same holds for mStatementOwner which can be
111 * holding such a reference chain as well.
113 inline void finalize()
115 // In the AsyncStatement case we may never have populated mStatement if the
116 // AsyncExecuteStatements got canceled or a failure occurred in constructing
117 // the statement.
118 if (mStatement) {
119 (void)::sqlite3_reset(mStatement);
120 (void)::sqlite3_clear_bindings(mStatement);
121 mStatement = NULL;
126 * Indicates if this statement has parameters to be bound before it is
127 * executed.
129 * @return true if the statement has parameters to bind against, false
130 * otherwise.
132 inline bool hasParametersToBeBound() const { return !!mParamsArray; }
134 * Indicates if this statement needs a transaction for execution.
136 * @return true if the statement needs a transaction, false otherwise.
138 inline bool needsTransaction() const
140 return mParamsArray != nsnull && mParamsArray->length() > 1;
143 private:
144 sqlite3_stmt *mStatement;
145 nsRefPtr<BindingParamsArray> mParamsArray;
148 * We hold onto a reference of the statement's owner so it doesn't get
149 * destroyed out from under us.
151 nsCOMPtr<StorageBaseStatementInternal> mStatementOwner;
154 } // namespace storage
155 } // namespace mozilla
157 #endif // mozStorageStatementData_h