From ccc65c361aa0f5fe060cbfacdf9e1f5a5fe2564f Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 16 Feb 2017 18:26:24 -0600 Subject: [PATCH] Privatize Conn.SecretKey --- conn.go | 6 +++--- conn_test.go | 4 ---- v3.md | 4 +++- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/conn.go b/conn.go index 88c344f4..4a0b6fda 100644 --- a/conn.go +++ b/conn.go @@ -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 diff --git a/conn_test.go b/conn_test.go index 9a703bbd..cc87efa8 100644 --- a/conn_test.go +++ b/conn_test.go @@ -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(¤tDB) if err != nil { diff --git a/v3.md b/v3.md index 89a080b2..4663cfd9 100644 --- a/v3.md +++ b/v3.md @@ -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).