summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-08-21 18:58:58 (GMT)
committerGitHub <noreply@github.com>2021-08-21 18:58:58 (GMT)
commit878e7267016ba25d05d8736349fb897c756f311d (patch)
tree1340cf1092e5dc7c91ef711acf641494e400b96c /Modules/_sqlite
parent4ceec495598e78f0776dd46d511dcc612a434dc3 (diff)
downloadcpython-878e7267016ba25d05d8736349fb897c756f311d.zip
cpython-878e7267016ba25d05d8736349fb897c756f311d.tar.gz
cpython-878e7267016ba25d05d8736349fb897c756f311d.tar.bz2
bpo-44965: Early exit for non-DML statements in sqlite3.Cursor.executemany() (GH-27865)
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/cursor.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 7308f30..e418caf 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -548,6 +548,13 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
goto error;
}
+ pysqlite_state *state = self->connection->state;
+ if (multiple && sqlite3_stmt_readonly(self->statement->st)) {
+ PyErr_SetString(state->ProgrammingError,
+ "executemany() can only execute DML statements.");
+ goto error;
+ }
+
if (self->statement->in_use) {
Py_SETREF(self->statement,
pysqlite_statement_create(self->connection, operation));
@@ -570,7 +577,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
}
}
- pysqlite_state *state = self->connection->state;
while (1) {
parameters = PyIter_Next(parameters_iter);
if (!parameters) {
@@ -653,13 +659,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
}
if (rc == SQLITE_ROW) {
- if (multiple) {
- PyErr_SetString(state->ProgrammingError,
- "executemany() can only execute DML "
- "statements.");
- goto error;
- }
-
self->next_row = _pysqlite_fetch_one_row(self);
if (self->next_row == NULL)
goto error;