我有这个查询
self.cursor.execute("""INSERT IGNORE INTO
groups
(
name,
builder_id,
content,city,
location,price,
target,
project_completion,
creator_id,verified,
live,
updater_id,
verify_id
)
VALUES
(
%s,
%s,
%s,
%s,
%s,
%s,
%s,
'30',
'4',
'1',
'1',
'4',
'4'
);""",
(
item['name'],
builder_id,
item['content'],
item['city'],
item['address'],
item['price'],
item['possession_date']
)
)
我正在使用Scrapy抓取一些数据并放入一个mysql数据库。 我一直在收到语法错误
回溯
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 '),
18,
("'friend' at line 19
18是builder_id和friend ...是内容字段的开头 任何帮助??
答案 0 :(得分:-1)
execute()方法只占用1个单一参数。
cursor.execute('insert into a ("a", "b") values (1,2)')
所以,不应该是''在你的参数中。你可以试试这个
self.cursor.execute("""INSERT IGNORE INTO
groups
(
name,
builder_id,
content,city,
location,price,
target,
project_completion,
creator_id,verified,
live,
updater_id,
verify_id
)
VALUES
(
%s,
%s,
%s,
%s,
%s,
%s,
%s,
'30',
'4',
'1',
'1',
'4',
'4'
);""" % (
item['name'],
builder_id,
item['content'],
item['city'],
item['address'],
item['price'],
item['possession_date']
)
)