我用python写了一段代码用于批量插入数据库出错,如何解决,伪代码:
from django.db import connection
...
cursor = connection.cursor()
cursor.execute("Insert into api_coupon(Quan_surplus,Quan_receive,) values ("+d['Quan_surplus']+","+d['Quan_receive']+") on duplicate key update Quan_receive="+d['Quan_receive']+",Quan_surplus="+d['Quan_surplus'])
cursor.close()
...
请教下
1、以上sql语句中变量的拼接是否正确,如果不正确该如何拼接
2、错误提示TypeError: coercing to Unicode: need string or buffer, int found ,请问如何解决~!
用%s格式化query语句