Author: Amaury Forgeot d'Arc <[email protected]>
Branch:
Changeset: r58719:afc480fa7162
Date: 2012-11-04 17:03 +0100
http://bitbucket.org/pypy/pypy/changeset/afc480fa7162/
Log: Issue1313: When sqlite cursor is an insert statement, list(cursor)
would execute it twice :-(
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -784,6 +784,9 @@
self.statement.reset()
raise self.connection._get_exception(ret)
+ if self.statement.kind == DML:
+ self.statement.reset()
+
if self.statement.kind == DQL and ret == SQLITE_ROW:
self.statement._build_row_cast_map()
self.statement._readahead(self)
@@ -791,9 +794,6 @@
self.statement.item = None
self.statement.exhausted = True
- if self.statement.kind == DML:
- self.statement.reset()
-
self.rowcount = -1
if self.statement.kind == DML:
self.rowcount = sqlite.sqlite3_changes(self.connection.db)
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py
b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -8,3 +8,9 @@
cursor.execute('CREATE TABLE foo (bar INTEGER)')
result = list(cursor)
assert result == []
+ cursor.execute('INSERT INTO foo (bar) VALUES (42)')
+ result = list(cursor)
+ assert result == []
+ cursor.execute('SELECT * FROM foo')
+ result = list(cursor)
+ assert result == [(42,)]
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit