mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-22 09:36:35 +03:00
minor improvement of HashDB
This commit is contained in:
parent
323aa7bf2f
commit
47b27a5988
|
@ -21,7 +21,7 @@ class HashDB(object):
|
|||
threadData = getCurrentThreadData()
|
||||
|
||||
if threadData.hashDBCursor is None:
|
||||
connection = sqlite3.connect(self.filepath, isolation_level=None)
|
||||
connection = sqlite3.connect(self.filepath, timeout=3, isolation_level=None)
|
||||
threadData.hashDBCursor = connection.cursor()
|
||||
threadData.hashDBCursor.execute("CREATE TABLE IF NOT EXISTS storage (id INTEGER PRIMARY KEY, value TEXT)")
|
||||
|
||||
|
@ -34,7 +34,6 @@ class HashDB(object):
|
|||
|
||||
def close(self):
|
||||
try:
|
||||
self.endTransaction()
|
||||
self.cursor.connection.close()
|
||||
except:
|
||||
pass
|
||||
|
@ -48,14 +47,28 @@ class HashDB(object):
|
|||
retVal = None
|
||||
if key:
|
||||
hash_ = self.hashKey(key)
|
||||
for row in self.cursor.execute("SELECT value FROM storage WHERE id=?", (hash_,)):
|
||||
retVal = row[0]
|
||||
while True:
|
||||
try:
|
||||
for row in self.cursor.execute("SELECT value FROM storage WHERE id=?", (hash_,)):
|
||||
retVal = row[0]
|
||||
except sqlite3.OperationalError, ex:
|
||||
if not 'locked' in ex.message:
|
||||
raise
|
||||
else:
|
||||
break
|
||||
return retVal
|
||||
|
||||
def write(self, key, value):
|
||||
if key:
|
||||
hash_ = self.hashKey(key)
|
||||
try:
|
||||
self.cursor.execute("INSERT INTO storage VALUES (?, ?)", (hash_, value,))
|
||||
except sqlite3.IntegrityError:
|
||||
self.cursor.execute("UPDATE storage SET value=? WHERE id=?", (value, hash_,))
|
||||
while True:
|
||||
try:
|
||||
try:
|
||||
self.cursor.execute("INSERT INTO storage VALUES (?, ?)", (hash_, value,))
|
||||
except sqlite3.IntegrityError:
|
||||
self.cursor.execute("UPDATE storage SET value=? WHERE id=?", (value, hash_,))
|
||||
except sqlite3.OperationalError, ex:
|
||||
if not 'locked' in ex.message:
|
||||
raise
|
||||
else:
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue
Block a user