GORM Playground Link
https://github.com/go-gorm/playground/pull/1
Description
mysql 5.6
code
type JdGoods struct {
Id int `gorm:"column:id" db:"id" json:"id" form:"id"`
Skuid int64 `gorm:"column:skuId" db:"skuId" json:"skuId" form:"skuId"`
ShorturlX7 string `gorm:"column:shorturl_x7" db:"shorturl_x7" json:"shorturl_x7" form:"shorturl_x7"`
}
func UpdateColumnBySKU(sku int64, column string, value interface{}) {
Conn.Model(&JdGoods{}).Where(" skuId = ?", sku).Update(column, value)
}
g:=JdGoods{}
g.UpdateColumnBySKU(100031601832,"shorturl_x7","https://union-click.jd.com/jdc?e=&p=JF8BANQJK1olVA8EVl5dDEwfM28JGloXXQEDVFdfC3tTXDdWRGtMGENDFlVDFhNSVzMXQA4KD1heSl5cCUoVA2gJG1IXXhlbEQIAOEMUACRJHDocOAJWBlwKexJSCxt0XSsZUTYHVF9cCU8XCmYBK1gUXQYDVFlaC0snM28NKw17XQcDVV9cCE4WAF8JK1sSWAYLVFpeAEoWAmg4G1MRbURKABsJVEpCUyc4K2sWbTYyVG5eOBV5AjwIGw8QD1FsDhZUVBxKWi5mG10SXAcGUVZfOEkWAm0KKw")
error log
2022/01/10 19:48:10 /source/db/JdGoods.go:105 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 '?' at line 1
[1.708ms] [rows:0] UPDATE `jd_goods` SET `shorturl_x7`='https://union-click.jd.com/jdc?e=&p=JF8BANQJK1olVA8EVl5dDEwfM28JGloXXQEDVFdfC3tTXDdWRGtMGENDFlVDFhNSVzMXQA4KD1heSl5cCUoVA2gJG1IXXhlbEQIAOEMUACRJHDocOAJWBlwKexJSCxt0XSsZUTYHVF9cCU8XCmYBK1gUXQYDVFlaC0snM28NKw17XQcDVV9cCE4WAF8JK1sSWAYLVFpeAEoWAmg4G1MRbURKABsJVEpCUyc4K2sWbTYyVG5eOBV5AjwIGw8QD1FsDhZUVBxKWi5mG10SXAcGUVZfOEkWAm0KKw' WHERE skuId = 100031601832
mysql error log
UPDATE `jd_goods` SET `shorturl_x7`='https://union-click.jd.com/jdc100031601832e=&p=JF8BANQJK1olVA8EVl5dDEwfM28JGloXXQEDVFdfC3tTXDdWRGtMGENDFlVDFhNSVzMXQA4KD1heSl5cCUoVA2gJG1IXXhlbEQIAOEMUACRJHDocOAJWBlwKexJSCxt0XSsZUTYHVF9cCU8XCmYBK1gUXQYDVFlaC0snM28NKw17XQcDVV9cCE4WAF8JK1sSWAYLVFpeAEoWAmg4G1MRbURKABsJVEpCUyc4K2sWbTYyVG5eOBV5AjwIGw8QD1FsDhZUVBxKWi5mG10SXAcGUVZfOEkWAm0KKw' WHERE skuId = ?
the shorturl_x7 had a "?" symbol , when execute the sql query Ideally, replace skuId ,but replace ..ck.jd.com/jdc?e=&p=JF8B... this point
and whe i use this code ,have same error
Conn.Model(&JdGoods{}).Where("skuId = ?", g.Skuid).Updates(&g)
Conn.Model(&JdGoods{}).Where(" skuId = @sku", sql.Named("sku", sku)).Update(column, value)
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨