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

This commit is contained in:
reed%reedloden.com 2007-11-13 08:26:46 +00:00
Родитель c706a7c8e3
Коммит 4b8d43fb2c
3 изменённых файлов: 44 добавлений и 2 удалений

Просмотреть файл

@ -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
*/

Просмотреть файл

@ -23,6 +23,7 @@
* Contributor(s):
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
* Shawn Wilsher <me@shawnwilsher.com>
* John Zhang <jzhang@aptana.com>
*
* 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;
}

Просмотреть файл

@ -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()
{