当前位置: 首页 >数据库 > pymysql 1064, 'You have an error in your SQL syntax; check the manual that corresponds to

pymysql 1064, 'You have an error in your SQL syntax; check the manual that corresponds to

在python 连接mysql时,最近一直出现了 

1064, 'You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near \'"58 convenience stores in Beijing Pilot selling class B over-the-counter drugs""\' at line 4'
这个异常信息,今早发现后就进行解决,尝试了多种方式,google提示用pymysql.escape_string函数对参数防止转义,最开始用的是{0} 这种占位符的方式,发现还是无法解决,后面还试了一种方式,在execute里面处理
sql_01 = '''  insert into cmstop_content(contentid,catid,modelid,title, tags,status,published,publishedby  ,createdby,created,modifiedby,modified,sourceid,score)  values (null,%s,"1",%s,%s,'3',UNIX_TIMESTAMP(SYSDATE()),'28','28',UNIX_TIMESTAMP(SYSDATE()),'28',UNIX_TIMESTAMP(SYSDATE()),'21','0');

  在execute的时候进行参数传递,可以正常入库了

  cur.execute(sql_01, (pymysql.escape_string(info["flag"]), pymysql.escape_string(info["标题"]),  pymysql.escape_string(info["标签"])))

  以前都是将参数与sql处理好一起传入excute,没怎么用过在execute中传递参数,特意看了下execute的定义,args的类型可以是tuple,list,dict中的任何一种,如果参数类型不对,会出现如下提示:

execute() takes from 2 to 3 positional arguments but 5 were given

 

 

 pymysql1064, 'You have an error in your SQL syntax; check the manual that corresponds to _ JavaClub全栈架构师技术笔记

 

 

作者:kakaok
来源链接:https://www.cnblogs.com/fly-kaka/p/11896470.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/database/117512.html

标签:SQL_syntax
分享给朋友:

“pymysql 1064, 'You have an error in your SQL syntax; check the manual that corresponds to” 的相关文章

触发器的定义及优点 2022年05月21日 11:37:15
MySQL 查询指定时间范围内的数据 2022年06月06日 16:59:25
MYSQL查询某字段为空的数据 2022年06月08日 21:35:13
MYSQL查询一个月前的数据 2022年06月12日 09:48:55
mysql 查询某字段最小的记录 2022年06月12日 13:41:31
MySQL基本查询 2022年06月15日 12:06:53
Mysql区间查询的注意点 2022年06月19日 14:49:56