各位版友好,小弟目前在写一个小project,目的是要做portable的windows app
但目前遇到从数据库里无法select的问题,已经卡了1星期了...
以下是我的程式码,想法是:
比对输入的字串是否为空→输入字串是否在数据库里面→如果是,将该笔资料select
但是执行之后,Error显示“No query Unable to fetch row”
我很确定第一个select执行完后,result里有select出来的资料
def srh(self):
query_object = QtSql.QSqlQuery()
prod_ID = self.srh_bar.text()
result = []
if prod_ID != "":
query_object.exec_("SELECT ID FROM add_prod")
while (query_object.next()):
result.append(query_object.value(0))
print(result)
if prod_ID in result:
query_object.exec_(
"SELECT prod_name, ingre, unit_price, effect"
"FROM add_ingre AS I, add_prod AS P, mix AS M"
"WHERE I.ID = M.ingre_ID AND P.ID = M.prod_ID"
"AND P.ID = '%s'"%prod_ID)
if not query_object.exec_():
print(query_object.lastError().text())
else:
print("false")
而我也试过用place holder的方式,变成:
query_object.prepare(
"SELECT prod_name, ingre, unit_price, effect"
"FROM add_ingre AS I, add_prod AS P, mix AS M"
"WHERE I.ID = M.ingre_ID AND P.ID = M.prod_ID AND P.ID = :a")
query_object.bindValue(":a", prod_ID)
query_object.exec_()
但是这段程式码出现“Parameter count mismatch”
希望各位版友能够帮我解答,谢谢!!