23 lines
522 B
Python
23 lines
522 B
Python
|
|
#!/usr/bin/env python3
|
||
|
|
import sqlite3
|
||
|
|
|
||
|
|
# 连接数据库
|
||
|
|
conn = sqlite3.connect('tophub_data.db')
|
||
|
|
cursor = conn.cursor()
|
||
|
|
|
||
|
|
# 查看所有表
|
||
|
|
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
|
||
|
|
tables = cursor.fetchall()
|
||
|
|
print('Tables:', tables)
|
||
|
|
|
||
|
|
# 查看表结构
|
||
|
|
for table in tables:
|
||
|
|
table_name = table[0]
|
||
|
|
print(f'\nTable {table_name}:')
|
||
|
|
cursor.execute(f'PRAGMA table_info({table_name});')
|
||
|
|
columns = cursor.fetchall()
|
||
|
|
for col in columns:
|
||
|
|
print(col)
|
||
|
|
|
||
|
|
# 关闭连接
|
||
|
|
conn.close()
|