summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 89bc879)
raw | patch | inline | side by side (parent: 89bc879)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 20 Nov 2014 21:05:24 +0000 (22:05 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 20 Nov 2014 21:05:24 +0000 (22:05 +0100) |
This function may be used to escape and quote a string suitable for use in a
query.
query.
proto/proto.go | patch | blob | history |
diff --git a/proto/proto.go b/proto/proto.go
index ee47fcfcf0442d78e4a89f076491bc629dc427da..5e93e472adbdb53c50c9bb0b10061dfeabec2419 100644 (file)
--- a/proto/proto.go
+++ b/proto/proto.go
"encoding/json"
"fmt"
"io"
+ "strings"
)
// Network byte order.
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 :