changeset 740:867bab9f317a dev

function to check the existence of tables
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 27 Aug 2015 23:51:18 -0400
parents 25e78d756823
children 5b91b8d97cf3
files python/storage.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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'''