【发布时间】:2014-02-07 06:28:52
【问题描述】:
我正在为这段代码苦苦挣扎:
addXml = '<bar><foo>thingy</foo></bar>'
sql = 'INSERT INTO table(col1,col2) VALUES(%s,%s);'
try:
cursor = cnx.cursor()
cursor.execute(sql, ('some_text', addXml))
cursor.close()
except Exception, e:
print cursor._last_executed
print e
在我的每个 SQL 请求中,都会出现这个错误:
(1241, 'Operand should contain 1 column(s)')
我发现 cursor.execute 将我的 sql 请求修改为:
INSERT INTO table(col1,col2) VALUES('some_text',("'<bar><foo>thingy</foo></bar>'"));
而不是
INSERT INTO table(col1,col2) VALUES('some_text','<bar><foo>thingy</foo></bar>');
我相信 cursor.execute 正在添加分隔符 ("")。
我怎样才能消除这种行为?或者我该怎么办?
python version : 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2]
谢谢
【问题讨论】:
标签: python sql python-2.7 mysql-python