SQlite元/系統數據查詢:表和列

import sqlite3

basedir='''C:\WorkSpace\PythonProgram\SSOETLMonitor'''
dbfile='''ssoetlmonitor.db'''
conn=sqlite3.connect(basedir+'\\'+dbfile)
md={}

tabs=conn.execute('''select name from sqlite_master where type='table' ''')

def Generate_Row(table_name):
    row={}
    cols=conn.execute(f"PRAGMA table_info({tab_name})")
    for col in cols:
        col_name=col[1]
        row[col_name]=f"{tab_name}:{col_name}"
    return row

for tab in tabs:
    tab_name=tab[0]
    md[tab_name]={}
    cols=conn.execute(f"PRAGMA table_info({tab_name})")
    for col in cols:
        col_name=col[1]
        md[tab_name][col_name]=f"{tab_name}:{col_name}"

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章