B2G/gecko/storage/test/unit/head_storage.js
/**
 * Run a query synchronously and verify that we get back the expected results.
 *
 * @param aSQLString
 *        The SQL string for the query.
 * @param aBind
 *        The value to bind at index 0.
 * @param aResults
 *        A list of the expected values returned in the sole result row.
 *        Express blobs as lists.
 */
Run a query synchronously and verify that we get back the expected results.
@param aSQLString
The SQL string for the query.
@param aBind
The value to bind at index 0.
@param aResults
A list of the expected values returned in the sole result row.
Express blobs as lists.
Run a query synchronously and verify that we get back the expected results . @param aSQLString The SQL string for the query . @param aBind The value to bind at index 0 . @param aResults A list of the expected values returned in the sole result row . Express blobs as lists .
function verifyQuery(aSQLString, aBind, aResults)
{
  let stmt = getOpenedDatabase().createStatement(aSQLString);
  stmt.bindByIndex(0, aBind);
  try {
    do_check_true(stmt.executeStep());
    let nCols = stmt.numEntries;
    if (aResults.length != nCols)
      do_throw("Expected " + aResults.length + " columns in result but " +
               "there are only " + aResults.length + "!");
    for (let iCol = 0; iCol < nCols; iCol++) {
      let expectedVal = aResults[iCol];
      let valType = stmt.getTypeOfIndex(iCol);
      if (expectedVal === null) {
        do_check_eq(stmt.VALUE_TYPE_NULL, valType);
        do_check_true(stmt.getIsNull(iCol));
      }
      else if (typeof(expectedVal) == "number") {
        if (Math.floor(expectedVal) == expectedVal) {
          do_check_eq(stmt.VALUE_TYPE_INTEGER, valType);
          do_check_eq(expectedVal, stmt.getInt32(iCol));
        }
        else {
          do_check_eq(stmt.VALUE_TYPE_FLOAT, valType);
          do_check_eq(expectedVal, stmt.getDouble(iCol));
        }
      }
      else if (typeof(expectedVal) == "string") {
        do_check_eq(stmt.VALUE_TYPE_TEXT, valType);
        do_check_eq(expectedVal, stmt.getUTF8String(iCol));
      }
      else { 
        do_check_eq(stmt.VALUE_TYPE_BLOB, valType);
        let count = { value: 0 }, blob = { value: null };
        stmt.getBlob(iCol, count, blob);
        do_check_eq(count.value, expectedVal.length);
        for (let i = 0; i < count.value; i++) {
          do_check_eq(expectedVal[i], blob.value[i]);
        }
      }
    }
  }
  finally {
    stmt.finalize();
  }
}
function verifyQuery ( aSQLString , aBind , aResults ) { let stmt = getOpenedDatabase ( ) . createStatement ( aSQLString ) ; stmt . bindByIndex ( 0 , aBind ) ; try { do_check_true ( stmt . executeStep ( ) ) ; let nCols = stmt . numEntries ; if ( aResults . length != nCols ) do_throw ( "Expected " + aResults . length + " columns in result but " + "there are only " + aResults . length + "!" ) ; for ( let iCol = 0 ; iCol < nCols ; iCol ++ ) { let expectedVal = aResults [ iCol ] ; let valType = stmt . getTypeOfIndex ( iCol ) ; if ( expectedVal === null ) { do_check_eq ( stmt . VALUE_TYPE_NULL , valType ) ; do_check_true ( stmt . getIsNull ( iCol ) ) ; } else if ( typeof ( expectedVal ) == "number" ) { if ( Math . floor ( expectedVal ) == expectedVal ) { do_check_eq ( stmt . VALUE_TYPE_INTEGER , valType ) ; do_check_eq ( expectedVal , stmt . getInt32 ( iCol ) ) ; } else { do_check_eq ( stmt . VALUE_TYPE_FLOAT , valType ) ; do_check_eq ( expectedVal , stmt . getDouble ( iCol ) ) ; } } else if ( typeof ( expectedVal ) == "string" ) { do_check_eq ( stmt . VALUE_TYPE_TEXT , valType ) ; do_check_eq ( expectedVal , stmt . getUTF8String ( iCol ) ) ; } else { do_check_eq ( stmt . VALUE_TYPE_BLOB , valType ) ; let count = { value : 0 } , blob = { value : null } ; stmt . getBlob ( iCol , count , blob ) ; do_check_eq ( count . value , expectedVal . length ) ; for ( let i = 0 ; i < count . value ; i ++ ) { do_check_eq ( expectedVal [ i ] , blob . value [ i ] ) ; } } } } finally { stmt . finalize ( ) ; } }
Run a query synchronously and verify that we get back the expected results.
Run a query synchronously and verify that we get back the expected results .
// blob