我正在尝试使用python函数将某些数据库字段更新为SQLite DB。我不断收到以下错误:
ValueError:操作参数必须为str
下面是我的代码。我很想知道如何在sqlite数据库中更新多个列。
def updateEventData(): ID = input('Enter ID of row you\'d like to update: ') eventname = input('\nPlease enter event name: ') startdate = input('\nPlease enter event start date: (DD/MM/YYYY): ') enddate = input('\nPlease enter event end date: (DD/MM/YYYY): ') venue = input('\nPlease enter event venue: ') # Sql update sql = """ UPDATE event_details SET name, startdate, enddate, venue, (?, ?, ?, ?) WHERE ROWID = ? """, (eventname, startdate, enddate, venue, ID) c.execute(sql) conn.commit()
falsetru.. 5
您需要分别传递sql
和参数,而不是包含sql
和参数的元组:
sql = """ UPDATE event_details SET name, startdate, enddate, venue, (?, ?, ?, ?) WHERE ROWID = ? """ c.execute(sql, (eventname, startdate, enddate, venue, ID)) # ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # separated argument, not as a single argument conn.commit()
看到 DB API 2 documentation, Cursor.execute(operation, parameter)
您需要分别传递sql
和参数,而不是包含sql
和参数的元组:
sql = """ UPDATE event_details SET name, startdate, enddate, venue, (?, ?, ?, ?) WHERE ROWID = ? """ c.execute(sql, (eventname, startdate, enddate, venue, ID)) # ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # separated argument, not as a single argument conn.commit()
看到 DB API 2 documentation, Cursor.execute(operation, parameter)