简体   繁体   English

在 sqlite 值中使用查询 - python

[英]Use a query in sqlite value - python

Does anyone know how to execute a query inside a value in python sqlite有谁知道如何在 python sqlite 的值内执行查询

The eroor i am getting is: sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.我得到的 eroor 是: sqlite3.InterfaceError: Error binding parameter 1 - 可能不受支持的类型。

my code is here:我的代码在这里:

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")  

You can also iterate over result:您还可以迭代结果:

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