Bug 403068 - "Need a wrapper function for SQLite function sqlite3_column_decltype" [p=jzhang@aptana.com (john Zhang) r=sdwilsh a1.9=damons]

git-svn-id: svn://10.0.0.236/trunk@239290 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
reed%reedloden.com 2007-11-13 08:26:46 +00:00
parent 41502a32b2
commit a986b0e9b8
3 changed files with 44 additions and 2 deletions

View File

@ -45,7 +45,7 @@ interface nsISimpleEnumerator;
[ptr] native sqlite3stmtptr(struct sqlite3_stmt); [ptr] native sqlite3stmtptr(struct sqlite3_stmt);
[scriptable, uuid(1a95a6ec-e4b0-4d0b-947b-d2f40b04d057)] [scriptable, uuid(42fad13e-c67d-4b2c-bd61-2c5b17186772)]
interface mozIStorageStatement : mozIStorageValueArray { interface mozIStorageStatement : mozIStorageValueArray {
/** /**
* Initialize this query with the given SQL statement. * Initialize this query with the given SQL statement.
@ -106,6 +106,15 @@ interface mozIStorageStatement : mozIStorageValueArray {
*/ */
unsigned long getColumnIndex(in AUTF8String aName); 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 * Reset parameters/statement execution
*/ */

View File

@ -23,6 +23,7 @@
* Contributor(s): * Contributor(s):
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com> * Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
* Shawn Wilsher <me@shawnwilsher.com> * Shawn Wilsher <me@shawnwilsher.com>
* John Zhang <jzhang@aptana.com>
* *
* Alternatively, the contents of this file may be used under the terms of * 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 * 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; 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;
}

View File

@ -163,12 +163,27 @@ function test_state_after_finalize()
do_check_eq(Ci.mozIStorageStatement.MOZ_STORAGE_STATEMENT_INVALID, stmt.state); 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, var tests = [test_parameterCount_none, test_parameterCount_one,
test_getParameterName, test_getParameterIndex_different, test_getParameterName, test_getParameterIndex_different,
test_getParameterIndex_same, test_columnCount, test_getParameterIndex_same, test_columnCount,
test_getColumnName, test_getColumnIndex_same_case, test_getColumnName, test_getColumnIndex_same_case,
test_getColumnIndex_different_case, test_state_ready, 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() function run_test()
{ {