Allow null where clauses in select
Signed-off-by: Martin J. Bligh <mbligh@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@662 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/db.py b/tko/db.py
index b6686cc..f2c3af9 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -8,17 +8,18 @@
self.cur = self.con.cursor()
- def select(self, fields, table, where_dict):
+ def select(self, fields, table, where):
"""\
select fields from table where {dictionary}
"""
- keys = [field + '=%s' for field in where_dict.keys()]
- values = [where_dict[field] for field in where_dict.keys()]
+ cmd = 'select %s from %s' % (fields, table)
- where = 'and'.join(keys)
- cmd = 'select %s from %s where %s' % (fields, table, where)
- print cmd
- print values
+ if where:
+ keys = [field + '=%s' for field in where.keys()]
+ values = [where[field] for field in where.keys()]
+
+ cmd = cmd + ' where ' + 'and'.join(keys)
+
self.cur.execute(cmd, values)
return self.cur.fetchall()
@@ -35,8 +36,7 @@
values = [data[field] for field in fields]
cmd = 'insert into %s (%s) values (%s)' % \
(table, ','.join(fields), ','.join(refs))
- print cmd
- print values
+
self.cur.execute(cmd, values)
self.con.commit()