[pypy-commit] pypy default: test/fix for sqlite cursor iteration in corner cases
bdkearns
noreply at buildbot.pypy.org
Tue Mar 12 05:06:14 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r62306:930d2954c777
Date: 2013-03-12 00:05 -0400
http://bitbucket.org/pypy/pypy/changeset/930d2954c777/
Log: test/fix for sqlite cursor iteration in corner cases
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -876,9 +876,6 @@
if self.__statement._kind == Statement._DQL and ret == _lib.SQLITE_ROW:
self.__statement._build_row_cast_map()
self.__statement._readahead(self)
- else:
- self.__statement._item = None
- self.__statement._exhausted = True
if self.__statement._kind == Statement._DML:
if self.__rowcount == -1:
@@ -1015,7 +1012,6 @@
self._kind = Statement._DDL
self._in_use = False
- self._exhausted = False
self._row_factory = None
if isinstance(sql, unicode):
@@ -1053,7 +1049,6 @@
if self._in_use and self._statement:
_lib.sqlite3_reset(self._statement)
self._in_use = False
- self._exhausted = False
if sys.version_info[0] < 3:
def __check_decodable(self, param):
@@ -1218,18 +1213,17 @@
self._item = row
def _next(self, cursor):
- if self._exhausted:
+ try:
+ item = self._item
+ except AttributeError:
raise StopIteration
- item = self._item
+ del self._item
ret = _lib.sqlite3_step(self._statement)
- if ret == _lib.SQLITE_DONE:
- self._exhausted = True
- self._item = None
- elif ret != _lib.SQLITE_ROW:
+ if ret not in (_lib.SQLITE_DONE, _lib.SQLITE_ROW):
_lib.sqlite3_reset(self._statement)
raise self.__con._get_exception(ret)
- else:
+ elif ret == _lib.SQLITE_ROW:
self._readahead(cursor)
return item
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
@@ -57,11 +57,34 @@
cur = con.cursor()
with pytest.raises(StopIteration):
next(cur)
- cur = con.execute('select 1')
+
+ cur.execute('select 1')
next(cur)
with pytest.raises(StopIteration):
next(cur)
+ cur.execute('select 1')
+ con.commit()
+ next(cur)
+ with pytest.raises(StopIteration):
+ next(cur)
+
+ with pytest.raises(_sqlite3.ProgrammingError):
+ cur.executemany('select 1', [])
+ with pytest.raises(StopIteration):
+ next(cur)
+
+ cur.execute('select 1')
+ cur.execute('create table test(ing)')
+ with pytest.raises(StopIteration):
+ next(cur)
+
+ cur.execute('select 1')
+ cur.execute('insert into test values(1)')
+ con.commit()
+ with pytest.raises(StopIteration):
+ next(cur)
+
def test_cursor_after_close():
con = _sqlite3.connect(':memory:')
cur = con.execute('select 1')
More information about the pypy-commit
mailing list