尝试从数据库中的表中获取一段数据并将其插入另一个表中:
获取订单总数并将其分配给变量:
cursor.execute('''SELECT Price FROM Tracks WHERE TrackID = ?''', (trackChoice,))
ordertotal = str(cursor.fetchall())
把它放到桌子上:
cursor.execute('''INSERT INTO Orders(OrderID, Date, OrderTotal, CustomerID, TrackID) VALUES(?, ?, ?, ?, ?)''', (orderID, date,
ordertotal, customerID, trackChoice))
错误:
sqlite3.InterfaceError: Error binding parameter 2 - probably unsupported type.
答案 0 :(得分:0)
使用cursor.fetchall()可以获得' Tracks'中的所有行。所以它将有一个ID,可能还有其他信息。 F.E.这样的事情:(1,'威廉','莎士比亚',' m',无,' 1961-10-25')。什么是' ordertotal'?我想这会是一个数字?如果是,并且您使用的是sqlite3,则可以使用row_factory。有关详细信息,请参阅此处的回答:Get a list of field values from Python's sqlite3, not tuples representing rows
答案 1 :(得分:-1)
为什么不这样做:
cursor.execute("""
INSERT INTO Orders(name, Date, name, name, name)
VALUES(?, strftime('now'), ?, ?, ?)""",
(value, value, value, value);
即,使用数据库中的当前时间。
(我假设name
实际上是四个不同的列,或者你应该得到另一个错误。)