diff -r 71c4b5dd82bb -r e490414a391d dbd/sqlite3/statement.c --- a/dbd/sqlite3/statement.c Sun Jul 18 03:42:30 2010 +0000 +++ b/dbd/sqlite3/statement.c Mon Dec 20 09:01:12 2010 +0000 @@ -1,5 +1,8 @@ #include "dbd_sqlite3.h" +extern int try_begin_transaction(connection_t *conn); +extern int try_end_transaction(connection_t *conn); + /* * Converts SQLite types to Lua types */ @@ -128,10 +131,12 @@ */ if (sqlite3_reset(statement->stmt) != SQLITE_OK) { lua_pushboolean(L, 0); - lua_pushfstring(L, DBI_ERR_EXECUTE_FAILED, sqlite3_errmsg(statement->sqlite)); + lua_pushfstring(L, DBI_ERR_EXECUTE_FAILED, sqlite3_errmsg(statement->conn->sqlite)); return 2; } + sqlite3_clear_bindings(statement->stmt); + expected_params = sqlite3_bind_parameter_count(statement->stmt); if (expected_params != num_bind_params) { /* @@ -180,18 +185,20 @@ if (errstr) lua_pushfstring(L, DBI_ERR_BINDING_PARAMS, errstr); else - lua_pushfstring(L, DBI_ERR_BINDING_PARAMS, sqlite3_errmsg(statement->sqlite)); + lua_pushfstring(L, DBI_ERR_BINDING_PARAMS, sqlite3_errmsg(statement->conn->sqlite)); + + return 2; + } + try_begin_transaction(statement->conn); + + if (!step(statement)) { + lua_pushboolean(L, 0); + lua_pushfstring(L, DBI_ERR_EXECUTE_FAILED, sqlite3_errmsg(statement->conn->sqlite)); return 2; } - if (!step(statement)) { - lua_pushboolean(L, 0); - lua_pushfstring(L, DBI_ERR_EXECUTE_FAILED, sqlite3_errmsg(statement->sqlite)); - return 2; - } - - statement->affected = sqlite3_changes(statement->sqlite); + statement->affected = sqlite3_changes(statement->conn->sqlite); lua_pushboolean(L, 1); return 1; @@ -283,7 +290,7 @@ /* * reset needs to be called to retrieve the 'real' error message */ - luaL_error(L, DBI_ERR_FETCH_FAILED, sqlite3_errmsg(statement->sqlite)); + luaL_error(L, DBI_ERR_FETCH_FAILED, sqlite3_errmsg(statement->conn->sqlite)); } } @@ -357,14 +364,14 @@ statement_t *statement = NULL; statement = (statement_t *)lua_newuserdata(L, sizeof(statement_t)); - statement->sqlite = conn->sqlite; + statement->conn = conn; statement->stmt = NULL; statement->more_data = 0; statement->affected = 0; - if (sqlite3_prepare_v2(statement->sqlite, sql_query, strlen(sql_query), &statement->stmt, NULL) != SQLITE_OK) { + if (sqlite3_prepare_v2(statement->conn->sqlite, sql_query, strlen(sql_query), &statement->stmt, NULL) != SQLITE_OK) { lua_pushnil(L); - lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, sqlite3_errmsg(statement->sqlite)); + lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, sqlite3_errmsg(statement->conn->sqlite)); return 2; }