tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mozStorageStatement.h (3965B)


      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/. */
      6 
      7 #ifndef mozStorageStatement_h
      8 #define mozStorageStatement_h
      9 
     10 #include "nsString.h"
     11 
     12 #include "nsTArray.h"
     13 
     14 #include "mozStorageBindingParamsArray.h"
     15 #include "mozStorageStatementData.h"
     16 #include "mozIStorageStatement.h"
     17 #include "mozIStorageValueArray.h"
     18 #include "StorageBaseStatementInternal.h"
     19 
     20 struct sqlite3_stmt;
     21 
     22 namespace mozilla {
     23 namespace storage {
     24 class StatementJSHelper;
     25 class Connection;
     26 class StatementParamsHolder;
     27 class StatementRowHolder;
     28 
     29 class Statement final : public mozIStorageStatement,
     30                        public mozIStorageValueArray,
     31                        public StorageBaseStatementInternal {
     32 public:
     33  NS_DECL_THREADSAFE_ISUPPORTS
     34  NS_DECL_MOZISTORAGESTATEMENT
     35  NS_DECL_MOZISTORAGEBASESTATEMENT
     36  NS_DECL_MOZISTORAGEBINDINGPARAMS
     37  // NS_DECL_MOZISTORAGEVALUEARRAY (methods in mozIStorageStatement)
     38  NS_DECL_STORAGEBASESTATEMENTINTERNAL
     39 
     40  Statement();
     41 
     42  /**
     43   * Initializes the object on aDBConnection by preparing the SQL statement
     44   * given by aSQLStatement.
     45   *
     46   * @param aDBConnection
     47   *        The Connection object this statement is associated with.
     48   * @param aNativeConnection
     49   *        The native Sqlite connection this statement is associated with.
     50   * @param aSQLStatement
     51   *        The SQL statement to prepare that this object will represent.
     52   */
     53  nsresult initialize(Connection* aDBConnection, sqlite3* aNativeConnection,
     54                      const nsACString& aSQLStatement);
     55 
     56  /**
     57   * Obtains the native statement pointer.
     58   */
     59  inline sqlite3_stmt* nativeStatement() { return mDBStatement; }
     60 
     61  /**
     62   * Obtains and transfers ownership of the array of parameters that are bound
     63   * to this statment.  This can be null.
     64   */
     65  inline already_AddRefed<BindingParamsArray> bindingParamsArray() {
     66    return mParamsArray.forget();
     67  }
     68 
     69 private:
     70  ~Statement();
     71 
     72  sqlite3_stmt* mDBStatement;
     73  uint32_t mParamCount;
     74  uint32_t mResultColumnCount;
     75  nsTArray<nsCString> mColumnNames;
     76  bool mExecuting;
     77 
     78  // Tracks whether the status for this statement has been recorded since it was
     79  // last reset or created.
     80  bool mQueryStatusRecorded;
     81  // Tracks whether this statement has been executed since it was last reset or
     82  // created.
     83  bool mHasExecuted;
     84 
     85  /**
     86   * @return a pointer to the BindingParams object to use with our Bind*
     87   *         method.
     88   */
     89  mozIStorageBindingParams* getParams();
     90 
     91  /**
     92   * Records a query status result in telemetry. If a result has already been
     93   * recorded for this statement then this does nothing. Otherwise the result
     94   * is recorded if it is an error or if this is the final result.
     95   */
     96  void MaybeRecordQueryStatus(int srv, bool isResetting = false);
     97 
     98  /**
     99   * Holds the array of parameters to bind to this statement when we execute
    100   * it asynchronously.
    101   */
    102  RefPtr<BindingParamsArray> mParamsArray;
    103 
    104  /**
    105   * The following two members are only used with the JS helper.  They cache
    106   * the row and params objects.
    107   */
    108  nsMainThreadPtrHandle<StatementParamsHolder> mStatementParamsHolder;
    109  nsMainThreadPtrHandle<StatementRowHolder> mStatementRowHolder;
    110 
    111  /**
    112   * Internal version of finalize that allows us to tell it if it is being
    113   * called from the destructor so it can know not to dispatch events that
    114   * require a reference to us.
    115   *
    116   * @param aDestructing
    117   *        Is the destructor calling?
    118   */
    119  nsresult internalFinalize(bool aDestructing);
    120 
    121  friend class StatementJSHelper;
    122 };
    123 
    124 inline nsISupports* ToSupports(Statement* p) {
    125  return NS_ISUPPORTS_CAST(mozIStorageStatement*, p);
    126 }
    127 
    128 }  // namespace storage
    129 }  // namespace mozilla
    130 
    131 #endif  // mozStorageStatement_h