所以我对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")