Bug 570529: mozIStorageStatement.execute() should reset itself even if an error occurs. r=sdwilsh

This commit is contained in:
Dave Townsend 2010-06-07 15:06:56 -07:00
parent 5a2fdda45e
commit 0383c618f7
2 changed files with 26 additions and 3 deletions

View File

@ -581,9 +581,9 @@ Statement::Execute()
PRBool ret;
nsresult rv = ExecuteStep(&ret);
NS_ENSURE_SUCCESS(rv, rv);
nsresult rv2 = Reset();
return Reset();
return NS_FAILED(rv) ? rv : rv2;
}
NS_IMETHODIMP

View File

@ -177,13 +177,36 @@ function test_getColumnDecltype()
stmt.finalize();
}
function test_failed_execute()
{
var stmt = createStatement("INSERT INTO test (name) VALUES ('foo')");
stmt.execute();
stmt.finalize();
var id = getOpenedDatabase().lastInsertRowID;
stmt = createStatement("INSERT INTO test(id, name) VALUES(:id, 'bar')");
stmt.params.id = id;
try {
// Should throw a constraint error
stmt.execute();
do_throw("Should have seen a constraint error");
}
catch (e) {
do_check_eq(getOpenedDatabase().lastError, Ci.mozIStorageError.CONSTRAINT);
}
do_check_eq(Ci.mozIStorageStatement.MOZ_STORAGE_STATEMENT_READY, stmt.state);
// Should succeed without needing to reset the statement manually
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_getColumnDecltype];
test_getColumnDecltype,
test_failed_execute,
];
function run_test()
{