Skip to content

Commit

Permalink
check_sqlite_table: also check if entires in table
Browse files Browse the repository at this point in the history
code that uses this funciton assume the table is present and sometimes
also that there are entries in the table (table is not empty). To ensure
this does not crash in instances where the table is present but is
empty, also check that the table is not empty.
  • Loading branch information
jcharkow committed Nov 1, 2024
1 parent aefda4a commit 6e79d72
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion massdash/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ def check_sqlite_table(con, table):
result = con.execute('SELECT count(name) FROM sqlite_master WHERE type="table" AND name=?', (table,))

if result.fetchone()[0] == 1:
table_present = True
# ensure the table is not empty
result = con.execute(f"SELECT COUNT(*) FROM {table}")
if result.fetchone()[0] > 0:
table_present = True

return table_present

Expand Down

0 comments on commit 6e79d72

Please sign in to comment.