# HG changeset patch # User Nicolas Saunier # Date 1437602073 14400 # Node ID 523eda2fafd4a12e86ee8fa222f9b9c27429e3ed # Parent 70a3cdf0dbb341adb6eae1c8f319214e96612af2 added function to create index diff -r 70a3cdf0dbb3 -r 523eda2fafd4 python/storage.py --- a/python/storage.py Wed Jul 22 17:01:25 2015 -0400 +++ b/python/storage.py Wed Jul 22 17:54:33 2015 -0400 @@ -34,6 +34,22 @@ except sqlite3.OperationalError as error: printDBError(error) +def createIndex(filename, tableName, columnName, createAnyway = False): + '''Creates an index for the column in the table + I will make querying with a condition on this column faster''' + try: + connection = sqlite3.connect(filename) + cursor = connection.cursor() + if createAnyway: + notExists = "" + else: + notExists = "IF NOT EXISTS " + cursor.execute("CREATE INDEX "+notExists+tableName+"_"+columnName+"_index ON "+tableName+"("+columnName+")") + connection.commit() + connection.close() + except sqlite3.OperationalError as error: + printDBError(error) + # TODO: add test if database connection is open # IO to sqlite def writeTrajectoriesToSqlite(objects, outputFilename, trajectoryType, objectNumbers = -1):