summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/cursor.c
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2017-02-26 15:22:38 (GMT)
committerGitHub <noreply@github.com>2017-02-26 15:22:38 (GMT)
commit4a926caf8e5fd8af771b2c34bfb6e91c732331fe (patch)
treebddaa3a91ef435b1b18716b8385a6415c55fbd13 /Modules/_sqlite/cursor.c
parent46ce7599af82a929506baeaaee5c149970440c4c (diff)
downloadcpython-4a926caf8e5fd8af771b2c34bfb6e91c732331fe.zip
cpython-4a926caf8e5fd8af771b2c34bfb6e91c732331fe.tar.gz
cpython-4a926caf8e5fd8af771b2c34bfb6e91c732331fe.tar.bz2
bpo-28518: Start a transaction implicitly before a DML statement (#245)
Patch by Aviv Palivoda.
Diffstat (limited to 'Modules/_sqlite/cursor.c')
-rw-r--r--Modules/_sqlite/cursor.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 39f7a65..8341fb8 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -511,10 +511,9 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
pysqlite_statement_reset(self->statement);
pysqlite_statement_mark_dirty(self->statement);
- /* For backwards compatibility reasons, do not start a transaction if a
- DDL statement is encountered. If anybody wants transactional DDL,
- they can issue a BEGIN statement manually. */
- if (self->connection->begin_statement && !sqlite3_stmt_readonly(self->statement->st) && !self->statement->is_ddl) {
+ /* We start a transaction implicitly before a DML statement.
+ SELECT is the only exception. See #9924. */
+ if (self->connection->begin_statement && self->statement->is_dml) {
if (sqlite3_get_autocommit(self->connection->db)) {
result = _pysqlite_connection_begin(self->connection);
if (!result) {
@@ -609,7 +608,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
}
}
- if (!sqlite3_stmt_readonly(self->statement->st)) {
+ if (self->statement->is_dml) {
self->rowcount += (long)sqlite3_changes(self->connection->db);
} else {
self->rowcount= -1L;