当前位置:优学网  >  在线题库

SQL lite搜索函数

发表时间:2022-07-26 02:57:30 阅读:184

所以我对SQL lite和Python一般来说都是新手...

我正在创建一个搜索函数,当输入收到一个空查询时,该函数应该返回一个else语句.当我填充else语句时,不理解返回的是整个数据库,而不是我调用的print语句.

def search_task():
askjeeves =  input("Enter Search Term: ")
cur = con.cursor()
if askjeeves != "" or askjeeves != " ":
    cur.execute("SELECT * FROM books WHERE author LIKE'%'||?||'%' ", (askjeeves,))
    finalsearch = cur.fetchall()
    print(finalsearch)
    search_task()
else:
    print("No value inputted, program ended. ")

还尝试了:

def search_task():
askjeeves =  input("Enter Search Term: ")
cur = con.cursor()
if askjeeves != None:
    cur.execute("SELECT * FROM books WHERE author LIKE'%'||?||'%' ", (askjeeves,))
    finalsearch = cur.fetchall()
    print(finalsearch)
    search_task()
else:
    print("No search input")
    input("Do you want to search again? Input 1 for Yes, 0 for No:")
    if input == 1:
        search_task()
    else:
        print("Search Ended")
🎖️ 优质答案
相关问题