[feat] 新增 MysqlRealEscapeString 方法
This commit is contained in:
parent
59b3faa171
commit
71def3bd03
18
util.go
18
util.go
@ -75,3 +75,21 @@ func Stripslashes(str string) string {
|
||||
}
|
||||
return string(dstRune)
|
||||
}
|
||||
|
||||
func MysqlRealEscapeString(value string) string {
|
||||
var sb strings.Builder
|
||||
for i := 0; i < len(value); i++ {
|
||||
c := value[i]
|
||||
switch c {
|
||||
case '\\', 0, '\n', '\r', '\'', '"':
|
||||
sb.WriteByte('\\')
|
||||
sb.WriteByte(c)
|
||||
case '\032':
|
||||
sb.WriteByte('\\')
|
||||
sb.WriteByte('Z')
|
||||
default:
|
||||
sb.WriteByte(c)
|
||||
}
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user