Skip to content

Commit 878e726

Browse files
author
Erlend Egeberg Aasland
authored
bpo-44965: Early exit for non-DML statements in sqlite3.Cursor.executemany() (GH-27865)
1 parent 4ceec49 commit 878e726

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Modules/_sqlite/cursor.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,13 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
548548
goto error;
549549
}
550550

551+
pysqlite_state *state = self->connection->state;
552+
if (multiple && sqlite3_stmt_readonly(self->statement->st)) {
553+
PyErr_SetString(state->ProgrammingError,
554+
"executemany() can only execute DML statements.");
555+
goto error;
556+
}
557+
551558
if (self->statement->in_use) {
552559
Py_SETREF(self->statement,
553560
pysqlite_statement_create(self->connection, operation));
@@ -570,7 +577,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
570577
}
571578
}
572579

573-
pysqlite_state *state = self->connection->state;
574580
while (1) {
575581
parameters = PyIter_Next(parameters_iter);
576582
if (!parameters) {
@@ -653,13 +659,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
653659
}
654660

655661
if (rc == SQLITE_ROW) {
656-
if (multiple) {
657-
PyErr_SetString(state->ProgrammingError,
658-
"executemany() can only execute DML "
659-
"statements.");
660-
goto error;
661-
}
662-
663662
self->next_row = _pysqlite_fetch_one_row(self);
664663
if (self->next_row == NULL)
665664
goto error;

0 commit comments

Comments
 (0)