【问题标题】:How to get more then one letter queries back in sqlite3 python?如何在 sqlite3 python 中返回一个以上的字母查询?
【发布时间】:2019-04-22 10:40:21
【问题描述】:

我正在制作一个程序,您可以在其中搜索是否在 sqlite3 数据库中。

def search():
tk = Tk()
tk.geometry('500x500')
def create():
    gette = entt.get()
    conn = sqlite3.connect('friend.db')
    with conn:
        cursor = conn.cursor()
    cursor.execute('SELECT * FROM Photos WHERE name1=?', gette)
    conn.commit()
    result = cursor.fetchall()
    print(result)

该程序仅在我搜索 1 个字母时才有效。当我尝试其他方法时,它说装订耗材的数量不正确。它还说当前语句使用 1,而我提供了多少个字母。如果有人知道如何解决这个问题,那将不胜感激。

【问题讨论】:

  • entt.get() 在做什么?您的语句看起来不错,如果您将字符串作为gette 传递,它应该将该字符串绑定到您的 SQL 查询。
  • entt.get() 正在获取条目中的内容(条目名称为 entt)
  • 但它是像字符串这样的单个值,还是元组或值列表?
  • 我不知道。我将如何检查?对不起,我对编程很陌生。
  • 请提供print(result)的结果。很可能是控制台或终端中显示的文本。

标签: python tkinter sqlite


【解决方案1】:

Cursor.execute() 方法需要一个序列作为第二个参数。您提供的字符串恰好是 8 个字符长。

请改用以下表格:

cursor.execute('SELECT * FROM Photos WHERE name1=?', [gette])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多