def makeProductTable():
"""This creates a database with a blank table."""
with connect("products.db") as db:
cursor = db.cursor()
cursor.execute("""
CREATE TABLE Product(
ProductID integer,
GTIN integer,
Description string,
StockLevel integer,
Primary Key(ProductID));""")
db.commit()
def editStockLevel():
with connect("products.db") as db:
cursor = db.cursor()
Product_ID=input("Please enter the id of the product you would like to change: ")
Stock_Update=input("Please enter the new stock level: ")
sql = "update product set StockLevel = ('Stock_Update') where ProductID = ('Product_ID');"
cursor.execute(sql)
db.commit()
return "Stock Level Updated."
最初の関数はテーブルを作成するために使用され、カラムタイトルが表示され、2番目の関数はテーブルの特定の値を更新するために必要です。(Python)cursor.execute
しかし、これを実行すると入力が実行されますが、すべてが表内のすべての製品を表示すると、在庫レベルの値は変更されません。
だから、問題はcursor.execute(sql)行と関係があると思います。
ありがとうございます、これは私のコードを修正しました。 – JW2209
@ JW2209。それが動作する場合は、答えとしてマークしてください。ありがとう。 – KR29