scrapy链式查询无法正常工作

时间:2013-11-28 13:49:47

标签: mysql scrapy

我有代码

def process_item(self, item, spider):
    print "about to go deep!"*50
    try:
        self.cursor.execute("""INSERT IGNORE INTO builders (name,creator_id,verified,live,updater_id,verify_id) 
                        VALUES (%s,'4','1','1','4','4');""", 
                       (item['builder'])
        )

        self.conn.commit()
        print ("Item stored in db: %s" % item)

    except MySQLdb.Error, e:
        print "oh! shit"*50
        print "Error %d: %s" % (e.args[0], e.args[1])

    try:
        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,(select id from builders where name=%s),%s,%s,%s,%s,'30',%s,'4','1','1','4','4');""", 
                       (item['name'],item['builder'],item['content'],item['city'],item['address'],item['price'],item['possession_date'])
        )

        self.conn.commit()
        print ("Item stored in db: %s" % item)

    except MySQLdb.Error, e:
        print "oh! shit"*50
        print "Error %d: %s" % (e.args[0], e.args[1])

    return item

中文查询

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,(select id from builders where name=%s),%s,%s,%s,%s,'30',%s,'4','1','1','4','4');""", 
               (item['name'],item['builder'],item['content'],item['city'],item['address'],item['price'],item['possession_date'])
)

self.conn.commit()

不起作用,它在

处断开
VALUES (%s,(select id from builders where name=%s),%s,%s,

给出错误

    Error 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 '),(select id from builders 
where name=("'******'",)),("'***********' at line 2

任何帮助??

0 个答案:

没有答案