在Sqlite3 statemens中使用变量时出现问题

2024-05-13 20:46:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python2.7项目的问题。在

我试图将一个变量设置为从sqlite3数据库检索到的值,但遇到了问题。这是到目前为止我的代码,以及我收到的错误。是的,连接打开得很好,表、列和所指示的行都在那里。在

import sqlite3 import Trailcrest

conn = sqlite3.connect('roster.paw')
c = conn.cursor()

def Lantern(AI):
    """Pulls all of the data for the selected user."""
    Trailcrest.FireAutoHelp = c.execute("""select fireautohelp 
                                             from roster 
                                            where index = ?;""", (AI,) ).fetchall()

错误是:

^{pr2}$

Tags: the项目代码import数据库defconnect错误
1条回答
网友
1楼 · 发布于 2024-05-13 20:46:54

正如thomask在评论中提到的,index是一个SQL关键字。
可以重命名该列,也可以将其括在反勾中:

Trailcrest.FireAutoHelp = c.execute("""select fireautohelp 
                                         from roster 
                                        where `index` = ?;""", (AI,) ).fetchall()

相关问题 更多 >