summaryrefslogtreecommitdiff
path: root/bin/sql_db.py
diff options
context:
space:
mode:
authorP. Christeas <p_christ@hol.gr>2009-01-06 15:17:46 +0200
committerP. Christeas <p_christ@hol.gr>2009-01-06 15:17:46 +0200
commit3487f659ec80bda2855885c432af6d71586b3ff5 (patch)
treec2a2650dc76351552a689537f96f4eec9708ec2c /bin/sql_db.py
parent7aa561987b8ff6b6bad07fb192402801bbac800c (diff)
Always print SQL counters.
bzr revid: p_christ@hol.gr-20090106131746-mwdgfx2l1z9hd02b
Diffstat (limited to 'bin/sql_db.py')
-rw-r--r--bin/sql_db.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/bin/sql_db.py b/bin/sql_db.py
index 30b4df1e2b8..042c41940a3 100644
--- a/bin/sql_db.py
+++ b/bin/sql_db.py
@@ -59,6 +59,8 @@ def log(msg, lvl=netsvc.LOG_DEBUG):
logger = netsvc.Logger()
logger.notifyChannel('sql', lvl, msg)
+sql_counter = 0
+
class Cursor(object):
IN_MAX = 1000
sql_from_log = {}
@@ -72,7 +74,7 @@ class Cursor(object):
@wraps(f)
def wrapper(self, *args, **kwargs):
if not hasattr(self, '_obj'):
- raise psycopg2.ProgrammingError('Unable to use the cursor after having closing it')
+ raise psycopg2.ProgrammingError('Unable to use the cursor after having closed it')
return f(self, *args, **kwargs)
return wrapper
@@ -104,7 +106,7 @@ class Cursor(object):
self.count+=1
if '%d' in query or '%f' in query:
log(query, netsvc.LOG_WARNING)
- log("SQL queries mustn't containt %d or %f anymore. Use only %s", netsvc.LOG_WARNING)
+ log("SQL queries cannot contain %d or %f anymore. Use only %s", netsvc.LOG_WARNING)
if params:
query = query.replace('%d', '%s').replace('%f', '%s')
@@ -134,19 +136,20 @@ class Cursor(object):
return res
def print_log(self):
+ global sql_counter
+ sql_counter += self.count
def process(type):
sqllogs = {'from':self.sql_from_log, 'into':self.sql_into_log}
- if not sqllogs[type]:
- return
- sqllogitems = sqllogs[type].items()
- sqllogitems.sort(key=lambda k: k[1][1])
sum = 0
- log("SQL LOG %s:" % (type,))
- for r in sqllogitems:
- log("table: %s: %s/%s" %(r[0], str(r[1][1]), r[1][0]))
- sum+= r[1][1]
- log("SUM:%s/%d" % (sum, self.count))
- sqllogs[type].clear()
+ if sqllogs[type]:
+ sqllogitems = sqllogs[type].items()
+ sqllogitems.sort(key=lambda k: k[1][1])
+ log("SQL LOG %s:" % (type,))
+ for r in sqllogitems:
+ log("table: %s: %s/%s" %(r[0], str(r[1][1]), r[1][0]))
+ sum+= r[1][1]
+ sqllogs[type].clear()
+ log("SUM:%s/%d [%d]" % (sum, self.count,sql_counter))
process('from')
process('into')
self.count = 0