简体   繁体   English

如何在sqlite3 python中获取更多然后一个字母的查询?

[英]How to get more then one letter queries back in sqlite3 python?

I am making a program where you can search if something is in an sqlite3 database. 我正在编写一个程序,您可以在其中搜索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)

The program only works when I search 1 letter things. 该程序仅在我搜索1个字母的东西时有效。 When I try something else, it says that there is incorrect number of binding supplies. 当我尝试其他操作时,它表示装订耗材的数量不正确。 It also says that the current statement uses 1, while there is how many letters I gave supplied. 它还说当前语句使用1,而我提供了多少个字母。 If anyone knows how to fix this, that would be greatly appreciated. 如果有人知道如何解决此问题,将不胜感激。

The Cursor.execute() method expects a sequence as second parameter. Cursor.execute()方法期望将序列作为第二个参数。 You are supplying a string which happens to be 8 characters long. 您提供的字符串恰巧是8个字符。

Use the following form instead: 请使用以下形式:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM