diff options
author | Benjamin Peterson <benjamin@python.org> | 2017-09-20 14:36:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-20 14:36:18 (GMT) |
commit | 525269430a3f9fbb7287e4bb6b365ac216004980 (patch) | |
tree | 2d773b5d8ee8582da1b90bcbd17bb3ffc9ce25f7 /Modules/_sqlite/cursor.c | |
parent | 0ad05c32cc41d4c21bfd78b9ffead519ead475a2 (diff) | |
download | cpython-525269430a3f9fbb7287e4bb6b365ac216004980.zip cpython-525269430a3f9fbb7287e4bb6b365ac216004980.tar.gz cpython-525269430a3f9fbb7287e4bb6b365ac216004980.tar.bz2 |
closes bpo-31525: require sqlite3_prepare_v2 (#3666)
This is based on
https://github.com/ghaering/pysqlite/commit/40b349cadbd87c42f70fc92e5e1aee6d02564c6d#diff-0489411409cd2934730e88bf7767790,
though we can be a bit more aggressive about deleting code.
Diffstat (limited to 'Modules/_sqlite/cursor.c')
-rw-r--r-- | Modules/_sqlite/cursor.c | 97 |
1 files changed, 34 insertions, 63 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index ba6e52d..cfe2627 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -536,47 +536,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); + rc = pysqlite_step(self->statement->st, self->connection); + if (rc != SQLITE_DONE && rc != SQLITE_ROW) { if (PyErr_Occurred()) { - (void)pysqlite_statement_reset(self->statement); - goto error; - } - if (rc == SQLITE_DONE || rc == SQLITE_ROW) { - /* If it worked, let's get out of the loop */ - break; - } -#if SQLITE_VERSION_NUMBER < 3003009 - /* Something went wrong. Re-set the statement and try again. */ - rc = pysqlite_statement_reset(self->statement); -#endif - 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; + /* 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; - } - } else { - if (PyErr_Occurred()) { - /* there was an error that occurred in a user-defined callback */ - if (_enable_callback_tracebacks) { - PyErr_Print(); - } else { - PyErr_Clear(); - } + 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) { @@ -584,29 +556,28 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* goto error; } - if (rc == SQLITE_ROW || rc == SQLITE_DONE) { - Py_BEGIN_ALLOW_THREADS - numcols = sqlite3_column_count(self->statement->st); - Py_END_ALLOW_THREADS - if (self->description == Py_None && numcols > 0) { - Py_SETREF(self->description, PyTuple_New(numcols)); - if (!self->description) { + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); + Py_BEGIN_ALLOW_THREADS + numcols = sqlite3_column_count(self->statement->st); + Py_END_ALLOW_THREADS + if (self->description == Py_None && numcols > 0) { + Py_SETREF(self->description, PyTuple_New(numcols)); + if (!self->description) { + goto error; + } + for (i = 0; i < numcols; i++) { + descriptor = PyTuple_New(7); + if (!descriptor) { goto error; } - for (i = 0; i < numcols; i++) { - descriptor = PyTuple_New(7); - if (!descriptor) { - goto error; - } - PyTuple_SetItem(descriptor, 0, _pysqlite_build_column_name(sqlite3_column_name(self->statement->st, i))); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 1, Py_None); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 2, Py_None); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 3, Py_None); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 4, Py_None); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 5, Py_None); - Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 6, Py_None); - PyTuple_SetItem(self->description, i, descriptor); - } + PyTuple_SetItem(descriptor, 0, _pysqlite_build_column_name(sqlite3_column_name(self->statement->st, i))); + Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 1, Py_None); + Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 2, Py_None); + Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 3, Py_None); + Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 4, Py_None); + Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 5, Py_None); + Py_INCREF(Py_None); PyTuple_SetItem(descriptor, 6, Py_None); + PyTuple_SetItem(self->description, i, descriptor); } } @@ -708,11 +679,11 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args) while (1) { Py_BEGIN_ALLOW_THREADS - rc = SQLITE3_PREPARE(self->connection->db, - script_cstr, - -1, - &statement, - &script_cstr); + rc = sqlite3_prepare_v2(self->connection->db, + script_cstr, + -1, + &statement, + &script_cstr); Py_END_ALLOW_THREADS if (rc != SQLITE_OK) { _pysqlite_seterror(self->connection->db, NULL); |