1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/storage/src/mozStorageAsyncStatement.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,115 @@ 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 mozilla_storage_mozStorageAsyncStatement_h_ 1.11 +#define mozilla_storage_mozStorageAsyncStatement_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 "mozIStorageAsyncStatement.h" 1.21 +#include "StorageBaseStatementInternal.h" 1.22 +#include "mozilla/Attributes.h" 1.23 + 1.24 +class nsIXPConnectJSObjectHolder; 1.25 +struct sqlite3_stmt; 1.26 + 1.27 +namespace mozilla { 1.28 +namespace storage { 1.29 + 1.30 +class AsyncStatementJSHelper; 1.31 +class Connection; 1.32 + 1.33 +class AsyncStatement MOZ_FINAL : public mozIStorageAsyncStatement 1.34 + , public StorageBaseStatementInternal 1.35 +{ 1.36 +public: 1.37 + NS_DECL_THREADSAFE_ISUPPORTS 1.38 + NS_DECL_MOZISTORAGEASYNCSTATEMENT 1.39 + NS_DECL_MOZISTORAGEBASESTATEMENT 1.40 + NS_DECL_MOZISTORAGEBINDINGPARAMS 1.41 + NS_DECL_STORAGEBASESTATEMENTINTERNAL 1.42 + 1.43 + AsyncStatement(); 1.44 + 1.45 + /** 1.46 + * Initializes the object on aDBConnection by preparing the SQL statement 1.47 + * given by aSQLStatement. 1.48 + * 1.49 + * @param aDBConnection 1.50 + * The Connection object this statement is associated with. 1.51 + * @param aNativeConnection 1.52 + * The native Sqlite connection this statement is associated with. 1.53 + * @param aSQLStatement 1.54 + * The SQL statement to prepare that this object will represent. 1.55 + */ 1.56 + nsresult initialize(Connection *aDBConnection, 1.57 + sqlite3 *aNativeConnection, 1.58 + const nsACString &aSQLStatement); 1.59 + 1.60 + /** 1.61 + * Obtains and transfers ownership of the array of parameters that are bound 1.62 + * to this statment. This can be null. 1.63 + */ 1.64 + inline already_AddRefed<BindingParamsArray> bindingParamsArray() 1.65 + { 1.66 + return mParamsArray.forget(); 1.67 + } 1.68 + 1.69 + 1.70 +private: 1.71 + ~AsyncStatement(); 1.72 + 1.73 + /** 1.74 + * Clean up the references JS helpers hold to us. For cycle-avoidance reasons 1.75 + * they do not hold reference-counted references to us, so it is important 1.76 + * we do this. 1.77 + */ 1.78 + void cleanupJSHelpers(); 1.79 + 1.80 + /** 1.81 + * @return a pointer to the BindingParams object to use with our Bind* 1.82 + * method. 1.83 + */ 1.84 + mozIStorageBindingParams *getParams(); 1.85 + 1.86 + /** 1.87 + * The SQL string as passed by the user. We store it because we create the 1.88 + * async statement on-demand on the async thread. 1.89 + */ 1.90 + nsCString mSQLString; 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 + * Caches the JS 'params' helper for this statement. 1.100 + */ 1.101 + nsCOMPtr<nsIXPConnectJSObjectHolder> mStatementParamsHolder; 1.102 + 1.103 + /** 1.104 + * Have we been explicitly finalized by the user? 1.105 + */ 1.106 + bool mFinalized; 1.107 + 1.108 + /** 1.109 + * Required for access to private mStatementParamsHolder field by 1.110 + * AsyncStatementJSHelper::getParams. 1.111 + */ 1.112 + friend class AsyncStatementJSHelper; 1.113 +}; 1.114 + 1.115 +} // storage 1.116 +} // mozilla 1.117 + 1.118 +#endif // mozilla_storage_mozStorageAsyncStatement_h_