MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / get_table_info

Function get_table_info

script/init_db.py:74–103  ·  view source on GitHub ↗
(db_obj, table)

Source from the content-addressed store, hash-verified

72
73# 获取表结构
74def get_table_info(db_obj, table):
75 field_info = {}
76 wheres = []
77 field_keys = []
78 tb_list = db_obj.query("PRAGMA table_info({});".format(table))
79 if not isinstance(tb_list, list):
80 if 'unable to open database file' in tb_list:
81 return None
82 print(table, tb_list)
83 print_x('{} 表结构读取失败,可能原因表已损坏'.format(table))
84 return None
85
86 for tb in tb_list:
87 field_info[tb[1]] = tb
88 field_keys.append('`{}`'.format(tb[1]))
89 wheres.append('`{}`=?'.format(tb[1]))
90
91 res = db_obj.query("SELECT * FROM sqlite_master WHERE type='table' AND name='{}';".format(table))
92 if not isinstance(res, list):
93 return None
94
95 if len(res) == 0:
96 return None
97 data = {}
98 data['field'] = field_info
99 data['sql'] = res[0][4]
100 data['field_keys'] = field_keys
101 data['wheres'] = wheres
102
103 return data
104
105
106# 检查表是否存在

Callers 4

sync_db_tableFunction · 0.85
get_sql_shellFunction · 0.85
test_sqlFunction · 0.85
repair_lack_fieldFunction · 0.85

Calls 4

print_xFunction · 0.70
queryMethod · 0.45
formatMethod · 0.45
appendMethod · 0.45

Tested by 1

test_sqlFunction · 0.68