From d4a300bd5836e85c85ca3976e1c8f138c4a6eb99 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 5 Sep 2020 13:24:57 -0500 Subject: [PATCH] Fix: FieldDescriptions are available on Rows before calling Next --- go.mod | 2 +- go.sum | 2 ++ query_test.go | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 14003102..074701dd 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.12 require ( github.com/cockroachdb/apd v1.1.0 github.com/gofrs/uuid v3.2.0+incompatible - github.com/jackc/pgconn v1.6.5-0.20200821030840-fdfc783345f6 + github.com/jackc/pgconn v1.6.5-0.20200905181414-0d4f029683fc github.com/jackc/pgio v1.0.0 github.com/jackc/pgproto3/v2 v2.0.4 github.com/jackc/pgtype v1.4.3-0.20200905161353-e7d2b057a716 diff --git a/go.sum b/go.sum index a511f139..8d628550 100644 --- a/go.sum +++ b/go.sum @@ -44,6 +44,8 @@ github.com/jackc/pgconn v1.6.5-0.20200821030021-3eb5432c4738 h1:t/IRFEw2da5v6Dro github.com/jackc/pgconn v1.6.5-0.20200821030021-3eb5432c4738/go.mod h1:gm9GeeZiC+Ja7JV4fB/MNDeaOqsCrzFiZlLVhAompxk= github.com/jackc/pgconn v1.6.5-0.20200821030840-fdfc783345f6 h1:7f1RmJO6KZI4cskLrNHBd5CCLmLpIQ0BD75hsorvdz8= github.com/jackc/pgconn v1.6.5-0.20200821030840-fdfc783345f6/go.mod h1:gm9GeeZiC+Ja7JV4fB/MNDeaOqsCrzFiZlLVhAompxk= +github.com/jackc/pgconn v1.6.5-0.20200905181414-0d4f029683fc h1:9ThyBXKdyBFN2Y1NSCPGCA0kdWCNpd9u4SKWwtr6GfU= +github.com/jackc/pgconn v1.6.5-0.20200905181414-0d4f029683fc/go.mod h1:gm9GeeZiC+Ja7JV4fB/MNDeaOqsCrzFiZlLVhAompxk= github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2 h1:JVX6jT/XfzNqIjye4717ITLaNwV9mWbJx0dLCpcRzdA= diff --git a/query_test.go b/query_test.go index 556fecef..c850b5fe 100644 --- a/query_test.go +++ b/query_test.go @@ -59,6 +59,20 @@ func TestConnQueryScan(t *testing.T) { } } +func TestConnQueryRowsFieldDescriptionsBeforeNext(t *testing.T) { + t.Parallel() + + conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) + defer closeConn(t, conn) + + rows, err := conn.Query(context.Background(), "select 'hello' as msg") + require.NoError(t, err) + defer rows.Close() + + require.Len(t, rows.FieldDescriptions(), 1) + assert.Equal(t, []byte("msg"), rows.FieldDescriptions()[0].Name) +} + func TestConnQueryWithoutResultSetCommandTag(t *testing.T) { t.Parallel()