-2

我正在尝试更新 MySQL DB 中的数据,但它抛出错误:

UPDATE scrapedDataTable  SET productDesc=, 
                            moreProductImages=full/545521_1363869251%20copy-500x500.jpg,full/545521_1363869251%20copy-275x275.jpg,full/545522_1363869309%20copy-500x500.jpg,full/545522_1363869309%20copy-74x74.jpg, ,productCategory=Clothing, 
                            productSubCategory=NA  WHERE Server=http://1click1call.com/Jeans-Shirts-Tshirts-Trousers/W-for-Woman-Kurta-54552


And 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 'moreProductImages=full/545521_1363869251%20copy-500x500.jpg,full/545521_13638692' at line 1")
"(<class '_mysql_exceptions.ProgrammingError'>)"

我的表结构是:

+--------------------+---------------+------+-----+---------+-------+
| Field              | Type          | Null | Key | Default | Extra |
+--------------------+---------------+------+-----+---------+-------+
| productTitle       | varchar(100)  | NO   |     | NULL    |       |
| productSite        | varchar(1000) | NO   |     | NULL    |       |
| productDesc        | text          | YES  |     | NULL    |       |
| productURL         | varchar(325)  | NO   | PRI | NULL    |       |
| productMRP         | varchar(200)  | YES  |     | NULL    |       |
| productPrice       | varchar(200)  | YES  |     | NULL    |       |
| productCategory    | varchar(50)   | YES  |     | NULL    |       |
| productSubCategory | varchar(50)   | YES  |     | NULL    |       |
| imageURL           | text          | YES  |     | NULL    |       |
| moreProductImages  | text          | YES  |     | NULL    |       |
+--------------------+---------------+------+-----+---------+-------+

询问 :

cursor.execute("UPDATE scrapedDataTable  SET productDesc=%s,moreProductImages='%s', ,productCategory=%s, productSubCategory=%s  WHERE productURL=%s" %(productDesc,image_paths,productCategory,productSubCategory,productURL))

有人可以帮我吗...

4

1 回答 1

1

你的 SQL 应该是:

UPDATE scrapedDataTable  SET productDesc='', 
                            moreProductImages='full/545521_1363869251%20copy-500x500.jpg,full/545521_1363869251%20copy-275x275.jpg,full/545522_1363869309%20copy-500x500.jpg,full/545522_1363869309%20copy-74x74.jpg, ',productCategory='Clothing', 
                            productSubCategory='NA'  WHERE Server='http://1click1call.com/Jeans-Shirts-Tshirts-Trousers/W-for-Woman-Kurta-54552'

等等。您的主键是一个长 URL 字符串?真的吗 ?最好使用诸如整数之类的短键来保持表的良好索引。

问题更新后更新:该行应该是:

cursor.execute("UPDATE scrapedDataTable  SET productDesc='%s',moreProductImages='%s', ,productCategory='%s', productSubCategory='%s'  WHERE productURL='%s'" %(productDesc,image_paths,productCategory,productSubCategory,productURL))
于 2013-05-27T09:55:46.860 回答