0
我想在調用股票價值並將其減少一個之後更新SQLite數據庫中的列表?如何使用新值更新SQlite數據庫列表?
這裏是我使用的代碼:
ComicID = int(input("Enter Comic ID: "))
with sqlite3.connect("Chris_comics.db") as db:
if ComicID == 111:
cursor.execute("""select Value from Comics where ComicID=?""",(ComicID,))
result1=cursor.fetchone()
result1= repr(result1).replace(',','').replace('(', '').replace(')', '')
print(result1)
Grandtotal = Grandtotal + int(result1)
cursor.execute("""select Stock from Comics where ComicID=?""",(ComicID,))
StockUpdate = cursor.fetchone()
StockUpdate = repr(StockUpdate).replace(',','').replace('(', '').replace(')', '')
StockUpdate = int(StockUpdate) - 1
print(StockUpdate)
##check cursor.execute for updating stock
cursor.execute = "update Comics set Stock={0} where ComicID=?" .format(StockUpdate)
這似乎並沒有工作。
所以我需要在代碼的最後一行後添加'commit()'? – Chris