我在 Contacts.sqlite 文件中有一个大约 20 个列表“联系人”。我使用 Mac 终端与其交互,并正在编写一个程序,该程序将根据表中的列数以及每列的名称执行某些操作。
因此,我需要执行某种查询来返回所有列标题的列表。
我发现了各种类似于以下版本的建议:
SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'Schema' AND table_name = 'Table_Name'
Run Code Online (Sandbox Code Playgroud)
但它几乎总是返回一个错误,指出“没有这样的表:information_scheme.columns”。
看起来 SQLite 不支持information_schema. 您可以从 中检索表名列表sqlite_master。但没有带有列的表。
相反,SQLite 支持专有的 pragma table_info():
pragma table_info(table_name);
Run Code Online (Sandbox Code Playgroud)