I am trying to use the results from an sqlite query in a later query. In the code below, note that exam[1] is a string and 'endtime' prints correctly. However, I don't seem to be able to pass that to the db.execute statement. To make matters more confusing, if I do the same thing from the python command line (set endtime to string and call db.execute statement) it works as expected. Any ideas about what I am missing.
exam_list consist of two datetime strings and a uuid. I have also tried passing the values as (kiosk,exam[1],exam[1],) with the same results.
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,))
produces
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.
I think I have figured it out. I was missing the "parameter 0" bit. The timedate thing turned out to be a red herring. The issue here is that 'kiosk' is passed into the function as a tuple. The solution is to specify kiosk[0].