mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
when echo on, log call time too
This commit is contained in:
parent
0a677fee56
commit
a697c292b5
1 changed files with 11 additions and 5 deletions
16
anki/db.py
16
anki/db.py
|
@ -2,7 +2,7 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import os
|
import os, time
|
||||||
try:
|
try:
|
||||||
from pysqlite2 import dbapi2 as sqlite
|
from pysqlite2 import dbapi2 as sqlite
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -25,24 +25,30 @@ class DB(object):
|
||||||
for stmt in "insert", "update", "delete":
|
for stmt in "insert", "update", "delete":
|
||||||
if s.startswith(stmt):
|
if s.startswith(stmt):
|
||||||
self.mod = True
|
self.mod = True
|
||||||
if self.echo:
|
t = time.time()
|
||||||
print sql #, a, ka
|
|
||||||
if ka:
|
if ka:
|
||||||
# execute("...where id = :id", id=5)
|
# execute("...where id = :id", id=5)
|
||||||
res = self._db.execute(sql, ka)
|
res = self._db.execute(sql, ka)
|
||||||
else:
|
else:
|
||||||
# execute("...where id = ?", 5)
|
# execute("...where id = ?", 5)
|
||||||
res = self._db.execute(sql, a)
|
res = self._db.execute(sql, a)
|
||||||
|
if self.echo:
|
||||||
|
#print a, ka
|
||||||
|
print sql, "%0.3fms" % ((time.time() - t)*1000)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def executemany(self, sql, l):
|
def executemany(self, sql, l):
|
||||||
self.mod = True
|
self.mod = True
|
||||||
if self.echo:
|
t = time.time()
|
||||||
print sql #, l
|
|
||||||
self._db.executemany(sql, l)
|
self._db.executemany(sql, l)
|
||||||
|
if self.echo:
|
||||||
|
print sql, "%0.3fms" % ((time.time() - t)*1000)
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
|
t = time.time()
|
||||||
self._db.commit()
|
self._db.commit()
|
||||||
|
if self.echo:
|
||||||
|
print "commit %0.3fms" % ((time.time() - t)*1000)
|
||||||
|
|
||||||
def executescript(self, sql):
|
def executescript(self, sql):
|
||||||
self.mod = True
|
self.mod = True
|
||||||
|
|
Loading…
Reference in a new issue