]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44965: Early exit for non-DML statements in sqlite3.Cursor.executemany() (GH...
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Sat, 21 Aug 2021 18:58:58 +0000 (20:58 +0200)
committerGitHub <noreply@github.com>
Sat, 21 Aug 2021 18:58:58 +0000 (19:58 +0100)
Modules/_sqlite/cursor.c

index 7308f3062da4b99aca8295b714ad7c9986bd3a65..e418cafb4feb602512798d28684bb9aeb46fb6a9 100644 (file)
@@ -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;