Backed out changeset b6f09258a505 (bug 490833).
authorShawn Wilsher <me@shawnwilsher.com>
Fri, 08 May 2009 19:57:37 -0700
changeset 28148 c60c37d487cae83cbcbb7db59b1b867d6eba27e2
parent 28147 b6f09258a505f54e81d64221d35b096d68e7a844
child 28149 53351b69bbbd3014782236343b1bcb8dc740d9ee
push id6913
push usersdwilsh@shawnwilsher.com
push dateSat, 09 May 2009 02:58:20 +0000
treeherdermozilla-central@c60c37d487ca [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs490833
milestone1.9.2a1pre
backs outb6f09258a505f54e81d64221d35b096d68e7a844
Backed out changeset b6f09258a505 (bug 490833).
storage/public/mozIStorageStatement.idl
storage/src/mozStorageStatement.cpp
storage/src/mozStorageStatementParams.cpp
storage/test/unit/test_storage_statement.js
--- a/storage/public/mozIStorageStatement.idl
+++ b/storage/public/mozIStorageStatement.idl
@@ -36,20 +36,21 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 #include "mozIStorageValueArray.idl"
 
 interface mozIStorageConnection;
+interface nsISimpleEnumerator;
 interface mozIStorageStatementCallback;
 interface mozIStoragePendingStatement;
 
-[scriptable, uuid(52d740cd-1c25-471f-a848-98d1a00a2963)]
+[scriptable, uuid(471e161a-af46-4eb3-adf6-f6b0c41fe81c)]
 interface mozIStorageStatement : mozIStorageValueArray {
   /**
    * 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();
 
@@ -70,20 +71,18 @@ interface mozIStorageStatement : mozISto
   /**
    * Name of nth parameter, if given
    */
   AUTF8String getParameterName(in unsigned long aParamIndex);
 
   /**
    * Returns the index of the named parameter.
    *
-   * @param aName
-   *        The name of the parameter you want the index for.  This does not
-   *        include the leading ':'.
-   * @returns the index of the named parameter.
+   * @param aName The name of the parameter you want the index for.
+   * @return The index of the named parameter.
    */
   unsigned long getParameterIndex(in AUTF8String aName);
 
   /**
    * Number of columns returned
    */
   readonly attribute unsigned long columnCount;
 
--- a/storage/src/mozStorageStatement.cpp
+++ b/storage/src/mozStorageStatement.cpp
@@ -340,22 +340,18 @@ Statement::GetParameterName(PRUint32 aPa
 
 NS_IMETHODIMP
 Statement::GetParameterIndex(const nsACString &aName,
                              PRUint32 *_index)
 {
   if (!mDBStatement)
     return NS_ERROR_NOT_INITIALIZED;
 
-  // We do not accept any forms of names other than ":name", but we need to add
-  // the colon for SQLite.
-  nsCAutoString name(":");
-  name.Append(aName);
   int ind = ::sqlite3_bind_parameter_index(mDBStatement,
-                                           PromiseFlatCString(name).get());
+                                           PromiseFlatCString(aName).get());
   if (ind  == 0) // Named parameter not found.
     return NS_ERROR_INVALID_ARG;
 
   *_index = ind - 1; // SQLite indexes are 1-based, we are 0-based.
 
   return NS_OK;
 }
 
--- a/storage/src/mozStorageStatementParams.cpp
+++ b/storage/src/mozStorageStatementParams.cpp
@@ -86,18 +86,19 @@ StatementParams::SetProperty(nsIXPConnec
   if (JSVAL_IS_INT(aId)) {
     int idx = JSVAL_TO_INT(aId);
 
     PRBool res = JSValStorageStatementBinder(aCtx, mStatement, idx, *_vp);
     NS_ENSURE_TRUE(res, NS_ERROR_UNEXPECTED);
   }
   else if (JSVAL_IS_STRING(aId)) {
     JSString *str = JSVAL_TO_STRING(aId);
-    NS_ConvertUTF16toUTF8 name(::JS_GetStringChars(str),
-                               ::JS_GetStringLength(str));
+    nsCAutoString name(":");
+    name.Append(NS_ConvertUTF16toUTF8(::JS_GetStringChars(str),
+                                      ::JS_GetStringLength(str)));
 
     // check to see if there's a parameter with this name
     PRUint32 index;
     nsresult rv = mStatement->GetParameterIndex(name, &index);
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRBool res = JSValStorageStatementBinder(aCtx, mStatement, index, *_vp);
     NS_ENSURE_TRUE(res, NS_ERROR_UNEXPECTED);
@@ -200,19 +201,21 @@ StatementParams::NewResolve(nsIXPConnect
     if (idx >= mParamCount)
       return NS_ERROR_INVALID_ARG;
   }
   else if (JSVAL_IS_STRING(aId)) {
     JSString *str = JSVAL_TO_STRING(aId);
     jschar *nameChars = ::JS_GetStringChars(str);
     size_t nameLength = ::JS_GetStringLength(str);
 
+    nsCAutoString name(":");
+    name.Append(NS_ConvertUTF16toUTF8(nameChars, nameLength));
+
     // Check to see if there's a parameter with this name, and if not, let
     // the rest of the prototype chain be checked.
-    NS_ConvertUTF16toUTF8 name(nameChars, nameLength);
     nsresult rv = mStatement->GetParameterIndex(name, &idx);
     if (NS_FAILED(rv))
       return NS_OK;
 
     *_retval = ::JS_DefineUCProperty(aCtx, aScopeObj, nameChars, nameLength,
                                      JSVAL_VOID, nsnull, nsnull, 0);
     NS_ENSURE_TRUE(*_retval, NS_OK);
   }
--- a/storage/test/unit/test_storage_statement.js
+++ b/storage/test/unit/test_storage_statement.js
@@ -64,26 +64,26 @@ function test_getParameterName()
   do_check_eq(":id", stmt.getParameterName(0));
   stmt.reset();
   stmt.finalize();
 }
 
 function test_getParameterIndex_different()
 {
   var stmt = createStatement("SELECT * FROM test WHERE id = :id OR name = :name");
-  do_check_eq(0, stmt.getParameterIndex("id"));
-  do_check_eq(1, stmt.getParameterIndex("name"));
+  do_check_eq(0, stmt.getParameterIndex(":id"));
+  do_check_eq(1, stmt.getParameterIndex(":name"));
   stmt.reset();
   stmt.finalize();
 }
 
 function test_getParameterIndex_same()
 {
-  var stmt = createStatement("SELECT * FROM test WHERE id = :test OR name = :test");
-  do_check_eq(0, stmt.getParameterIndex("test"));
+  var stmt = createStatement("SELECT * FROM test WHERE id = @test OR name = @test");
+  do_check_eq(0, stmt.getParameterIndex("@test"));
   stmt.reset();
   stmt.finalize();
 }
 
 function test_columnCount()
 {
   var stmt = createStatement("SELECT * FROM test WHERE id = ?1 OR name = ?2");
   do_check_eq(2, stmt.columnCount);