diff --git a/Database.py b/Database.py index 49ba7ea..9e8364b 100644 --- a/Database.py +++ b/Database.py @@ -10,24 +10,28 @@ class Database(object): self.conn.close() def create_table(self, name, row_list): + """creates table 'name' with rows from 'row_list' if it doesn't exist""" + if self.table_exists(name): return True else: - row_string = "" + rows = "" separator = ", " for i in range(0, len(row_list)): if i == len(row_list) - 1: separator = "" - row_string += "%s%s" % (row_list[i], separator) + rows += "%s%s" % (row_list[i], separator) - self.conn.execute("CREATE TABLE %s(%s)" % (name, row_string)) + self.conn.execute("CREATE TABLE %s(%s)" % (name, rows)) if self.table_exists(name): return True else: return False def table_exists(self, name): + """returns true if table 'name' exists""" + result = self.conn.execute("""SELECT * FROM sqlite_master WHERE type='table' AND name=?""", (name,)) if result.fetchone() is None: @@ -45,3 +49,6 @@ class Database(object): log_entry.duration, log_entry.file_count)) self.conn.commit() + + def query(self, query): + return self.conn.execute(query).fetchall()