本文介绍了如何逃避回壁虱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MySQL 要求对隐藏保留字的表进行回勾.我有一个表角色,它是一个保留字,但我已经把我的查询放在了反引号中,这样我就可以把它写在多行上(这是一个玩具查询,大的查询不适合一行).
MySQL requires tables that shadow reserved words to be back ticked. I have a table Role which is a reserved word, but I have already put my query in back ticks so I can write it over multiple lines (this is a toy query, large ones will not fit on one line).
我如何逃避回勾?
这是我的代码:
dbmap := db.InitDb()
var roles []entities.Role
query :=
` << Difficult to see with SO's code editor widget, but here is a back tick
SELECT *
FROM `Role` <<< Needs escaping
` << Difficult to see, but here is a back tick
_, err := dbmap.Select(&roles, query, nil)
if err != nil {
panic(err)
}
fmt.Println(roles)
推荐答案
你不能在反引号内转义反引号,但你可以这样做:
You cannot escape backticks inside backticks, but you can do:
dbmap := db.InitDb()
var roles []entities.Role
query := `
SELECT *
FROM ` + "`Role`"
_, err := dbmap.Select(&roles, query, nil)
if err != nil {
panic(err)
}
fmt.Println(roles)
这篇关于如何逃避回壁虱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!