Skip to content

Commit b08aeed

Browse files
committed
Fix SQLite3 rowcount issue of always returning -1
SQLite does not return rowcount reliably, so forcing a fetchall and then doing a len on it will get the correct rowcount. This will also fix ALL of the row count keywords and table must exist keyword.
1 parent 8350ea8 commit b08aeed

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/DatabaseLibrary/query.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,11 @@ def row_count(self, selectStatement):
8787
try:
8888
cur = self._dbconnection.cursor()
8989
self.__execute_sql(cur, selectStatement)
90-
cur.fetchall()
91-
rowCount = cur.rowcount
90+
data = cur.fetchall()
91+
if self.db_api_module_name in ["sqlite3"]:
92+
rowCount = len(data)
93+
else:
94+
rowCount = cur.rowcount
9295
return rowCount
9396
finally :
9497
if cur :

0 commit comments

Comments
 (0)