speed of --replicate is now vastly improved

This commit is contained in:
Miroslav Stampar 2011-04-14 14:34:12 +00:00
parent 96da7ba4eb
commit 866cdb4cf7
3 changed files with 16 additions and 2 deletions

View File

@ -177,7 +177,7 @@ def safechardecode(value):
else:
break
elif isinstance(value, list):
elif isinstance(value, (list, tuple)):
for i in xrange(len(value)):
retVal[i] = safechardecode(value[i])

View File

@ -358,6 +358,9 @@ class Dump:
if not conf.multipleTargets and not conf.replicate:
dataToDumpFile(dumpFP, "\n")
if conf.replicate:
rtable.beginTransaction()
for i in range(count):
field = 1
values = []
@ -398,11 +401,12 @@ class Dump:
self.__write("%s\n" % separator)
if conf.replicate:
rtable.endTransaction()
logger.info("Table '%s.%s' dumped to sqlite3 file '%s'" % (db, table, replication.dbpath))
elif not conf.multipleTargets:
dataToDumpFile(dumpFP, "\n")
dumpFP.close()
logger.info("Table '%s.%s' dumped to CSV file '%s'" % (db, table, dumpFileName))
def dbColumns(self, dbColumns, colConsider, dbs):

View File

@ -71,6 +71,16 @@ class Replication:
errMsg = "wrong number of columns used in replicating insert"
raise sqlmapValueException, errMsg
def beginTransaction(self):
"""
Great speed improvement can be gained by using explicit transactions around multiple inserts.
Reference: http://stackoverflow.com/questions/4719836/python-and-sqlite3-adding-thousands-of-rows
"""
self.parent.cursor.execute('BEGIN TRANSACTION')
def endTransaction(self):
self.parent.cursor.execute('END TRANSACTION')
def select(self, condition=None):
"""
This function is used for selecting row(s) from current table.