Test every QueryExecMode

query-exec-mode
Jack Christensen 2022-03-05 13:57:48 -06:00
parent aad3d65e16
commit 0d8e109c21
6 changed files with 118 additions and 120 deletions

17
conn.go
View File

@ -567,6 +567,23 @@ const (
QueryExecModeSimpleProtocol
)
func (m QueryExecMode) String() string {
switch m {
case QueryExecModeCacheStatement:
return "cache statement"
case QueryExecModeCacheDescribe:
return "cache describe"
case QueryExecModeDescribeExec:
return "describe exec"
case QueryExecModeExec:
return "exec"
case QueryExecModeSimpleProtocol:
return "simple protocol"
default:
return "invalid"
}
}
// QueryResultFormats controls the result format (text=0, binary=1) of a query by result column position.
type QueryResultFormats []int16

View File

@ -188,7 +188,7 @@ func TestParseConfigExtractsDefaultQueryExecMode(t *testing.T) {
func TestExec(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
if results := mustExec(t, conn, "create temporary table foo(id integer primary key);"); results.String() != "CREATE TABLE" {
t.Error("Unexpected results from Exec")
}
@ -222,7 +222,7 @@ func TestExec(t *testing.T) {
func TestExecFailure(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
if _, err := conn.Exec(context.Background(), "selct;"); err == nil {
t.Fatal("Expected SQL syntax error")
}
@ -238,7 +238,7 @@ func TestExecFailure(t *testing.T) {
func TestExecFailureWithArguments(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
_, err := conn.Exec(context.Background(), "selct $1;", 1)
if err == nil {
t.Fatal("Expected SQL syntax error")
@ -253,7 +253,7 @@ func TestExecFailureWithArguments(t *testing.T) {
func TestExecContextWithoutCancelation(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
@ -271,7 +271,7 @@ func TestExecContextWithoutCancelation(t *testing.T) {
func TestExecContextFailureWithoutCancelation(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
@ -293,7 +293,7 @@ func TestExecContextFailureWithoutCancelation(t *testing.T) {
func TestExecContextFailureWithoutCancelationWithArguments(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
@ -720,7 +720,7 @@ func TestFatalTxError(t *testing.T) {
func TestInsertBoolArray(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
if results := mustExec(t, conn, "create temporary table foo(spice bool[]);"); results.String() != "CREATE TABLE" {
t.Error("Unexpected results from Exec")
}
@ -735,7 +735,7 @@ func TestInsertBoolArray(t *testing.T) {
func TestInsertTimestampArray(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
if results := mustExec(t, conn, "create temporary table foo(spice timestamp[]);"); results.String() != "CREATE TABLE" {
t.Error("Unexpected results from Exec")
}
@ -859,7 +859,7 @@ func TestConnInitTypeMap(t *testing.T) {
}
func TestUnregisteredTypeUsableAsStringArgumentAndBaseResult(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
skipCockroachDB(t, conn, "Server does support domain types (https://github.com/cockroachdb/cockroach/issues/27796)")
var n uint64
@ -875,7 +875,7 @@ func TestUnregisteredTypeUsableAsStringArgumentAndBaseResult(t *testing.T) {
}
func TestDomainType(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
skipCockroachDB(t, conn, "Server does support domain types (https://github.com/cockroachdb/cockroach/issues/27796)")
// Domain type uint64 is a PostgreSQL domain of underlying type numeric.
@ -1046,7 +1046,7 @@ func TestStmtCacheInvalidationTx(t *testing.T) {
}
func TestInsertDurationInterval(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
_, err := conn.Exec(context.Background(), "create temporary table t(duration INTERVAL(0) NOT NULL)")
require.NoError(t, err)

View File

@ -12,43 +12,33 @@ import (
"github.com/stretchr/testify/require"
)
func testWithAndWithoutPreferSimpleProtocol(t *testing.T, f func(t *testing.T, conn *pgx.Conn)) {
t.Run("SimpleProto",
func(t *testing.T) {
config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
require.NoError(t, err)
config.DefaultQueryExecMode = pgx.QueryExecModeSimpleProtocol
conn, err := pgx.ConnectConfig(context.Background(), config)
require.NoError(t, err)
defer func() {
err := conn.Close(context.Background())
func testWithAllQueryExecModes(t *testing.T, f func(t *testing.T, conn *pgx.Conn)) {
for _, mode := range []pgx.QueryExecMode{
pgx.QueryExecModeCacheStatement,
pgx.QueryExecModeCacheDescribe,
pgx.QueryExecModeDescribeExec,
pgx.QueryExecModeExec,
pgx.QueryExecModeSimpleProtocol,
} {
t.Run(mode.String(),
func(t *testing.T) {
config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
require.NoError(t, err)
}()
f(t, conn)
ensureConnValid(t, conn)
},
)
t.Run("DefaultProto",
func(t *testing.T) {
config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
require.NoError(t, err)
conn, err := pgx.ConnectConfig(context.Background(), config)
require.NoError(t, err)
defer func() {
err := conn.Close(context.Background())
config.DefaultQueryExecMode = mode
conn, err := pgx.ConnectConfig(context.Background(), config)
require.NoError(t, err)
}()
defer func() {
err := conn.Close(context.Background())
require.NoError(t, err)
}()
f(t, conn)
f(t, conn)
ensureConnValid(t, conn)
},
)
ensureConnValid(t, conn)
},
)
}
}
func mustConnectString(t testing.TB, connString string) *pgx.Conn {

View File

@ -1912,7 +1912,7 @@ func TestQueryErrorWithNilStatementCacheMode(t *testing.T) {
func TestConnQueryFunc(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
var actualResults []interface{}
var a, b int
@ -1942,7 +1942,7 @@ func TestConnQueryFuncScanError(t *testing.T) {
t.Skip("TODO - unskip later in v5")
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
var actualResults []interface{}
var a, b int
@ -1964,7 +1964,7 @@ func TestConnQueryFuncScanError(t *testing.T) {
func TestConnQueryFuncAbort(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
var a, b int
ct, err := conn.QueryFunc(
context.Background(),

View File

@ -74,41 +74,32 @@ func skipPostgreSQLVersionLessThan(t testing.TB, db *sql.DB, minVersion int64) {
require.NoError(t, err)
}
func testWithAndWithoutPreferSimpleProtocol(t *testing.T, f func(t *testing.T, db *sql.DB)) {
t.Run("SimpleProto",
func(t *testing.T) {
config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
require.NoError(t, err)
config.DefaultQueryExecMode = pgx.QueryExecModeSimpleProtocol
db := stdlib.OpenDB(*config)
defer func() {
err := db.Close()
func testWithAllQueryExecModes(t *testing.T, f func(t *testing.T, db *sql.DB)) {
for _, mode := range []pgx.QueryExecMode{
pgx.QueryExecModeCacheStatement,
pgx.QueryExecModeCacheDescribe,
pgx.QueryExecModeDescribeExec,
pgx.QueryExecModeExec,
pgx.QueryExecModeSimpleProtocol,
} {
t.Run(mode.String(),
func(t *testing.T) {
config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
require.NoError(t, err)
}()
f(t, db)
config.DefaultQueryExecMode = mode
db := stdlib.OpenDB(*config)
defer func() {
err := db.Close()
require.NoError(t, err)
}()
ensureDBValid(t, db)
},
)
f(t, db)
t.Run("DefaultProto",
func(t *testing.T) {
config, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
require.NoError(t, err)
db := stdlib.OpenDB(*config)
defer func() {
err := db.Close()
require.NoError(t, err)
}()
f(t, db)
ensureDBValid(t, db)
},
)
ensureDBValid(t, db)
},
)
}
}
// Do a simple query to ensure the DB is still usable. This is of less use in stdlib as the connection pool should
@ -267,7 +258,7 @@ func TestQueryCloseRowsEarly(t *testing.T) {
}
func TestConnExec(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
_, err := db.Exec("create temporary table t(a varchar not null)")
require.NoError(t, err)
@ -281,7 +272,7 @@ func TestConnExec(t *testing.T) {
}
func TestConnQuery(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
skipCockroachDB(t, db, "Server issues incorrect ParameterDescription (https://github.com/cockroachdb/cockroach/issues/60907)")
rows, err := db.Query("select 'foo', n from generate_series($1::int, $2::int) n", int32(1), int32(10))
@ -313,7 +304,7 @@ func TestConnQuery(t *testing.T) {
// https://github.com/jackc/pgx/issues/781
func TestConnQueryDifferentScanPlansIssue781(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
var s string
var b bool
@ -328,7 +319,7 @@ func TestConnQueryDifferentScanPlansIssue781(t *testing.T) {
}
func TestConnQueryNull(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
rows, err := db.Query("select $1::int", nil)
require.NoError(t, err)
@ -353,7 +344,7 @@ func TestConnQueryNull(t *testing.T) {
}
func TestConnQueryRowByteSlice(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
expected := []byte{222, 173, 190, 239}
var actual []byte
@ -364,7 +355,7 @@ func TestConnQueryRowByteSlice(t *testing.T) {
}
func TestConnQueryFailure(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
_, err := db.Query("select 'foo")
require.Error(t, err)
require.IsType(t, new(pgconn.PgError), err)
@ -372,7 +363,7 @@ func TestConnQueryFailure(t *testing.T) {
}
func TestConnSimpleSlicePassThrough(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
skipCockroachDB(t, db, "Server does not support cardinality function")
var n int64
@ -385,7 +376,7 @@ func TestConnSimpleSlicePassThrough(t *testing.T) {
// Test type that pgx would handle natively in binary, but since it is not a
// database/sql native type should be passed through as a string
func TestConnQueryRowPgxBinary(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
sql := "select $1::int4[]"
expected := "{1,2,3}"
var actual string
@ -397,7 +388,7 @@ func TestConnQueryRowPgxBinary(t *testing.T) {
}
func TestConnQueryRowUnknownType(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
skipCockroachDB(t, db, "Server does not support point type")
sql := "select $1::point"
@ -411,7 +402,7 @@ func TestConnQueryRowUnknownType(t *testing.T) {
}
func TestConnQueryJSONIntoByteSlice(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
_, err := db.Exec(`
create temporary table docs(
body json not null
@ -471,7 +462,7 @@ func TestConnExecInsertByteSliceIntoJSON(t *testing.T) {
}
func TestTransactionLifeCycle(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
_, err := db.Exec("create temporary table t(a varchar not null)")
require.NoError(t, err)
@ -505,7 +496,7 @@ func TestTransactionLifeCycle(t *testing.T) {
}
func TestConnBeginTxIsolation(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
skipCockroachDB(t, db, "Server always uses serializable isolation level")
var defaultIsoLevel string
@ -561,7 +552,7 @@ func TestConnBeginTxIsolation(t *testing.T) {
}
func TestConnBeginTxReadOnly(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
tx, err := db.BeginTx(context.Background(), &sql.TxOptions{ReadOnly: true})
require.NoError(t, err)
defer tx.Rollback()
@ -579,7 +570,7 @@ func TestConnBeginTxReadOnly(t *testing.T) {
}
func TestBeginTxContextCancel(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
_, err := db.Exec("drop table if exists t")
require.NoError(t, err)
@ -607,7 +598,7 @@ func TestBeginTxContextCancel(t *testing.T) {
}
func TestAcquireConn(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
var conns []*pgx.Conn
for i := 1; i < 6; i++ {
@ -643,7 +634,7 @@ func TestAcquireConn(t *testing.T) {
}
func TestConnRaw(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
conn, err := db.Conn(context.Background())
require.NoError(t, err)
@ -659,7 +650,7 @@ func TestConnRaw(t *testing.T) {
// https://github.com/jackc/pgx/issues/673
func TestReleaseConnWithTxInProgress(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
skipCockroachDB(t, db, "Server does not support backend PID")
c1, err := stdlib.AcquireConn(db)
@ -690,14 +681,14 @@ func TestReleaseConnWithTxInProgress(t *testing.T) {
}
func TestConnPingContextSuccess(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
err := db.PingContext(context.Background())
require.NoError(t, err)
})
}
func TestConnPrepareContextSuccess(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
stmt, err := db.PrepareContext(context.Background(), "select now()")
require.NoError(t, err)
err = stmt.Close()
@ -706,14 +697,14 @@ func TestConnPrepareContextSuccess(t *testing.T) {
}
func TestConnExecContextSuccess(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
_, err := db.ExecContext(context.Background(), "create temporary table exec_context_test(id serial primary key)")
require.NoError(t, err)
})
}
func TestConnExecContextFailureRetry(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
// We get a connection, immediately close it, and then get it back;
// DB.Conn along with Conn.ResetSession does the retry for us.
{
@ -730,7 +721,7 @@ func TestConnExecContextFailureRetry(t *testing.T) {
}
func TestConnQueryContextSuccess(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
rows, err := db.QueryContext(context.Background(), "select * from generate_series(1,10) n")
require.NoError(t, err)
@ -744,7 +735,7 @@ func TestConnQueryContextSuccess(t *testing.T) {
}
func TestConnQueryContextFailureRetry(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
// We get a connection, immediately close it, and then get it back;
// DB.Conn along with Conn.ResetSession does the retry for us.
{
@ -762,7 +753,7 @@ func TestConnQueryContextFailureRetry(t *testing.T) {
}
func TestRowsColumnTypeDatabaseTypeName(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
rows, err := db.Query("select 42::bigint")
require.NoError(t, err)
@ -846,7 +837,7 @@ func TestStmtQueryContextSuccess(t *testing.T) {
}
func TestRowsColumnTypes(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
columnTypesTests := []struct {
Name string
TypeName string
@ -984,7 +975,7 @@ func TestRowsColumnTypes(t *testing.T) {
}
func TestQueryLifeCycle(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
skipCockroachDB(t, db, "Server issues incorrect ParameterDescription (https://github.com/cockroachdb/cockroach/issues/60907)")
rows, err := db.Query("SELECT 'foo', n FROM generate_series($1::int, $2::int) n WHERE 3 = $3", 1, 10, 3)
@ -1033,7 +1024,7 @@ func TestQueryLifeCycle(t *testing.T) {
// https://github.com/jackc/pgx/issues/409
func TestScanJSONIntoJSONRawMessage(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
var msg json.RawMessage
err := db.QueryRow("select '{}'::json").Scan(&msg)
@ -1088,7 +1079,7 @@ func TestRegisterConnConfig(t *testing.T) {
// https://github.com/jackc/pgx/issues/958
func TestConnQueryRowConstraintErrors(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {
skipPostgreSQLVersionLessThan(t, db, 11)
skipCockroachDB(t, db, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)")

View File

@ -18,7 +18,7 @@ import (
func TestDateTranscode(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
dates := []time.Time{
time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC),
time.Date(1000, 1, 1, 0, 0, 0, 0, time.UTC),
@ -57,7 +57,7 @@ func TestDateTranscode(t *testing.T) {
func TestTimestampTzTranscode(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
inputTime := time.Date(2013, 1, 2, 3, 4, 5, 6000, time.Local)
var outputTime time.Time
@ -77,7 +77,7 @@ func TestTimestampTzTranscode(t *testing.T) {
func TestJSONAndJSONBTranscode(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
for _, typename := range []string{"json", "jsonb"} {
if _, ok := conn.TypeMap().TypeForName(typename); !ok {
continue // No JSON/JSONB type -- must be running against old PostgreSQL
@ -247,7 +247,7 @@ func TestStringToNotTextTypeTranscode(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
input := "01086ee0-4963-4e35-9116-30c173a8d0bd"
var output string
@ -272,7 +272,7 @@ func TestStringToNotTextTypeTranscode(t *testing.T) {
func TestInetCIDRTranscodeIPNet(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
tests := []struct {
sql string
value *net.IPNet
@ -323,7 +323,7 @@ func TestInetCIDRTranscodeIPNet(t *testing.T) {
func TestInetCIDRTranscodeIP(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
tests := []struct {
sql string
value net.IP
@ -387,7 +387,7 @@ func TestInetCIDRTranscodeIP(t *testing.T) {
func TestInetCIDRArrayTranscodeIPNet(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
tests := []struct {
sql string
value []*net.IPNet
@ -450,7 +450,7 @@ func TestInetCIDRArrayTranscodeIPNet(t *testing.T) {
func TestInetCIDRArrayTranscodeIP(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
tests := []struct {
sql string
value []net.IP
@ -536,7 +536,7 @@ func TestInetCIDRArrayTranscodeIP(t *testing.T) {
func TestInetCIDRTranscodeWithJustIP(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
tests := []struct {
sql string
value string
@ -582,7 +582,7 @@ func TestInetCIDRTranscodeWithJustIP(t *testing.T) {
func TestArrayDecoding(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
tests := []struct {
sql string
query interface{}
@ -698,7 +698,7 @@ func TestArrayDecoding(t *testing.T) {
func TestEmptyArrayDecoding(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
var val []string
err := conn.QueryRow(context.Background(), "select array[]::text[]").Scan(&val)
@ -743,7 +743,7 @@ func TestEmptyArrayDecoding(t *testing.T) {
func TestPointerPointer(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
skipCockroachDB(t, conn, "Server auto converts ints to bigint and test relies on exact types")
type allTypes struct {
@ -829,7 +829,7 @@ func TestPointerPointer(t *testing.T) {
func TestPointerPointerNonZero(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
f := "foo"
dest := &f
@ -846,7 +846,7 @@ func TestPointerPointerNonZero(t *testing.T) {
func TestEncodeTypeRename(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
type _int int
inInt := _int(1)
var outInt _int
@ -993,7 +993,7 @@ func TestEncodeTypeRename(t *testing.T) {
func TestRowsScanNilThenScanValue(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
testWithAllQueryExecModes(t, func(t *testing.T, conn *pgx.Conn) {
sql := `select null as a, null as b
union
select 1, 2