2016-12-16 57 views
0

我想在以後的查詢中使用sqlite查詢的結果。在下面的代碼中,請注意exam [1]是一個字符串,'endtime'打印正確。但是,我似乎無法將它傳遞給db.execute語句。更麻煩的是,如果我從python命令行執行相同的操作(將endtime設置爲字符串並調用db.execute語句),它將按預期工作。任何關於我失蹤的想法。如何將datetime傳遞到sqlite

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. 

回答

0

我想我已經想通了。我錯過了「參數0」位。時間的事情原來是一個紅鯡魚。這裏的問題是'kiosk'作爲一個元組傳遞給函數。解決方案是指定kiosk [0]。