# HG changeset patch # User Nicolas Saunier # Date 1440733878 14400 # Node ID 867bab9f317a8377f2dc47488722de493e5b939c # Parent 25e78d756823518b5c5bba403c6eca2d9647279b function to check the existence of tables diff -r 25e78d756823 -r 867bab9f317a python/storage.py --- a/python/storage.py Thu Aug 20 15:30:19 2015 -0400 +++ b/python/storage.py Thu Aug 27 23:51:18 2015 -0400 @@ -34,6 +34,16 @@ except sqlite3.OperationalError as error: printDBError(error) +def tableExists(filename, tableName): + 'indicates if the table exists in the database' + try: + connection = sqlite3.connect(filename) + cursor = connection.cursor() + cursor.execute('SELECT COUNT(*) FROM SQLITE_MASTER WHERE type = \'table\' AND name = \''+tableName+'\'') + return cursor.fetchone()[0] == 1 + except sqlite3.OperationalError as error: + printDBError(error) + def createIndex(connection, tableName, columnName, unique = False): '''Creates an index for the column in the table I will make querying with a condition on this column faster'''