我有这个代码,它采用标题、isbn 或一本书的作者,并从数据库中检索所有匹配的数据。问题在于传递参数行,它只检索第一条记录,关于用户输入的数据。我尝试在数据库控制台中使用select 语句并检索正确的语句,我知道传递参数行的 cur.execute 是不正确的。 你能帮我解决这个问题吗?提前谢谢。这是代码class Searchb: def __init__(self,isbn,author,title): self.isbn=isbn self.author=author self.title=title def booksearch(self): query= "select author,title from books where isbn LIKE '%%s%%' OR author LIKE '%%s%%' OR title like '%%s%%' " cur.execute(query,(self.isbn,self.author,self.title),) book=cur.fetchmany()
2 回答

慕工程0101907
TA贡献1887条经验 获得超5个赞
问题出在 select 语句中,在将参数传递给数据库的同时,我可以找到使用 Like 的 select 语句的正确语法;postgres
query="select author,title from books where isbn LIKE %s or author like %s or title like %s " book_to_search=(self.isbn,self.author,self.title) cur.execute(query,book_to_search) book=cur.fetchall()
添加回答
举报
0/150
提交
取消