2016-07-14 8 views
0

エラー:のPython 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'と一緒に働くのか? Pythonはそれを暗黙のうちにリストに変更しましたか? –

関連する問題