更新Mysq中的行

2024-09-26 18:12:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试更新MySQL数据库中的数据,但它引发错误:

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))

谁能帮帮我。。。你知道吗


Tags: notextmysqlupdatenullfullyesjpg
1条回答
网友
1楼 · 发布于 2024-09-26 18:12:23

您的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))

相关问题 更多 >

    热门问题