Parse ParameterStatus

pgx-vs-pq
Jack Christensen 2013-03-30 20:28:23 -05:00
parent 226142ae1b
commit aefc85a67b
2 changed files with 38 additions and 1 deletions

29
conn.go
View File

@ -1,6 +1,8 @@
package pqx
import (
"bufio"
"bytes"
"encoding/binary"
"errors"
"fmt"
@ -39,6 +41,16 @@ func Connect(options map[string]string) (c *conn, err error) {
fmt.Println(err)
fmt.Println(response)
for {
response, err = c.rxMsg()
if err != nil {
break
}
fmt.Println(response)
}
fmt.Println(err)
return c, nil
}
@ -58,8 +70,10 @@ func (c *conn) rxMsg() (msg interface{}, err error) {
switch t {
case 'R':
return c.rxAuthenticationX(buf)
case 'S':
return c.rxParameterStatus(buf)
default:
return nil, errors.New("Received unknown message type")
return nil, fmt.Errorf("Received unknown message type: %c", t)
}
panic("Unreachable")
@ -98,3 +112,16 @@ func (c *conn) rxAuthenticationX(buf []byte) (msg interface{}, err error) {
panic("Unreachable")
}
func (c *conn) rxParameterStatus(buf []byte) (msg *parameterStatus, err error) {
msg = new(parameterStatus)
r := bufio.NewReader(bytes.NewReader(buf))
msg.name, err = r.ReadString(0)
if err != nil {
return
}
msg.value, err = r.ReadString(0)
return
}

View File

@ -2,6 +2,7 @@ package pqx
import (
"encoding/binary"
"fmt"
)
const (
@ -36,3 +37,12 @@ type authenticationOk struct {
func (self *authenticationOk) String() string {
return "AuthenticationOk"
}
type parameterStatus struct {
name string
value string
}
func (self *parameterStatus) String() string {
return fmt.Sprintf("ParameterStatus %s: %s", self.name, self.value)
}