Privatize Conn.SecretKey

v3-experimental
Jack Christensen 2017-02-16 18:26:24 -06:00
parent e390ac33f5
commit ccc65c361a
3 changed files with 6 additions and 8 deletions

View File

@ -74,7 +74,7 @@ type Conn struct {
wbuf [1024]byte
writeBuf WriteBuf
pid int32 // backend pid
SecretKey int32 // key to use to send a cancel query message to the server
secretKey int32 // key to use to send a cancel query message to the server
RuntimeParams map[string]string // parameters that have been reported by the server
PgTypes map[OID]PgType // oids to PgTypes
config ConnConfig // config used when establishing this connection
@ -1148,7 +1148,7 @@ func (c *Conn) rxErrorResponse(r *msgReader) (err PgError) {
func (c *Conn) rxBackendKeyData(r *msgReader) {
c.pid = r.readInt32()
c.SecretKey = r.readInt32()
c.secretKey = r.readInt32()
}
func (c *Conn) rxReadyForQuery(r *msgReader) {
@ -1321,7 +1321,7 @@ func (c *Conn) cancelQuery() {
binary.BigEndian.PutUint32(buf[0:4], 16)
binary.BigEndian.PutUint32(buf[4:8], 80877102)
binary.BigEndian.PutUint32(buf[8:12], uint32(c.pid))
binary.BigEndian.PutUint32(buf[12:16], uint32(c.SecretKey))
binary.BigEndian.PutUint32(buf[12:16], uint32(c.secretKey))
_, err = cancelConn.Write(buf)
if err != nil {
return err

View File

@ -32,10 +32,6 @@ func TestConnect(t *testing.T) {
t.Error("Backend PID not stored")
}
if conn.SecretKey == 0 {
t.Error("Backend secret key not stored")
}
var currentDB string
err = conn.QueryRow("select current_database()").Scan(&currentDB)
if err != nil {

4
v3.md
View File

@ -18,6 +18,8 @@ Transaction isolation level constants are now typed strings instead of bare stri
Conn.Pid changed to accessor method Conn.PID()
Conn.SecretKey removed
Remove Conn.TxStatus
Added Context methods
@ -50,7 +52,7 @@ dValueReader / msgReader cleanup
Make easier / possible to mock Conn or ConnPool (https://github.com/jackc/pgx/pull/162)
Every field that should not be set by user should be replaced by accessor method (e.g. Conn.PID, Conn.SecretKey)
Every field that should not be set by user should be replaced by accessor method (only ones left are Conn.RuntimeParams and Conn.PgTypes)
Investigate strongly typed queries. i.e. Some sort of interface where varargs of Query, Exec, and Scan wouldn't happen. Need to be some low-level interface where (probably generated) functions could (more or less) directly read and write to the connection. Clean code and type-safety / control would be the benefits. Row scanning performance is already so fast there is little to improve (go_db_bench shows under 1 microsecond per row).