2016-07-14 3 views
0

오류 :파이썬 3.5 sqlite3를 전달하는 매개 변수 - 공급 바인딩의 잘못된 수

c = dbConnection.execute("SELECT compid FROM " + tableToUse + " WHERE id = ?", id) sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied.

내가 할 경우 :

def getcompid (dbConnection, tableToUse, id): 
    c = dbConnection.execute("SELECT compid FROM " + tableToUse + " WHERE id = ?", id) 

manualcompid = [('8','from01'),('35','28')] 
for manid in manualcompid: 

    ERROR: 
    foundid = getcompid (dbConnection, tableToUse, manid[0]) 

    OR SAME ERROR: 

    r = str(manid[0]) 
    foundid = getcompid (dbConnection, tableToUse, r) 


    THE BELOW IS FINE: 
    foundid = getcompid (dbConnection, tableToUse, '8') 

그것은 '간단한'로 string 동일해야 나 r에 솔기 8 '및 more manid[0]은 이미 문자열입니다. 왜 오류가 있습니까?

왜 사용해야합니까 : foundid = getcompid (dbConnection, tableToUse, (manid[0],))?

답변

1

바인딩은 목록 또는 튜플에 있어야합니다. 사용해보기 :

c = dbConnection.execute(
    "SELECT compid FROM " + tableToUse + " WHERE id = ?", [id]) 
+0

감사합니다. 내 질문은 그 때 '8'과 함께 작동하는 이유는 무엇입니까? 파이썬은 그것을 암시 적으로 목록에 추가했습니다. –