Make sqlite index deletion and creation work.
Also updated the coding style and logging in that area.
This commit is contained in:
parent
3716f11f06
commit
6b00311756
|
@ -1162,7 +1162,8 @@ class Database:
|
||||||
self.connection.set_isolation_level(0) # allow table/index operations to work
|
self.connection.set_isolation_level(0) # allow table/index operations to work
|
||||||
for idx in self.indexes[self.backend]:
|
for idx in self.indexes[self.backend]:
|
||||||
if self.backend == self.MYSQL_INNODB:
|
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:
|
try:
|
||||||
s = "create index %s on %s(%s)" % (idx['col'],idx['tab'],idx['col'])
|
s = "create index %s on %s(%s)" % (idx['col'],idx['tab'],idx['col'])
|
||||||
self.get_cursor().execute(s)
|
self.get_cursor().execute(s)
|
||||||
|
@ -1170,21 +1171,23 @@ class Database:
|
||||||
print " create idx failed: " + str(sys.exc_info())
|
print " create idx failed: " + str(sys.exc_info())
|
||||||
elif self.backend == self.PGSQL:
|
elif self.backend == self.PGSQL:
|
||||||
# mod to use tab_col for index name?
|
# 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:
|
try:
|
||||||
s = "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col'])
|
s = "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col'])
|
||||||
self.get_cursor().execute(s)
|
self.get_cursor().execute(s)
|
||||||
except:
|
except:
|
||||||
print " create idx failed: " + str(sys.exc_info())
|
print " create idx failed: " + str(sys.exc_info())
|
||||||
elif self.backend == self.SQLITE:
|
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:
|
try:
|
||||||
s = "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col'])
|
s = "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col'])
|
||||||
self.get_cursor().execute(s)
|
self.get_cursor().execute(s)
|
||||||
except:
|
except:
|
||||||
log.debug("Create idx failed: " + str(sys.exc_info()))
|
log.debug("Create idx failed: " + str(sys.exc_info()))
|
||||||
else:
|
else:
|
||||||
print "Only MySQL, Postgres and SQLite supported so far"
|
print "Unknown database: MySQL, Postgres and SQLite supported"
|
||||||
return -1
|
return -1
|
||||||
if self.backend == self.PGSQL:
|
if self.backend == self.PGSQL:
|
||||||
self.connection.set_isolation_level(1) # go back to normal isolation level
|
self.connection.set_isolation_level(1) # go back to normal isolation level
|
||||||
|
@ -1215,8 +1218,15 @@ class Database:
|
||||||
% (idx['tab'],idx['col']) )
|
% (idx['tab'],idx['col']) )
|
||||||
except:
|
except:
|
||||||
print " drop idx failed: " + str(sys.exc_info())
|
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:
|
else:
|
||||||
print "Only MySQL and Postgres supported so far"
|
print "Only MySQL, Postgres and SQLITE supported, what are you trying to use?"
|
||||||
return -1
|
return -1
|
||||||
if self.backend == self.PGSQL:
|
if self.backend == self.PGSQL:
|
||||||
self.connection.set_isolation_level(1) # go back to normal isolation level
|
self.connection.set_isolation_level(1) # go back to normal isolation level
|
||||||
|
|
Loading…
Reference in New Issue
Block a user