Permalink
Browse files

fetchone() should return None if no row

  • Loading branch information...
1 parent 92a3f2b commit 31c4737a98bab851b9686ace3ac7c98fda2de183 @nakagami committed Jun 23, 2011
Showing with 20 additions and 2 deletions.
  1. +6 −2 firebirdsql/fbcore.py
  2. +14 −0 firebirdsql/tests.py
@@ -642,8 +642,12 @@ def executemany(self, query, seq_of_params):
self.execute(query, params)
def fetchone(self):
- return self.rows[self.cur_row]
- self.cur_row += 1
+ if self.cur_row < len(self.rows):
+ r = self.rows[self.cur_row]
+ self.cur_row += 1
+ return r
+ else:
+ return None
def fetchall(self):
return self.rows
View
@@ -50,6 +50,12 @@ def debug_print(msg):
)
''')
conn.commit()
+
+ cur = conn.cursor()
+ cur.execute("select * from foo")
+ assert cur.fetchone() is None
+ cur.close()
+
conn.cursor().execute("insert into foo(a, b, c) values (1, 'a', 'b')")
conn.cursor().execute("""insert into foo(a, b, c, e, g, i, j)
values (2, 'A', 'B', '1999-01-25', '00:00:01', 0.1, 0.1)""")
@@ -61,6 +67,14 @@ def debug_print(msg):
conn.commit()
cur = conn.cursor()
+ cur.execute("select * from foo")
+ assert not cur.fetchone() is None
+ assert not cur.fetchone() is None
+ assert not cur.fetchone() is None
+ assert cur.fetchone() is None
+ cur.close()
+
+ cur = conn.cursor()
try:
conn.cursor().execute("insert into foo(a, b, c) values (1, 'a', 'b')")
except firebirdsql.IntegrityError:

0 comments on commit 31c4737

Please sign in to comment.