Fix up the main display page to only use one SQL query per rendering.
We use the new data view, and use SQL counting to get results
Signed-off-by: Martin Bligh <mbligh@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1059 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/db.py b/tko/db.py
index 06a37e5..0ccd753 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -52,14 +52,15 @@
def dprint(self, value):
if self.debug:
- sys.stderr.write('SQL: ' + str(value) + '\n')
+ sys.stdout.write('SQL: ' + str(value) + '\n')
def commit(self):
self.con.commit()
- def select(self, fields, table, where, wherein={}, distinct = False):
+ def select(self, fields, table, where, wherein={}, distinct = False,
+ group_by = None):
"""\
select fields from table where {dictionary}
"""
@@ -83,7 +84,10 @@
keys_in += [field_in + ' in (' + ','.join(wherein[field_in])+') ']
cmd.append(' and '+' and '.join(keys_in))
- self.dprint('%s %s' % (' '.join(cmd),values))
+ if group_by:
+ cmd.append(' GROUP BY ' + group_by)
+
+ self.dprint('%s %s' % (' '.join(cmd), values))
self.cur.execute(' '.join(cmd), values)
return self.cur.fetchall()