From 71def3bd0378fb1fe09845023b3785de9d4cdf93 Mon Sep 17 00:00:00 2001 From: what-00 Date: Thu, 13 Apr 2023 09:51:05 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E6=96=B0=E5=A2=9E=20MysqlRealEscapeSt?= =?UTF-8?q?ring=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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() +}