0

我正在尝试在以后的查询中使用来自 sqlite 查询的结果。在下面的代码中,请注意,exam[1] 是一个字符串,并且 'endtime' 打印正确。但是,我似乎无法将其传递给 db.execute 语句。更令人困惑的是,如果我从 python 命令行执行相同的操作(将 endtime 设置为字符串并调用 db.execute 语句),它会按预期工作。关于我所缺少的任何想法。

Exam_list 由两个日期时间字符串和一个 uuid 组成。我还尝试将值作为 (kiosk,exam[1],exam[1],) 传递,结果相同。

   for exam in exam_list:
     print "%s\t%s\n%s\t%s\n%s\t%s\n" % (exam[0],type(exam[0]),exam[1],type(exam[1]),exam[2],type(exam[2]),)
     endtime = exam[1]
     print "Endtime is %s" % (endtime)
     db.execute("""select sessionid, examtype, email from schedule where stationid = ? and iestart < ? and ieend > ? and status = 'Pending' """, (kiosk, endtime, endtime,))

生产

2016-12-16 14:45:00 <type 'str'>
2016-12-16 19:30:00 <type 'str'>
48f7a832-cf8a-47c2-b3b0-b279fc23f932    <type 'str'>

Endtime is 2016-12-16 19:30:00
Traceback (most recent call last):
  File "checkschedule.py", line 62, in <module>
    check_overlap(kiosk)
  File "checkschedule.py", line 40, in check_overlap
    db.execute("""select sessionid, examtype, email from schedule where stationid = ? and iestart < ? and ieend > ? and status = 'Pending' """, (kiosk, endtime, endtime,))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
4

1 回答 1

0

我想我已经想通了。我错过了“参数0”位。时间日期的事情原来是一个红鲱鱼。这里的问题是“kiosk”作为元组传递给函数。解决方案是指定 kiosk[0]。

于 2016-12-16T22:37:07.100 回答