comparison sqlex/model.py @ 3:5f1e1ac96aa7

stub works with SELECT
author Jeff Hammel <k0scist@gmail.com>
date Sat, 01 Apr 2017 09:19:22 -0700
parents 63a75d318b06
children 3a7f515571dc
comparison
equal deleted inserted replaced
2:63a75d318b06 3:5f1e1ac96aa7
9 def __init__(self, db): 9 def __init__(self, db):
10 self.db = db 10 self.db = db
11 self.conn = sqlite3.connect(self.db) 11 self.conn = sqlite3.connect(self.db)
12 12
13 def __call__(self, sql, *args): 13 def __call__(self, sql, *args):
14 c = conn.cursor() 14 c = self.conn.cursor()
15 c.execute(sql, args) 15 c.execute(sql, args)
16 c.commit() 16 self.conn.commit()
17 try:
18 return c.fetchall()
19 except Exception as e:
20 raise e
17 21
18 def __del__(self): 22 def __del__(self):
19 self.conn.close() 23 self.conn.close()
20 24
21 def tables(self): 25 def tables(self):
22 """ 26 """
23 returns table names in database 27 returns table names in database
24 """ 28 """
25 # http://stackoverflow.com/questions/82875/how-to-list-the-tables-in-an-sqlite-database-file-that-was-opened-with-attach 29 # http://stackoverflow.com/questions/82875/how-to-list-the-tables-in-an-sqlite-database-file-that-was-opened-with-attach
26 30
27 sql = "SELECT name FROM dbname.sqlite_master WHERE type='table';" 31 sql = "SELECT name FROM sqlite_master WHERE type='table';"
28 tables = self(sql) 32 tables = self(sql)
29 return tables 33 return sum([list(item) for item in tables], [])
30