Add in condition for db class, for example select * from tests where kernel_idx
in (x, y, z)
From: Ying Han <yinghan@google.com>
Signed-off-by: Martin Bligh <mbligh@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1045 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/db.py b/tko/db.py
index cece69a..06a37e5 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -59,7 +59,7 @@
self.con.commit()
- def select(self, fields, table, where, distinct = False):
+ def select(self, fields, table, where, wherein={}, distinct = False):
"""\
select fields from table where {dictionary}
"""
@@ -77,6 +77,12 @@
elif where and isinstance(where, types.StringTypes):
cmd.append(' where ' + where)
+ if wherein and isinstance(wherein, types.DictionaryType):
+ keys_in = []
+ for field_in in wherein.keys():
+ keys_in += [field_in + ' in (' + ','.join(wherein[field_in])+') ']
+
+ cmd.append(' and '+' and '.join(keys_in))
self.dprint('%s %s' % (' '.join(cmd),values))
self.cur.execute(' '.join(cmd), values)
return self.cur.fetchall()