From 69434056c65891277f70fe8b30aca07fe95b56ad Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 7 Jan 2017 14:10:11 -0600 Subject: [PATCH] Remove Conn.TxStatus --- conn.go | 4 ++-- conn_pool.go | 2 +- conn_pool_test.go | 16 ++++++++-------- private_test.go | 7 +++++++ v3.md | 2 ++ 5 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 private_test.go diff --git a/conn.go b/conn.go index 72e9652c..75792408 100644 --- a/conn.go +++ b/conn.go @@ -53,7 +53,7 @@ type Conn struct { 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 - TxStatus byte + txStatus byte preparedStatements map[string]*PreparedStatement channels map[string]struct{} notifications []*Notification @@ -1150,7 +1150,7 @@ func (c *Conn) rxBackendKeyData(r *msgReader) { } func (c *Conn) rxReadyForQuery(r *msgReader) { - c.TxStatus = r.readByte() + c.txStatus = r.readByte() } func (c *Conn) rxRowDescription(r *msgReader) (fields []FieldDescription) { diff --git a/conn_pool.go b/conn_pool.go index 126d5b14..4bb64a24 100644 --- a/conn_pool.go +++ b/conn_pool.go @@ -181,7 +181,7 @@ func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) { // Release gives up use of a connection. func (p *ConnPool) Release(conn *Conn) { - if conn.TxStatus != 'I' { + if conn.txStatus != 'I' { conn.Exec("rollback") } diff --git a/conn_pool_test.go b/conn_pool_test.go index f6f166d8..0bbda0bc 100644 --- a/conn_pool_test.go +++ b/conn_pool_test.go @@ -328,14 +328,14 @@ func TestPoolReleaseWithTransactions(t *testing.T) { t.Fatal("Did not receive expected error") } - if conn.TxStatus != 'E' { - t.Fatalf("Expected TxStatus to be 'E', instead it was '%c'", conn.TxStatus) + if conn.TxStatus() != 'E' { + t.Fatalf("Expected TxStatus to be 'E', instead it was '%c'", conn.TxStatus()) } pool.Release(conn) - if conn.TxStatus != 'I' { - t.Fatalf("Expected release to rollback errored transaction, but it did not: '%c'", conn.TxStatus) + if conn.TxStatus() != 'I' { + t.Fatalf("Expected release to rollback errored transaction, but it did not: '%c'", conn.TxStatus()) } conn, err = pool.Acquire() @@ -343,14 +343,14 @@ func TestPoolReleaseWithTransactions(t *testing.T) { t.Fatalf("Unable to acquire connection: %v", err) } mustExec(t, conn, "begin") - if conn.TxStatus != 'T' { - t.Fatalf("Expected txStatus to be 'T', instead it was '%c'", conn.TxStatus) + if conn.TxStatus() != 'T' { + t.Fatalf("Expected txStatus to be 'T', instead it was '%c'", conn.TxStatus()) } pool.Release(conn) - if conn.TxStatus != 'I' { - t.Fatalf("Expected release to rollback uncommitted transaction, but it did not: '%c'", conn.TxStatus) + if conn.TxStatus() != 'I' { + t.Fatalf("Expected release to rollback uncommitted transaction, but it did not: '%c'", conn.TxStatus()) } } diff --git a/private_test.go b/private_test.go new file mode 100644 index 00000000..df732a72 --- /dev/null +++ b/private_test.go @@ -0,0 +1,7 @@ +package pgx + +// This file contains methods that expose internal pgx state to tests. + +func (c *Conn) TxStatus() byte { + return c.txStatus +} diff --git a/v3.md b/v3.md index 424635fc..ca13055f 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() +Remove Conn.TxStatus + ## TODO / Possible / Investigate Organize errors better