您好我有小桌子,我希望能够更新这是在任何更新之前表格的样子:
RoomNumber Available Breakfast Price Booked DateBooked FullName
1 1 0 49.0 0 NB
2 1 0 49.0 0 NB
3 1 0 49.0 0 NB
4 1 0 49.0 0 NB
当我尝试更新表一旦它被执行后它实际上不会更新并且没有任何改变,这是应该更新它的代码:
print("#################### Database Updating ####################")
time.sleep(2)
with sqlite3.connect(DatabaseName) as db:
cursor = db.cursor()
SQL = "UPDATE BOOKINGS SET Available = ?, Breakfast = ?, Price = ?, Booked = ?, DateBooked = ?, FullName = ? WHERE RoomNumber = ?"
cursor.execute(SQL,data)
db.commit()
print(data)
print("#################### Database Updated ####################")
我甚至不知道在哪里寻找错误,它可能是一些小但我无法看到任何东西,任何帮助将不胜感激。
这是数据包含的内容:
print("#################### Booking ####################")
RoomNumber = int(input("Please enter the Room number you want to book"))
SQLlibrary.CheckRoom(RoomNumber,DatabaseName)
Available = False
Breakfast = int(input("Would you like to have Breakfast included with your booking: 1 = yes, 0 = no"))
if Breakfast == 1:
Breakfast = True
elif Breakfast == 0:
Breakfast = False
else:
print("Error")
Booking()
Price = 49.00
Booked = True
Date = input("Please Input the date you want to book the room in this format: dd/mm")
FirstName = input("Please Enter your First name: ")
Surname = input("Please Enter your Surname: ")
FullName = (FirstName + "" + Surname)
data = (Available,Breakfast,Price,Booked,Date,RoomNumber,FullName)
SQLlibrary.UpdateDatabase(DatabaseName,data)
答案 0 :(得分:0)
查询:
UPDATE BOOKINGS SET Available = ?, ..., FullName = ? WHERE RoomNumber = ?
参数:
data = (Available, ..., RoomNumber, FullName)
只要您碰巧与您的房间同名,这就可以正常工作。