我试图执行一条SQL语句,但遇到了一些编码问题。对其进行转义和编码后,它会返回一个我无法识别的语法错误。
该语句由以下代码构成:
dbquery = "INSERT INTO series (id,nombreSerie,imdbUrl,urlPoster,descripcionEs,descripcionEn,rating,episodiosEn,episodiosEs,estado,firstAired,airDay,Network) VALUES (" + t['gossip girl']['id']+ "," + t['gossip girl']['seriesname'] + ',http://imdb.com/title/' + t['gossip girl']['imdb_id'] + "," + t['gossip girl']['poster'] + "," + t['gossip girl']['overview'][:400] + "... ,"+ t['gossip girl']['overview'][:400] + "... ," + t['gossip girl']['rating'] + "," + total + "," + total + "," + t['gossip girl']['status'] + "," + t['gossip girl']['firstaired'] + "," + t['gossip girl']['airs_dayofweek'] + "," + t['gossip girl']['network']+")"
cursor.execute (MySQLdb.escape_string(dbquery))打印执行将返回以下内容:
print MySQLdb.escape_string(dbquery)
INSERT INTO series (id,nombreSerie,imdbUrl,urlPoster,descripcionEs,descripcionEn,rating,episodiosEn,episodiosEs,estado,firstAired,airDay,Network) VALUES (80547,Gossip Girl,http://imdb.com/title/tt0397442,http://www.thetvdb.com/banners/posters/80547-6.jpg,Gossip Girl satirizes and revolves around the lives of young Manhattan socialites growing up on New York City\'s Upper East Side who attend elite academic institutions while dealing with sex, drugs, jealousy, and other teenage issues.... ,Gossip Girl satirizes and revolves around the lives of young Manhattan socialites growing up on New York City\'s Upper East Side who attend eliteacademic institutions while dealing with sex, drugs, jealousy, and other teenage issues.... ,8.1,0x11|1x18|2x25|3x22|4x22|5x24|,0x11|1x18|2x25|3x22|4x22|5x24|,Continuing,2007-09-19,Monday,The CW)我得到的错误是这样的:
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in default errorhandler raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (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 'Girl,http://imdb.com/title/tt0397442,http://www.thetvdb.com/banners/posters/8054' at line 1")我知道大字符串上的逗号可能会影响sql语法,但我已经替换了逗号,它似乎不会影响查询的执行。
抱歉,如果这是非常简单的,但我还没有在网上找到任何答案(可能我没有搜索好)
提前谢谢你
发布于 2012-03-26 23:37:31
字符串必须包含'‘,您应该有
Values (80547,'Gossip Girl','http://imdb.com/title/tt0397442,http://www.thetvdb.com/banners/posters/80547-6.jpg', etchttps://stackoverflow.com/questions/9875062
复制相似问题