簡體   English   中英

在 sqlite 值中使用查詢 - python

[英]Use a query in sqlite value - python

有誰知道如何在 python sqlite 的值內執行查詢

我得到的 eroor 是: sqlite3.InterfaceError: Error binding parameter 1 - 可能不受支持的類型。

我的代碼在這里:

Name = input("Enter the name of the product you want to purchase: >>")
item = Name
qty = input("Enter the Quantity of the product you want to purchase: >>")

today = date.today()
cursor = db.cursor()
cursor.execute("SELECT CatID from Products where Name=?",(Name,))
result = cursor.fetchall()

 confirm = input("are you sure you want tot buy this product (y/n): >>" )

if confirm == "y":

     ### In this query where it says result i want to execute the data from the result query
cursor.execute("INSERT INTO OrderHistory(Username,Category,Date,Qty,ItemHistory) Values(?,?,?,?,?)",(Username,result,today,qty,Name))

db.commit()

print("Product purchased. Thankyou for your order")

cursor.execute("UPDATE Products SET Qty = (? -1) where Name = ?",(qty,item,))

else:

print("The program will now terminate")  

您還可以迭代結果:

for row in result:
    cursor.execute(
    "INSERT INTO OrderHistory(Username,Category,Date,Qty,ItemHistory) SELECT CatID,?,?,?,? FROM Products WHERE Name=?",(Username,row,today,qty,Name))
    db.commit()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM