Skip to content

Commit

Permalink
Switch to v2 statement API.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaering committed Aug 18, 2015
1 parent b041167 commit 40b349c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ PyObject* _pysqlite_connection_begin(pysqlite_Connection* self)
sqlite3_stmt* statement;

Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare(self->db, self->begin_statement, -1, &statement, &tail);
rc = sqlite3_prepare_v2(self->db, self->begin_statement, -1, &statement, &tail);
Py_END_ALLOW_THREADS

if (rc != SQLITE_OK) {
Expand Down Expand Up @@ -442,7 +442,7 @@ PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args)

if (self->inTransaction) {
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail);
rc = sqlite3_prepare_v2(self->db, "COMMIT", -1, &statement, &tail);
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
_pysqlite_seterror(self->db, NULL);
Expand Down Expand Up @@ -488,7 +488,7 @@ PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args
pysqlite_do_all_statements(self, ACTION_RESET, 1);

Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare(self->db, "ROLLBACK", -1, &statement, &tail);
rc = sqlite3_prepare_v2(self->db, "ROLLBACK", -1, &statement, &tail);
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
_pysqlite_seterror(self->db, NULL);
Expand Down
44 changes: 11 additions & 33 deletions src/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,41 +638,19 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
goto error;
}

/* Keep trying the SQL statement until the schema stops changing. */
while (1) {
/* Actually execute the SQL statement. */
rc = pysqlite_step(self->statement->st, self->connection);
if (rc == SQLITE_DONE || rc == SQLITE_ROW) {
/* If it worked, let's get out of the loop */
break;
}
/* Something went wrong. Re-set the statement and try again. */
rc = pysqlite_statement_reset(self->statement);
if (rc == SQLITE_SCHEMA) {
/* If this was a result of the schema changing, let's try
again. */
rc = pysqlite_statement_recompile(self->statement, parameters);
if (rc == SQLITE_OK) {
continue;
rc = pysqlite_step(self->statement->st, self->connection);
if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
if (PyErr_Occurred()) {
/* there was an error that occurred in a user-defined callback */
if (_enable_callback_tracebacks) {
PyErr_Print();
} else {
/* If the database gave us an error, promote it to Python. */
(void)pysqlite_statement_reset(self->statement);
_pysqlite_seterror(self->connection->db, NULL);
goto error;
PyErr_Clear();
}
} else {
if (PyErr_Occurred()) {
/* there was an error that occurred in a user-defined callback */
if (_enable_callback_tracebacks) {
PyErr_Print();
} else {
PyErr_Clear();
}
}
(void)pysqlite_statement_reset(self->statement);
_pysqlite_seterror(self->connection->db, NULL);
goto error;
}
(void)pysqlite_statement_reset(self->statement);
_pysqlite_seterror(self->connection->db, NULL);
goto error;
}

if (pysqlite_build_row_cast_map(self) != 0) {
Expand Down Expand Up @@ -823,7 +801,7 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)

while (1) {
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare(self->connection->db,
rc = sqlite3_prepare_v2(self->connection->db,
script_cstr,
-1,
&statement,
Expand Down
4 changes: 2 additions & 2 deletions src/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
sql_cstr = PyString_AsString(sql_str);

Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare(connection->db,
rc = sqlite3_prepare_v2(connection->db,
sql_cstr,
-1,
&self->st,
Expand Down Expand Up @@ -346,7 +346,7 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
sql_cstr = PyString_AsString(self->sql);

Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare(self->db,
rc = sqlite3_prepare_v2(self->db,
sql_cstr,
-1,
&new_st,
Expand Down

0 comments on commit 40b349c

Please sign in to comment.