2009-05-09 04:29:56 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-10-09 04:04:10 +04:00
|
|
|
|
2010-06-01 16:38:00 +04:00
|
|
|
#ifndef mozStorageStatement_h
|
|
|
|
#define mozStorageStatement_h
|
2004-10-09 04:04:10 +04:00
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
|
2009-01-22 07:15:34 +03:00
|
|
|
#include "nsTArray.h"
|
2004-12-03 19:56:57 +03:00
|
|
|
|
2009-06-17 23:12:51 +04:00
|
|
|
#include "mozStorageBindingParamsArray.h"
|
2009-07-28 21:21:03 +04:00
|
|
|
#include "mozStorageStatementData.h"
|
2004-10-09 04:04:10 +04:00
|
|
|
#include "mozIStorageStatement.h"
|
2010-03-24 10:32:40 +03:00
|
|
|
#include "mozIStorageValueArray.h"
|
|
|
|
#include "StorageBaseStatementInternal.h"
|
2012-06-13 07:35:10 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2004-10-09 04:04:10 +04:00
|
|
|
|
2009-05-09 04:29:56 +04:00
|
|
|
struct sqlite3_stmt;
|
2009-04-08 20:24:25 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace storage {
|
|
|
|
class StatementJSHelper;
|
2009-04-18 01:19:31 +04:00
|
|
|
class Connection;
|
2017-08-24 11:52:52 +03:00
|
|
|
class StatementParamsHolder;
|
2017-08-22 10:25:37 +03:00
|
|
|
class StatementRowHolder;
|
2008-07-11 23:47:33 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class Statement final : public mozIStorageStatement,
|
2015-03-27 21:52:19 +03:00
|
|
|
public mozIStorageValueArray,
|
|
|
|
public StorageBaseStatementInternal {
|
2004-10-09 04:04:10 +04:00
|
|
|
public:
|
2013-07-19 06:24:15 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-05-09 04:29:56 +04:00
|
|
|
NS_DECL_MOZISTORAGESTATEMENT
|
2010-03-24 10:32:40 +03:00
|
|
|
NS_DECL_MOZISTORAGEBASESTATEMENT
|
|
|
|
NS_DECL_MOZISTORAGEBINDINGPARAMS
|
|
|
|
// NS_DECL_MOZISTORAGEVALUEARRAY (methods in mozIStorageStatement)
|
|
|
|
NS_DECL_STORAGEBASESTATEMENTINTERNAL
|
2009-05-09 04:29:56 +04:00
|
|
|
|
|
|
|
Statement();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the object on aDBConnection by preparing the SQL statement
|
|
|
|
* given by aSQLStatement.
|
|
|
|
*
|
|
|
|
* @param aDBConnection
|
|
|
|
* The Connection object this statement is associated with.
|
2014-04-24 13:54:09 +04:00
|
|
|
* @param aNativeConnection
|
|
|
|
* The native Sqlite connection this statement is associated with.
|
2009-05-09 04:29:56 +04:00
|
|
|
* @param aSQLStatement
|
|
|
|
* The SQL statement to prepare that this object will represent.
|
|
|
|
*/
|
|
|
|
nsresult initialize(Connection* aDBConnection, sqlite3* aNativeConnection,
|
|
|
|
const nsACString& aSQLStatement);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains the native statement pointer.
|
|
|
|
*/
|
|
|
|
inline sqlite3_stmt* nativeStatement() { return mDBStatement; }
|
2008-07-11 23:47:33 +04:00
|
|
|
|
2009-06-17 23:12:51 +04:00
|
|
|
/**
|
|
|
|
* Obtains and transfers ownership of the array of parameters that are bound
|
|
|
|
* to this statment. This can be null.
|
|
|
|
*/
|
|
|
|
inline already_AddRefed<BindingParamsArray> bindingParamsArray() {
|
|
|
|
return mParamsArray.forget();
|
|
|
|
}
|
|
|
|
|
2004-10-09 04:04:10 +04:00
|
|
|
private:
|
2009-05-09 04:29:56 +04:00
|
|
|
~Statement();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2004-10-09 04:04:10 +04:00
|
|
|
sqlite3_stmt* mDBStatement;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mParamCount;
|
|
|
|
uint32_t mResultColumnCount;
|
2009-01-22 07:15:34 +03:00
|
|
|
nsTArray<nsCString> mColumnNames;
|
2009-05-09 04:29:56 +04:00
|
|
|
bool mExecuting;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-08-11 23:55:33 +03:00
|
|
|
// Tracks whether the status for this statement has been recorded since it was
|
|
|
|
// last reset or created.
|
|
|
|
bool mQueryStatusRecorded;
|
|
|
|
// Tracks whether this statement has been executed since it was last reset or
|
|
|
|
// created.
|
|
|
|
bool mHasExecuted;
|
|
|
|
|
2009-07-28 21:21:03 +04:00
|
|
|
/**
|
|
|
|
* @return a pointer to the BindingParams object to use with our Bind*
|
|
|
|
* method.
|
|
|
|
*/
|
2010-03-24 10:32:40 +03:00
|
|
|
mozIStorageBindingParams* getParams();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-08-11 23:55:33 +03:00
|
|
|
/**
|
|
|
|
* Records a query status result in telemetry. If a result has already been
|
|
|
|
* recorded for this statement then this does nothing. Otherwise the result
|
|
|
|
* is recorded if it is an error or if this is the final result.
|
|
|
|
*/
|
|
|
|
void MaybeRecordQueryStatus(int srv, bool isResetting = false);
|
|
|
|
|
2009-06-17 23:12:51 +04:00
|
|
|
/**
|
|
|
|
* Holds the array of parameters to bind to this statement when we execute
|
|
|
|
* it asynchronously.
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BindingParamsArray> mParamsArray;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-09-13 01:30:41 +04:00
|
|
|
/**
|
|
|
|
* The following two members are only used with the JS helper. They cache
|
|
|
|
* the row and params objects.
|
|
|
|
*/
|
2017-08-24 11:52:52 +03:00
|
|
|
nsMainThreadPtrHandle<StatementParamsHolder> mStatementParamsHolder;
|
2017-08-22 10:25:37 +03:00
|
|
|
nsMainThreadPtrHandle<StatementRowHolder> mStatementRowHolder;
|
2008-09-13 01:30:41 +04:00
|
|
|
|
2010-03-24 10:32:40 +03:00
|
|
|
/**
|
|
|
|
* Internal version of finalize that allows us to tell it if it is being
|
|
|
|
* called from the destructor so it can know not to dispatch events that
|
|
|
|
* require a reference to us.
|
|
|
|
*
|
|
|
|
* @param aDestructing
|
|
|
|
* Is the destructor calling?
|
|
|
|
*/
|
|
|
|
nsresult internalFinalize(bool aDestructing);
|
|
|
|
|
2015-03-12 19:55:56 +03:00
|
|
|
friend class StatementJSHelper;
|
2004-10-09 04:04:10 +04:00
|
|
|
};
|
|
|
|
|
2017-08-22 10:25:37 +03:00
|
|
|
inline nsISupports* ToSupports(Statement* p) {
|
|
|
|
return NS_ISUPPORTS_CAST(mozIStorageStatement*, p);
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace storage
|
|
|
|
} // namespace mozilla
|
2009-05-09 04:29:56 +04:00
|
|
|
|
2010-06-01 16:38:00 +04:00
|
|
|
#endif // mozStorageStatement_h
|