如何逃避s虫 [英] How to escape back ticks

查看:32
本文介绍了如何逃避s虫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MySQL要求对带有阴影的保留字的表进行打勾.我有一个表Role(表角色),它是一个保留字,但是我已经将查询放在后面的刻度中,因此可以在多行中写出来(这是一个玩具查询,大的查询不能放在一行上).

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

如何摆脱背escape?

How do I escape the back ticks?

这是我的代码:

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)

这篇关于如何逃避s虫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆