[feat] 新增 MysqlRealEscapeString 方法

This commit is contained in:
what-00 2023-04-13 09:51:05 +08:00
parent 59b3faa171
commit 71def3bd03

18
util.go
View File

@ -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()
}