【发布时间】:2014-09-26 10:46:47
【问题描述】:
根据此处找到的示例进行代码设置:
for ICAO_COUNTRY in ['GM','DA','DT']:
table='aerodrome'
query = 'delete from %s where code_icao regexp "%s[A-Z][A-Z]"'
cursor.execute(query,(table,ICAO_COUNTRY))
给出答案
Traceback (most recent call last):
File "bin/cleanup2", line 22, in <module>
cursor.execute(query,(table,ICAO_COUNTRY))
File "/usr/lib/python2.7/dist-packages/mysql/connector/cursor.py", line 491, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "/usr/lib/python2.7/dist-packages/mysql/connector/connection.py", line 635, in cmd_query statement))
File "/usr/lib/python2.7/dist-packages/mysql/connector/connection.py", line 553, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): 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 ''aerodrome' where code_icao regexp "'GM'[A-Z][A-Z]"' at line 1
在我看来,单引号被转移到 MySql 引擎,这不是我想要的。
【问题讨论】: