このメソッドはテーブルを更新する必要がありますが、最後の行で操作上の sql エラーが発生します。
def update_lookup(table, lookup_table, anon_table, fieldname, anon_field_prefix):
c.execute('SELECT DISTINCT ' + fieldname + ' FROM ' + table)
result = c.fetchall() #gives a list of tuples
#get a list of random integers in range, as many as there are unique mssi's
rnds = random.sample(xrange(10000,80000),len(result))
#for every name insert the value in the vesselname lookup
lst = []
lst_rev = []
for i,row in enumerate(result):
field_value_anon = anon_field_prefix + str(rnds[i]) #create a random mssi number
field_value = row[0]
lst_rev.append((anon_table, fieldname , field_value_anon, fieldname, field_value)) #needed later on
lst.append((field_value, field_value_anon))
c.executemany('INSERT INTO '+ lookup_table +' VALUES (null, ?, ?)', lst)
#update the anon table col:
c.executemany('UPDATE ? SET ?=? WHERE ?=?', lst_rev) //error is trhown
スタックトレース:
Traceback (most recent call last):
File "C:\Users\jgoddijn\workspace\DataAnonDMVV\src\Main.py", line 119, in <module>
update_lookup('AIS', 'MMSI_lookup', 'AIS_anoniem', 'dad_vesselname', 'AIS_schip')
File "C:\Users\jgoddijn\workspace\DataAnonDMVV\src\Main.py", line 35, in update_lookup
c.executemany('UPDATE ? SET ?=? WHERE ?=?', lst_rev)
sqlite3.OperationalError: near "?": syntax error
タプルの挿入に何か問題がありますが、何がわかりません!
本当にありがとう!