0
class DatabaseManager(object): ##Ignore the indentation##
def __init__(self, db):
self.conn = sqlite3.connect(db)
self.conn.execute('pragma foreign_keys = on')
self.conn.commit()
self.c = self.conn.cursor()
def query_params(self, arg, params=None):
self.c.execute(arg, params)
self.conn.commit()
return self.c
def query(self, arg):
self.c.execute(arg)
self.conn.commit()
return self.c
def fetch(self):
self.c.fetchall()
self.conn.commit()
return self.c
def __del__(self):
self.conn.close()
dbmgr = DatabaseManager("connect.db")
其他代碼 .... .... .... 然後:接收表信息打印到控制檯
def read_from_db():
tables = []
query = "SELECT name FROM sqlite_master WHERE type='table'"
dbmgr.query(query)
rows = dbmgr.fetch()
for row in rows:
tables.append(row)
print (tables)
我不能弄清楚如何查看我的數據庫中的表格,它們是真實的,因爲我可以在我的sqlite管理器中看到它們。這用來工作的時候,我沒有階級,只是做了:
def read_from_db():
tables = []
c.execute("SELECT name FROM sqlite_master WHERE type='table'")
rows = c.fetchall()
for row in rows:
tables.append(row)
print (tables)