Python-MySQL中的TIMEDIFF()函数未将小时数纳入查询

时间:2019-03-31 21:01:33

标签: python mysql

我有一个python代码,试图使用end_time函数在MySQL表中的start_timeTIMEDIFF()之间放置持续时间。问题是,当我从代码中调用查询并为其提供参数时,它将引发下一个异常:

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':35:23, 15:35:18)' at line 1

在这里,如您所见,它表示我输入的参数格式错误。但是我调试了代码,并且start_timeend_time都具有正确的格式,所以我不知道为什么要这样做。

这是我的代码:

def update_duration_mysql(pkt):
    data_base = mysql.connector.connect(host="localhost", user="root", passwd="", database="proyecto1DB")
    cursor = data_base.cursor()
    end_hour = pkt.sniff_time.hour
    end_minute = pkt.sniff_time.minute
    end_second = pkt.sniff_time.second
    set_end_time_mysql(end_hour, end_minute, end_second, pkt.sip.call_id)
    t1 = get_start_time_mysql(pkt.sip.call_id)#this is the start_time
    t2 = str(end_hour) + ":" + str(end_minute) + ":" + str(end_second)#this is the end_time
    consult = "SELECT TIMEDIFF(%s, %s)"%(t2,str(t1))
    time = cursor.execute(consult)
    sql = "UPDATE call SET duration = %s WHERE = %s"%(str(time), str(pkt.sip.call_id))
    cursor.execute(sql)
    data_base.commit()

0 个答案:

没有答案