Author: Brian Kearns <bdkea...@gmail.com>
Branch: py3k
Changeset: r62121:6c374f053724
Date: 2013-03-06 02:16 -0500
http://bitbucket.org/pypy/pypy/changeset/6c374f053724/

Log:    merge default

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -867,8 +867,12 @@
                 self.__statement.set_params(params)
                 ret = sqlite.sqlite3_step(self.__statement.statement)
                 if ret != SQLITE_DONE:
+                    self.__statement.reset()
+                    self.__connection._in_transaction = \
+                            not 
sqlite.sqlite3_get_autocommit(self.__connection._db)
                     raise self.__connection._get_exception(ret)
                 self.__rowcount += 
sqlite.sqlite3_changes(self.__connection._db)
+            self.__statement.reset()
 
         return self
 
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
@@ -106,3 +106,20 @@
         open_many(True)
     finally:
         resource.setrlimit(resource.RLIMIT_NOFILE, limit)
+
+def test_on_conflict_rollback_executemany():
+    major, minor, micro = _sqlite3.sqlite_version.split('.')
+    if (int(major), int(minor), int(micro)) < (3, 2, 2):
+        pytest.skip("requires sqlite3 version >= 3.2.2")
+    con = _sqlite3.connect(":memory:")
+    con.execute("create table foo(x, unique(x) on conflict rollback)")
+    con.execute("insert into foo(x) values (1)")
+    try:
+        con.executemany("insert into foo(x) values (?)", [[1]])
+    except _sqlite3.DatabaseError:
+        pass
+    con.execute("insert into foo(x) values (2)")
+    try:
+        con.commit()
+    except _sqlite3.OperationalError:
+        pytest.fail("_sqlite3 knew nothing about the implicit ROLLBACK")
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to