Bug 434796
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Wed, 11 Jun 2008 11:00:09 -0400
changeset 15318 a2741a49c3fa07389eadd66e3518a398f3d6b89b
parent 15317 efec937177fd1a257c1113dfa1a13ec5069f9e2e
child 15319 cf5b92c60cc378963cd0c4096d52043c765e9cff
push idunknown
push userunknown
push dateunknown
bugs434796
milestone1.9.1a1pre
Bug 434796 Remove mozIStorageStatement::initialize r=vlad sr=shaver
storage/public/mozIStorageStatement.idl
storage/src/mozStorageStatement.cpp
storage/src/mozStorageStatement.h
--- a/storage/public/mozIStorageStatement.idl
+++ b/storage/public/mozIStorageStatement.idl
@@ -40,26 +40,19 @@
 #include "mozIStorageValueArray.idl"
 
 interface mozIStorageConnection;
 interface mozIStorageDataSet;
 interface nsISimpleEnumerator;
 
 [ptr] native sqlite3stmtptr(struct sqlite3_stmt);
 
-[scriptable, uuid(42fad13e-c67d-4b2c-bd61-2c5b17186772)]
+[scriptable, uuid(4101bda7-6ec8-4a72-bbf8-6569af0030ea)]
 interface mozIStorageStatement : mozIStorageValueArray {
   /**
-   * Initialize this query with the given SQL statement.
-   *
-   */
-  void initialize(in mozIStorageConnection aDBConnection,
-                  in AUTF8String aSQLStatement);
-
-  /**
    * Finalizes a statement so you can successfully close a database connection.
    * This method does not need to be used from native callers since you can just
    * set the statement to null, but is extremely useful to JS callers.
    */
   void finalize();
 
   /**
    * Create a clone of this statement, by initializing a new statement
--- a/storage/src/mozStorageStatement.cpp
+++ b/storage/src/mozStorageStatement.cpp
@@ -87,41 +87,28 @@ protected:
 
 NS_IMPL_ISUPPORTS2(mozStorageStatement, mozIStorageStatement, mozIStorageValueArray)
 
 mozStorageStatement::mozStorageStatement()
     : mDBConnection (nsnull), mDBStatement(nsnull), mColumnNames(nsnull), mExecuting(PR_FALSE)
 {
 }
 
-NS_IMETHODIMP
-mozStorageStatement::Initialize(mozIStorageConnection *aDBConnection, const nsACString & aSQLStatement)
+nsresult
+mozStorageStatement::Initialize(mozStorageConnection *aDBConnection,
+                                const nsACString & aSQLStatement)
 {
-    int srv;
+    NS_ASSERTION(aDBConnection, "No database connection given!");
+    NS_ASSERTION(!mDBStatement, "Calling Initialize on an already initialized statement!");
 
-    // we can't do this if we're mid-execute
-    if (mExecuting) {
-        return NS_ERROR_FAILURE;
-    }
-
-    sqlite3 *db = nsnull;
-    // XXX - need to implement a private iid to QI for here, to make sure
-    // we have a real mozStorageConnection
-    mozStorageConnection *msc = static_cast<mozStorageConnection*>(aDBConnection);
-    db = msc->GetNativeConnection();
+    sqlite3 *db = aDBConnection->GetNativeConnection();
     NS_ENSURE_TRUE(db != nsnull, NS_ERROR_NULL_POINTER);
 
-    // clean up old goop
-    if (mDBStatement) {
-        sqlite3_finalize(mDBStatement);
-        mDBStatement = nsnull;
-    }
-
     int nRetries = 0;
-
+    int srv;
     while (nRetries < 2) {
         srv = sqlite3_prepare_v2(db, nsPromiseFlatCString(aSQLStatement).get(),
                                  aSQLStatement.Length(), &mDBStatement, NULL);
         if ((srv == SQLITE_SCHEMA && nRetries != 0) ||
             (srv != SQLITE_SCHEMA && srv != SQLITE_OK))
         {
 #ifdef PR_LOGGING
             PR_LOG(gStorageLog, PR_LOG_ERROR, ("Sqlite statement prepare error: %d '%s'", srv, sqlite3_errmsg(db)));
--- a/storage/src/mozStorageStatement.h
+++ b/storage/src/mozStorageStatement.h
@@ -34,41 +34,52 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _MOZSTORAGESTATEMENT_H_
 #define _MOZSTORAGESTATEMENT_H_
 
-#include "nsCOMPtr.h"
+#include "nsAutoPtr.h"
 #include "nsString.h"
 
 #include "nsVoidArray.h"
 
 #include "mozIStorageStatement.h"
-#include "mozIStorageConnection.h"
 
 #include <sqlite3.h>
 
 class mozStorageStatement : public mozIStorageStatement
 {
 public:
     mozStorageStatement();
 
     // interfaces
     NS_DECL_ISUPPORTS
     NS_DECL_MOZISTORAGESTATEMENT
     NS_DECL_MOZISTORAGEVALUEARRAY
 
+    /**
+     * Initializes the object on aDBConnection by preparing the SQL statement
+     * given by aSQLStatement.
+     *
+     * @param aDBConnection
+     *        The mozStorageConnection object this statement is associated with.
+     * @param aSQLStatement
+     *        The SQL statement to prepare that this object will represent.
+     */
+    nsresult Initialize(mozStorageConnection *aDBConnection,
+                        const nsACString &aSQLStatement);
+
 private:
     ~mozStorageStatement();
 
 protected:
-    nsCOMPtr<mozIStorageConnection> mDBConnection;
+    nsRefPtr<mozStorageConnection> mDBConnection;
     sqlite3_stmt *mDBStatement;
     PRUint32 mParamCount;
     PRUint32 mResultColumnCount;
     nsCStringArray mColumnNames;
     PRBool mExecuting;
 
 };