Code

client: Added support for querying the server version.
[sysdb/go.git] / proto / proto.go
index 91e21122b82ac5013d7bc90bbbe933d7ade4dbd1..a58725d6f81a6c7ad451390974e311b63a08b0f7 100644 (file)
@@ -33,6 +33,7 @@ import (
        "encoding/json"
        "fmt"
        "io"
+       "strings"
 )
 
 // Network byte order.
@@ -79,8 +80,13 @@ const (
        // 'TIMESERIES' command in the server.
        ConnectionTimeseries = Status(7)
 
-       // ConnectionExpr is the internal state for expression parsing.
-       ConnectionExpr = Status(100)
+       // ConnectionMatcher is the internal state for parsing matchers.
+       ConnectionMatcher = Status(100)
+       // ConnectionExpr is the internal state for parsing expressions.
+       ConnectionExpr = Status(101)
+
+       // ConnectionServerVersion is the state requesting the server version.
+       ConnectionServerVersion = Status(1000)
 )
 
 // The DataType describes the type of data in a ConnectionData message.
@@ -176,4 +182,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 :