Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 866cdb4

Browse files
committed
speed of --replicate is now vastly improved
1 parent 96da7ba commit 866cdb4

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/core/convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def safechardecode(value):
177177
else:
178178
break
179179

180-
elif isinstance(value, list):
180+
elif isinstance(value, (list, tuple)):
181181
for i in xrange(len(value)):
182182
retVal[i] = safechardecode(value[i])
183183

lib/core/dump.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ def dbTableValues(self, tableValues):
358358
if not conf.multipleTargets and not conf.replicate:
359359
dataToDumpFile(dumpFP, "\n")
360360

361+
if conf.replicate:
362+
rtable.beginTransaction()
363+
361364
for i in range(count):
362365
field = 1
363366
values = []
@@ -398,11 +401,12 @@ def dbTableValues(self, tableValues):
398401
self.__write("%s\n" % separator)
399402

400403
if conf.replicate:
404+
rtable.endTransaction()
401405
logger.info("Table '%s.%s' dumped to sqlite3 file '%s'" % (db, table, replication.dbpath))
406+
402407
elif not conf.multipleTargets:
403408
dataToDumpFile(dumpFP, "\n")
404409
dumpFP.close()
405-
406410
logger.info("Table '%s.%s' dumped to CSV file '%s'" % (db, table, dumpFileName))
407411

408412
def dbColumns(self, dbColumns, colConsider, dbs):

lib/core/replication.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ def insert(self, values):
7171
errMsg = "wrong number of columns used in replicating insert"
7272
raise sqlmapValueException, errMsg
7373

74+
def beginTransaction(self):
75+
"""
76+
Great speed improvement can be gained by using explicit transactions around multiple inserts.
77+
Reference: http://stackoverflow.com/questions/4719836/python-and-sqlite3-adding-thousands-of-rows
78+
"""
79+
self.parent.cursor.execute('BEGIN TRANSACTION')
80+
81+
def endTransaction(self):
82+
self.parent.cursor.execute('END TRANSACTION')
83+
7484
def select(self, condition=None):
7585
"""
7686
This function is used for selecting row(s) from current table.

0 commit comments

Comments
 (0)