comparison python/storage.py @ 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 967d244968a4
children ed6ff2ec0aeb
comparison
equal deleted inserted replaced
739:25e78d756823 740:867bab9f317a
31 cursor = connection.cursor() 31 cursor = connection.cursor()
32 for tableName in tableNames: 32 for tableName in tableNames:
33 cursor.execute('DROP TABLE IF EXISTS '+tableName) 33 cursor.execute('DROP TABLE IF EXISTS '+tableName)
34 except sqlite3.OperationalError as error: 34 except sqlite3.OperationalError as error:
35 printDBError(error) 35 printDBError(error)
36
37 def tableExists(filename, tableName):
38 'indicates if the table exists in the database'
39 try:
40 connection = sqlite3.connect(filename)
41 cursor = connection.cursor()
42 cursor.execute('SELECT COUNT(*) FROM SQLITE_MASTER WHERE type = \'table\' AND name = \''+tableName+'\'')
43 return cursor.fetchone()[0] == 1
44 except sqlite3.OperationalError as error:
45 printDBError(error)
36 46
37 def createIndex(connection, tableName, columnName, unique = False): 47 def createIndex(connection, tableName, columnName, unique = False):
38 '''Creates an index for the column in the table 48 '''Creates an index for the column in the table
39 I will make querying with a condition on this column faster''' 49 I will make querying with a condition on this column faster'''
40 try: 50 try: