简体   繁体   中英

Use a query in sqlite value - python

Does anyone know how to execute a query inside a value in python sqlite

The eroor i am getting is: sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM