[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executescript commits the transaction even if isolation_level = None #59

Closed
ghaering opened this issue Oct 14, 2013 · 1 comment
Closed

Comments

@ghaering
Copy link
Owner

From ikar...@gmail.com 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

@ghaering
Copy link
Owner Author

From ikar...@gmail.com on May 02, 2013 08:21:37

Oops, corrected a mistake in the comment:
when isolation_level is None, then connection->begin_statement == NULL

Attachment: patch.diff

@ghaering ghaering self-assigned this Jan 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant