【问题标题】:Sqlite Select Query with where clause in python return noneSqlite选择查询与python中的where子句返回无
【发布时间】:2017-09-23 08:39:12
【问题描述】:

我在 python 中使用 where 子句的 sqlite 选择查询返回无或空(>>>)

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 子句的简单选择查询时,它会返回所有数据

【问题讨论】:

  • 请粘贴INSERTs,以便人们重现该行为。另外,也许您只是缺少单词周围的引号,即:SELECT * FROM entries Where word="?"
  • 这个在sqlite官网上有提到
  • 你确定你有word = 'hello'的一行吗?
  • SELECT word='hello', * FROM entries 的输出是什么?一行是否标有1
  • 是的,因为这是包含 176023 个单词的字典数据库

标签: python sqlite


【解决方案1】:

试试这个查询:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-28
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多