Sqlite使用python中的where子句选择查询返回无

问题描述 投票:0回答:1

我的sqlite select查询,其中python中的where子句返回none或为空(>>>)

import os.path
import sqlite3

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(BASE_DIR, "Dictionary.db")
with sqlite3.connect(db_path) as db:
    t = ('hello',)
    cursor = db.cursor()
    cursor.execute("SELECT * FROM entries Where word=?",t)
    Value = cursor.fetchall()
    for i in Value:
        print (i)        

输出:(>>>)

但是当我使用简单的选择查询而没有where子句时,它返回所有数据

python sqlite
1个回答
0
投票

试试这个查询:

cursor.execute("SELECT * FROM entries Where word=?",(t,))

第二个参数应该是元组或列表。

© www.soinside.com 2019 - 2024. All rights reserved.