Skip to content

executescript commits the transaction even if isolation_level = None #59

@ghaering

Description

@ghaering

From [email protected] on May 02, 2013 17:16:47

The following script should print "My precious data is here.", but it raises an exception instead...
I think pysqlite should not implicitly mess with transactions in "autocommit" mode (when isolation_level = None).

My proposed patch corrects the problem.

BEGIN

import pysqlite2.dbapi2 as sqlite3

import sqlite3

con = sqlite3.connect(':memory:')
con.isolation_level = None
cur = con.cursor()

cur.execute('create table test(t text)')
cur.execute('insert into test(t) values(?)', ('My precious data is here.',))

after the next command, inTransaction will be 1,

because of the following line in cursor.c, (line 762):

self->connection->inTransaction =

!sqlite3_get_autocommit(self->connection->db);

cur.execute('begin')

cur.execute('drop table test')

Now issue an arbitrary dummy command using executescript.

executescript implicitly calls pysqlite_connection_commit.

Since inTransaction == 1, this will actually commit the transaction.

cur.executescript('select 2+3')

There is no way to roll back.

cur.execute('rollback')

for x in cur.execute('select t from test'):
print(x[0])

cur.close()
con.close()

END

Attachment: patch.diff test.py

Original issue: http://code.google.com/p/pysqlite/issues/detail?id=59

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions