MySQL时间类型的参数化查询

MySQL Parameterized query for time type

我正在尝试插入一个名为 duration 的时间类型变量的记录,它是通过使用 datetime 包获得的..

duration_start_time = datetime.now()
time.sleep(5)
duration_end_time = datetime.now()
duration = duration_end_time - duration_start_time

print(f"{fileName} took", duration, "to download")

insert_duration = "INSERT INTO ImportHistory(Duration) VALUES (%s)"
mycursor.execute(insert_duration, duration)
connection.commit()

我得到的错误是 'ValueError: Could not process parameters'

有谁知道我做错了什么吗?让我知道是否可以澄清我可能错过的任何必要信息!

参数必须是一个元组,即使只有一个参数:

mycursor.execute(insert_duration, (duration,))