diff --git a/util.go b/util.go index 2164f37..09f7c45 100644 --- a/util.go +++ b/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() +}