django中使用SQL原生语句如何动态插入变量
高洛峰
高洛峰 2016-11-14 10:42:15
0
1
1084

我用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  ,请问如何解决~!

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

répondre à tous(1)
三叔

bVFns2.png

用%s格式化query语句

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!