storage/src/mozStorageStatement.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/storage/src/mozStorageStatement.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozStorageStatement_h
    1.11 +#define mozStorageStatement_h
    1.12 +
    1.13 +#include "nsAutoPtr.h"
    1.14 +#include "nsString.h"
    1.15 +
    1.16 +#include "nsTArray.h"
    1.17 +
    1.18 +#include "mozStorageBindingParamsArray.h"
    1.19 +#include "mozStorageStatementData.h"
    1.20 +#include "mozIStorageStatement.h"
    1.21 +#include "mozIStorageValueArray.h"
    1.22 +#include "StorageBaseStatementInternal.h"
    1.23 +#include "mozilla/Attributes.h"
    1.24 +
    1.25 +class nsIXPConnectJSObjectHolder;
    1.26 +struct sqlite3_stmt;
    1.27 +
    1.28 +namespace mozilla {
    1.29 +namespace storage {
    1.30 +class StatementJSHelper;
    1.31 +class Connection;
    1.32 +
    1.33 +class Statement MOZ_FINAL : public mozIStorageStatement
    1.34 +                          , public mozIStorageValueArray
    1.35 +                          , public StorageBaseStatementInternal
    1.36 +{
    1.37 +public:
    1.38 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.39 +  NS_DECL_MOZISTORAGESTATEMENT
    1.40 +  NS_DECL_MOZISTORAGEBASESTATEMENT
    1.41 +  NS_DECL_MOZISTORAGEBINDINGPARAMS
    1.42 +  // NS_DECL_MOZISTORAGEVALUEARRAY (methods in mozIStorageStatement)
    1.43 +  NS_DECL_STORAGEBASESTATEMENTINTERNAL
    1.44 +
    1.45 +  Statement();
    1.46 +
    1.47 +  /**
    1.48 +   * Initializes the object on aDBConnection by preparing the SQL statement
    1.49 +   * given by aSQLStatement.
    1.50 +   *
    1.51 +   * @param aDBConnection
    1.52 +   *        The Connection object this statement is associated with.
    1.53 +   * @param aNativeConnection
    1.54 +   *        The native Sqlite connection this statement is associated with.
    1.55 +   * @param aSQLStatement
    1.56 +   *        The SQL statement to prepare that this object will represent.
    1.57 +   */
    1.58 +  nsresult initialize(Connection *aDBConnection,
    1.59 +                      sqlite3* aNativeConnection,
    1.60 +                      const nsACString &aSQLStatement);
    1.61 +
    1.62 +
    1.63 +  /**
    1.64 +   * Obtains the native statement pointer.
    1.65 +   */
    1.66 +  inline sqlite3_stmt *nativeStatement() { return mDBStatement; }
    1.67 +
    1.68 +  /**
    1.69 +   * Obtains and transfers ownership of the array of parameters that are bound
    1.70 +   * to this statment.  This can be null.
    1.71 +   */
    1.72 +  inline already_AddRefed<BindingParamsArray> bindingParamsArray()
    1.73 +  {
    1.74 +    return mParamsArray.forget();
    1.75 +  }
    1.76 +
    1.77 +private:
    1.78 +    ~Statement();
    1.79 +
    1.80 +    sqlite3_stmt *mDBStatement;
    1.81 +    uint32_t mParamCount;
    1.82 +    uint32_t mResultColumnCount;
    1.83 +    nsTArray<nsCString> mColumnNames;
    1.84 +    bool mExecuting;
    1.85 +
    1.86 +    /**
    1.87 +     * @return a pointer to the BindingParams object to use with our Bind*
    1.88 +     *         method.
    1.89 +     */
    1.90 +    mozIStorageBindingParams *getParams();
    1.91 +
    1.92 +    /**
    1.93 +     * Holds the array of parameters to bind to this statement when we execute
    1.94 +     * it asynchronously.
    1.95 +     */
    1.96 +    nsRefPtr<BindingParamsArray> mParamsArray;
    1.97 +
    1.98 +    /**
    1.99 +     * The following two members are only used with the JS helper.  They cache
   1.100 +     * the row and params objects.
   1.101 +     */
   1.102 +    nsCOMPtr<nsIXPConnectJSObjectHolder> mStatementParamsHolder;
   1.103 +    nsCOMPtr<nsIXPConnectJSObjectHolder> mStatementRowHolder;
   1.104 +
   1.105 +  /**
   1.106 +   * Internal version of finalize that allows us to tell it if it is being
   1.107 +   * called from the destructor so it can know not to dispatch events that
   1.108 +   * require a reference to us.
   1.109 +   *
   1.110 +   * @param aDestructing
   1.111 +   *        Is the destructor calling?
   1.112 +   */
   1.113 +  nsresult internalFinalize(bool aDestructing);
   1.114 +
   1.115 +    friend class StatementJSHelper;
   1.116 +};
   1.117 +
   1.118 +} // storage
   1.119 +} // mozilla
   1.120 +
   1.121 +#endif // mozStorageStatement_h

mercurial