2012-03-26 2 views
1

SQL 문 수행을 시도하고 인코딩 문제가 발생했습니다. 이스케이프하고 인코딩 한 후 식별 할 수없는 구문 오류를 반환합니다.Python에서 Mysqldb를 사용하여 대형 SQL 문에서 Econding/char 이스케이프 처리

문은 다음 코드에 의해 형성된다 :

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") 

:

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) 

과 내가 오류이 하나입니다

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)) 

실행 인쇄이 (가) 다음 반환 큰 문자열의 쉼표가 SQL 구문에 영향을 미칠 수 있음을 알고 있지만 쉼표 대신 그것은 쿼리 실행에 영향을 미치지 않는 것 같습니다. 이것은 매우 간단합니다,하지만 웹 (어쩌면 내가 잘 검색되지 않는 경우)

답변

0

문자열이 그들 주위에 ''이 있어야 미리 감사에 어떤 답을 찾을 수없는 경우

죄송합니다 , 가지고 있어야합니다

Values (80547,'Gossip Girl','http://imdb.com/title/tt0397442,http://www.thetvdb.com/banners/posters/80547-6.jpg', etc 
+0

감사합니다 Niek de Klein! 나는 그것으로 주위를 어지럽 혔지만, 나는 SQL 문을 쓰는 데별로 익숙하지 않다. –

관련 문제