diff --git a/mozilla/storage/public/mozIStorageStatement.idl b/mozilla/storage/public/mozIStorageStatement.idl index a53f062e6fa..12f7d7b54fc 100644 --- a/mozilla/storage/public/mozIStorageStatement.idl +++ b/mozilla/storage/public/mozIStorageStatement.idl @@ -45,7 +45,7 @@ interface nsISimpleEnumerator; [ptr] native sqlite3stmtptr(struct sqlite3_stmt); -[scriptable, uuid(1a95a6ec-e4b0-4d0b-947b-d2f40b04d057)] +[scriptable, uuid(42fad13e-c67d-4b2c-bd61-2c5b17186772)] interface mozIStorageStatement : mozIStorageValueArray { /** * Initialize this query with the given SQL statement. @@ -106,6 +106,15 @@ interface mozIStorageStatement : mozIStorageValueArray { */ unsigned long getColumnIndex(in AUTF8String aName); + /** + * Obtains the declared column type of a prepared statement. + * + * @param aParamIndex The zero-based index of the column who's declared type + * we are interested in. + * @returns the declared index type. + */ + AUTF8String getColumnDecltype(in unsigned long aParamIndex); + /** * Reset parameters/statement execution */ diff --git a/mozilla/storage/src/mozStorageStatement.cpp b/mozilla/storage/src/mozStorageStatement.cpp index 6c5b8fff2b6..12e71814939 100644 --- a/mozilla/storage/src/mozStorageStatement.cpp +++ b/mozilla/storage/src/mozStorageStatement.cpp @@ -23,6 +23,7 @@ * Contributor(s): * Vladimir Vukicevic * Shawn Wilsher + * John Zhang * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -805,3 +806,20 @@ mozStorageStatement::EscapeStringForLIKE(const nsAString & aValue, } return NS_OK; } + +/* AString getColumnDecltype(in unsigned long aParamIndex); */ +NS_IMETHODIMP +mozStorageStatement::GetColumnDecltype(PRUint32 aParamIndex, + nsACString& aDeclType) +{ + if (!mDBConnection || !mDBStatement) + return NS_ERROR_NOT_INITIALIZED; + + if (aParamIndex < 0 || aParamIndex >= mResultColumnCount) + return NS_ERROR_ILLEGAL_VALUE; + + const char *declType = sqlite3_column_decltype(mDBStatement, aParamIndex); + aDeclType.Assign(declType); + + return NS_OK; +} diff --git a/mozilla/storage/test/unit/test_storage_statement.js b/mozilla/storage/test/unit/test_storage_statement.js index 651c7137fde..a1b16f67a10 100644 --- a/mozilla/storage/test/unit/test_storage_statement.js +++ b/mozilla/storage/test/unit/test_storage_statement.js @@ -163,12 +163,27 @@ function test_state_after_finalize() do_check_eq(Ci.mozIStorageStatement.MOZ_STORAGE_STATEMENT_INVALID, stmt.state); } +function test_getColumnDecltype() +{ + var stmt = createStatement("SELECT name, id FROM test"); + do_check_eq("TEXT", stmt.getColumnDecltype(0)); + do_check_eq("INTEGER", stmt.getColumnDecltype(1)); + try { + do_check_eq("GARBAGE", stmt.getColumnDecltype(2)); + do_throw("should not get here"); + } catch (e) { + do_check_eq(Cr.NS_ERROR_ILLEGAL_VALUE, e.result); + } + stmt.finalize(); +} + var tests = [test_parameterCount_none, test_parameterCount_one, test_getParameterName, test_getParameterIndex_different, test_getParameterIndex_same, test_columnCount, test_getColumnName, test_getColumnIndex_same_case, test_getColumnIndex_different_case, test_state_ready, - test_state_executing, test_state_after_finalize]; + test_state_executing, test_state_after_finalize, + test_getColumnDecltype]; function run_test() {