From: Sebastian Harl Date: Thu, 20 Nov 2014 21:05:24 +0000 (+0100) Subject: proto: Added EscapeString(). X-Git-Url: https://git.tokkee.org/?p=sysdb%2Fgo.git;a=commitdiff_plain;h=c81695bc6081eca14767d47315cf91f6e1979d8b proto: Added EscapeString(). This function may be used to escape and quote a string suitable for use in a query. --- 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 :