From 6b00311756e7c4d54205ccc1b2d55b00550755c4 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 4 Jun 2010 14:37:46 +0800 Subject: [PATCH] Make sqlite index deletion and creation work. Also updated the coding style and logging in that area. --- pyfpdb/Database.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 8939d4b3..23fb02fb 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1162,7 +1162,8 @@ class Database: self.connection.set_isolation_level(0) # allow table/index operations to work for idx in self.indexes[self.backend]: if self.backend == self.MYSQL_INNODB: - print "creating mysql index ", idx['tab'], idx['col'] + print "Creating mysql index %s %s" %(idx['tab'], idx['col']) + log.debug("Creating sqlite index %s %s" %(idx['tab'], idx['col'])) try: s = "create index %s on %s(%s)" % (idx['col'],idx['tab'],idx['col']) self.get_cursor().execute(s) @@ -1170,21 +1171,23 @@ class Database: print " create idx failed: " + str(sys.exc_info()) elif self.backend == self.PGSQL: # mod to use tab_col for index name? - print "creating pg index ", idx['tab'], idx['col'] + print "Creating pg index %s %s" %(idx['tab'], idx['col']) + log.debug("Creating sqlite index %s %s" %(idx['tab'], idx['col'])) try: s = "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col']) self.get_cursor().execute(s) except: print " create idx failed: " + str(sys.exc_info()) elif self.backend == self.SQLITE: - log.debug("Creating sqlite index %s %s" % (idx['tab'], idx['col'])) + print "Creating sqlite index %s %s" %(idx['tab'], idx['col']) + log.debug("Creating sqlite index %s %s" %(idx['tab'], idx['col'])) try: s = "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col']) self.get_cursor().execute(s) except: log.debug("Create idx failed: " + str(sys.exc_info())) else: - print "Only MySQL, Postgres and SQLite supported so far" + print "Unknown database: MySQL, Postgres and SQLite supported" return -1 if self.backend == self.PGSQL: self.connection.set_isolation_level(1) # go back to normal isolation level @@ -1215,8 +1218,15 @@ class Database: % (idx['tab'],idx['col']) ) except: print " drop idx failed: " + str(sys.exc_info()) + elif self.backend == self.SQLITE: + print "Dropping sqlite index ", idx['tab'], idx['col'] + try: + self.get_cursor().execute( "drop index %s_%s_idx" + % (idx['tab'],idx['col']) ) + except: + print " drop idx failed: " + str(sys.exc_info()) else: - print "Only MySQL and Postgres supported so far" + print "Only MySQL, Postgres and SQLITE supported, what are you trying to use?" return -1 if self.backend == self.PGSQL: self.connection.set_isolation_level(1) # go back to normal isolation level