mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
gh-92206: Improve scoping of sqlite3 reset statement helper (#92241)
This commit is contained in:
parent
d5dfcd4489
commit
415944379f
3 changed files with 28 additions and 30 deletions
|
@ -101,6 +101,24 @@ pysqlite_cursor_init_impl(pysqlite_Cursor *self,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
stmt_reset(pysqlite_Statement *self)
|
||||||
|
{
|
||||||
|
int rc = SQLITE_OK;
|
||||||
|
|
||||||
|
if (self->in_use && self->st) {
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
rc = sqlite3_reset(self->st);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
|
if (rc == SQLITE_OK) {
|
||||||
|
self->in_use = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cursor_traverse(pysqlite_Cursor *self, visitproc visit, void *arg)
|
cursor_traverse(pysqlite_Cursor *self, visitproc visit, void *arg)
|
||||||
{
|
{
|
||||||
|
@ -124,7 +142,7 @@ cursor_clear(pysqlite_Cursor *self)
|
||||||
Py_CLEAR(self->row_factory);
|
Py_CLEAR(self->row_factory);
|
||||||
if (self->statement) {
|
if (self->statement) {
|
||||||
/* Reset the statement if the user has not closed the cursor */
|
/* Reset the statement if the user has not closed the cursor */
|
||||||
pysqlite_statement_reset(self->statement);
|
stmt_reset(self->statement);
|
||||||
Py_CLEAR(self->statement);
|
Py_CLEAR(self->statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,7 +562,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
|
||||||
|
|
||||||
if (self->statement != NULL) {
|
if (self->statement != NULL) {
|
||||||
/* There is an active statement */
|
/* There is an active statement */
|
||||||
pysqlite_statement_reset(self->statement);
|
stmt_reset(self->statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reset description and rowcount */
|
/* reset description and rowcount */
|
||||||
|
@ -553,7 +571,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
|
||||||
self->rowcount = 0L;
|
self->rowcount = 0L;
|
||||||
|
|
||||||
if (self->statement) {
|
if (self->statement) {
|
||||||
(void)pysqlite_statement_reset(self->statement);
|
(void)stmt_reset(self->statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *stmt = get_statement_from_cache(self, operation);
|
PyObject *stmt = get_statement_from_cache(self, operation);
|
||||||
|
@ -577,7 +595,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pysqlite_statement_reset(self->statement);
|
stmt_reset(self->statement);
|
||||||
pysqlite_statement_mark_dirty(self->statement);
|
pysqlite_statement_mark_dirty(self->statement);
|
||||||
|
|
||||||
/* We start a transaction implicitly before a DML statement.
|
/* We start a transaction implicitly before a DML statement.
|
||||||
|
@ -614,7 +632,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(void)pysqlite_statement_reset(self->statement);
|
(void)stmt_reset(self->statement);
|
||||||
_pysqlite_seterror(state, self->connection->db);
|
_pysqlite_seterror(state, self->connection->db);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -663,12 +681,12 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc == SQLITE_DONE && !multiple) {
|
if (rc == SQLITE_DONE && !multiple) {
|
||||||
pysqlite_statement_reset(self->statement);
|
stmt_reset(self->statement);
|
||||||
Py_CLEAR(self->statement);
|
Py_CLEAR(self->statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (multiple) {
|
if (multiple) {
|
||||||
pysqlite_statement_reset(self->statement);
|
stmt_reset(self->statement);
|
||||||
}
|
}
|
||||||
Py_XDECREF(parameters);
|
Py_XDECREF(parameters);
|
||||||
}
|
}
|
||||||
|
@ -824,7 +842,7 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
|
||||||
sqlite3_stmt *stmt = self->statement->st;
|
sqlite3_stmt *stmt = self->statement->st;
|
||||||
assert(stmt != NULL);
|
assert(stmt != NULL);
|
||||||
if (sqlite3_data_count(stmt) == 0) {
|
if (sqlite3_data_count(stmt) == 0) {
|
||||||
(void)pysqlite_statement_reset(self->statement);
|
(void)stmt_reset(self->statement);
|
||||||
Py_CLEAR(self->statement);
|
Py_CLEAR(self->statement);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -835,7 +853,7 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
|
||||||
}
|
}
|
||||||
int rc = stmt_step(stmt);
|
int rc = stmt_step(stmt);
|
||||||
if (rc == SQLITE_DONE) {
|
if (rc == SQLITE_DONE) {
|
||||||
(void)pysqlite_statement_reset(self->statement);
|
(void)stmt_reset(self->statement);
|
||||||
}
|
}
|
||||||
else if (rc != SQLITE_ROW) {
|
else if (rc != SQLITE_ROW) {
|
||||||
(void)_pysqlite_seterror(self->connection->state,
|
(void)_pysqlite_seterror(self->connection->state,
|
||||||
|
@ -1005,7 +1023,7 @@ pysqlite_cursor_close_impl(pysqlite_Cursor *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->statement) {
|
if (self->statement) {
|
||||||
(void)pysqlite_statement_reset(self->statement);
|
(void)stmt_reset(self->statement);
|
||||||
Py_CLEAR(self->statement);
|
Py_CLEAR(self->statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -366,25 +366,6 @@ pysqlite_statement_bind_parameters(pysqlite_state *state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int pysqlite_statement_reset(pysqlite_Statement* self)
|
|
||||||
{
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = SQLITE_OK;
|
|
||||||
|
|
||||||
if (self->in_use && self->st) {
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
|
||||||
rc = sqlite3_reset(self->st);
|
|
||||||
Py_END_ALLOW_THREADS
|
|
||||||
|
|
||||||
if (rc == SQLITE_OK) {
|
|
||||||
self->in_use = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
|
void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
|
||||||
{
|
{
|
||||||
self->in_use = 1;
|
self->in_use = 1;
|
||||||
|
|
|
@ -44,7 +44,6 @@ void pysqlite_statement_bind_parameters(pysqlite_state *state,
|
||||||
pysqlite_Statement *self,
|
pysqlite_Statement *self,
|
||||||
PyObject *parameters);
|
PyObject *parameters);
|
||||||
|
|
||||||
int pysqlite_statement_reset(pysqlite_Statement* self);
|
|
||||||
void pysqlite_statement_mark_dirty(pysqlite_Statement* self);
|
void pysqlite_statement_mark_dirty(pysqlite_Statement* self);
|
||||||
|
|
||||||
int pysqlite_statement_setup_types(PyObject *module);
|
int pysqlite_statement_setup_types(PyObject *module);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue