Bug 552092 - Expose a length property on mozIStorageBindingParamsArray
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Mon, 15 Mar 2010 10:23:39 -0700
changeset 39461 cbf4b59a607dd0236a5c2aafa76a3d42efe549cf
parent 39460 1df18e6b6e7858d39428a2a4e287d62c923e3594
child 39462 3c689de8ee14bb296b52018cedad6efabc932350
push idunknown
push userunknown
push dateunknown
bugs552092
milestone1.9.3a4pre
Bug 552092 - Expose a length property on mozIStorageBindingParamsArray Expose the length so that consumers don't have to track if they added anything to the array themselves. r=asuth sr=rob_strong
storage/public/mozIStorageBindingParamsArray.idl
storage/src/mozStorageBindingParamsArray.cpp
storage/test/unit/test_statement_executeAsync.js
--- a/storage/public/mozIStorageBindingParamsArray.idl
+++ b/storage/public/mozIStorageBindingParamsArray.idl
@@ -36,27 +36,32 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 interface mozIStorageBindingParams;
 
-[scriptable, uuid(e676e1a3-1dc6-4802-ac03-291fa9de7f93)]
+[scriptable, uuid(67eea5c3-4881-41ff-b0fe-09f2356aeadb)]
 interface mozIStorageBindingParamsArray : nsISupports {
   /**
    * Creates a new mozIStorageBindingParams object that can be added to this
    * array.
    *
-   * @returns a mozIStorageBindingParams object that can be used to specify
-   *          parameters that need to be bound.
+   * @return a mozIStorageBindingParams object that can be used to specify
+   *         parameters that need to be bound.
    */
   mozIStorageBindingParams newBindingParams();
 
   /**
    * Adds the parameters to the end of this array.
    *
    * @param aParameters
    *        The parameters to add to this array.
    */
   void addParams(in mozIStorageBindingParams aParameters);
+
+  /**
+   * The number of mozIStorageBindingParams this object contains.
+   */
+  readonly attribute unsigned long length;
 };
--- a/storage/src/mozStorageBindingParamsArray.cpp
+++ b/storage/src/mozStorageBindingParamsArray.cpp
@@ -104,10 +104,17 @@ BindingParamsArray::AddParams(mozIStorag
   NS_ENSURE_TRUE(mArray.AppendElement(params), NS_ERROR_OUT_OF_MEMORY);
 
   // Lock the parameters only after we've successfully added them.
   params->lock();
 
   return NS_OK;
 }
 
+NS_IMETHODIMP
+BindingParamsArray::GetLength(PRUint32 *_length)
+{
+  *_length = length();
+  return NS_OK;
+}
+
 } // namespace storage
 } // namespace mozilla
--- a/storage/test/unit/test_statement_executeAsync.js
+++ b/storage/test/unit/test_statement_executeAsync.js
@@ -515,16 +515,17 @@ function test_bind_multiple_rows_by_inde
   for (let i = 0; i < AMOUNT_TO_ADD; i++) {
     let bp = array.newBindingParams();
     bp.bindByIndex(0, INTEGER);
     bp.bindByIndex(1, TEXT);
     bp.bindByIndex(2, REAL);
     bp.bindByIndex(3, null);
     bp.bindBlobByIndex(4, BLOB, BLOB.length);
     array.addParams(bp);
+    do_check_eq(array.length, i + 1);
   }
   stmt.bindParameters(array);
 
   // Get our current number of rows in the table.
   var currentRows = 0;
   var countStmt = getOpenedDatabase().createStatement(
     "SELECT COUNT(1) AS count FROM test"
   );
@@ -584,16 +585,17 @@ function test_bind_multiple_rows_by_name
   for (let i = 0; i < AMOUNT_TO_ADD; i++) {
     let bp = array.newBindingParams();
     bp.bindByName("int", INTEGER);
     bp.bindByName("text", TEXT);
     bp.bindByName("real", REAL);
     bp.bindByName("null", null);
     bp.bindBlobByName("blob", BLOB, BLOB.length);
     array.addParams(bp);
+    do_check_eq(array.length, i + 1);
   }
   stmt.bindParameters(array);
 
   // Get our current number of rows in the table.
   var currentRows = 0;
   var countStmt = getOpenedDatabase().createStatement(
     "SELECT COUNT(1) AS count FROM test"
   );