【问题标题】:sqlite3.OperationalError: no such table: sqlite_schemasqlite3.OperationalError:没有这样的表:sqlite_schema
【发布时间】:2022-01-21 21:23:31
【问题描述】:

我遇到了一个奇怪的问题。在 TablePlus 中,当我运行以下命令时,它会返回表,但相同的查询在 Python 中不起作用。

SELECT 
    name
FROM 
    sqlite_schema
WHERE 
    type ='table' 
    AND 
    name NOT LIKE 'lookup%';

Python代码如下:

def get_connection():
    path = 'data.sqlite3'
    connection = sqlite3.connect(path)
    return connection

sql_select = "SELECT name FROM sqlite_schema WHERE type ='table' AND name NOT LIKE 'lookup%';"
cursor = connection.execute(sql_select)

错误:

cursor = connection.execute(sql_select)
sqlite3.OperationalError: no such table: sqlite_schema

我正在使用 SQLite 3.36

【问题讨论】:

  • sqlite.org/schematab.html - 查看第 2 段的替代名称
  • @balderman 所以sqlite_master 工作。但是为什么sqlite_schema 在 TablePlus 中为同一个数据库工作,但在 Python 中却不行?
  • 我不知道.. :-)
  • 您可能在 TablePlus 中使用 3.36 版本,但 Python 版本比这更旧。 select sqlite_version(); 在 Python 中返回什么?
  • @MarkBenningfield 3.29.0

标签: python sqlite


【解决方案1】:

在 PHP CPANEL VERSION 92 中为 sqlite_master 更改 sqlite_schema,成功

【讨论】:

    猜你喜欢
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 2015-07-30
    • 2016-02-20
    • 2018-08-18
    • 2021-07-24
    • 2017-09-12
    • 2017-12-10
    相关资源
    最近更新 更多