From c81695bc6081eca14767d47315cf91f6e1979d8b Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Thu, 20 Nov 2014 22:05:24 +0100 Subject: [PATCH] proto: Added EscapeString(). This function may be used to escape and quote a string suitable for use in a query. --- proto/proto.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proto/proto.go b/proto/proto.go index ee47fcf..5e93e47 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -33,6 +33,7 @@ import ( "encoding/json" "fmt" "io" + "strings" ) // Network byte order. @@ -178,4 +179,12 @@ func Unmarshal(m *Message, v interface{}) error { return json.Unmarshal(m.Raw[4:], v) } +// EscapeString returns the quoted and escaped string s suitable for use +// in a query. +func EscapeString(s string) string { + // Currently, the server only handles double-quotes. + // Backslashes do not serve any special purpose. + return "'" + strings.Replace(s, "'", "''", -1) + "'" +} + // vim: set tw=78 sw=4 sw=4 noexpandtab : -- 2.30.2