#endcding=utf-8
import MySQLdb
conn = MySQLdb.connect{
host='localhost'
port=3306,
user='root',
passwd='admin
db='db01',
charset='utf8
)
cur = conn.cursor()
count = cur.execute("select * from t_r_def_audit")
results = cur.fetchmany(count)
provcode = cur.execute("select * from t_r_params where
param_tag='PROVINCE_CODE' and param_code not in(1,95,99)")
provResults = cur.fetchmany(provcode)
i = 0
sql = "insert into ti_r_audit values({0},{1},{2},{3})"
values = "["
for result in results:
i = i+1
prev = result[8]
audit_id = result[0]
if(prev == "1"):
prov = 31
for index in range(prov):
values =values + "("+str(i)+","+audit_id+",'"+provResults[index]
[0]+"',0),"
i = i+1
elif prev=="0":
values =values + "("+str(i)+","+audit_id+",'"+provResults[31][0]+"',0),"
values = values + "]"
cur.executemany(sql,values)
cur.close
conn.commit()
conn.close()
手動でSQLのexecutableemany実装で、SQLのパラメータをステッチが、スクリプトの実行後にpython2.7の例外TypeError:文字列中に変換すべての引数が
を次のように エラーがあると報告されるのフォーマットではありませんλ python audit.py
Traceback (most recent call last):
File "audit.py", line 34, in <module>
cur.executemany(sql,values)
File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 255, in
executemany
self.errorhandler(self, TypeError, msg)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in
defaulterrorhandler
raise errorclass, errorvalue
TypeError: not all arguments converted during string formatting
は、独自のマニュアルのパラメータを記述し、スクリプトは問題になりませんことを示す、間違いを発見していない、問題は、スプライシングSQLパラメータであってもよいが、問題
あなたは明確に壊れている投稿したコードを実行する前に、構文ハイライトを見てください。それを[mcve]に切り捨ててください – jonrsharpe