Handle too many params in pgconn

pull/483/head
Jack Christensen 2019-04-05 12:09:15 -05:00
parent d619d8913e
commit 1715b17abb
3 changed files with 3 additions and 73 deletions

View File

@ -2,9 +2,7 @@ package pgx_test
import (
"context"
"fmt"
"os"
"strconv"
"strings"
"sync"
"testing"
@ -404,76 +402,6 @@ func TestPrepareBadSQLFailure(t *testing.T) {
ensureConnValid(t, conn)
}
func TestPrepareQueryManyParameters(t *testing.T) {
t.Parallel()
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn)
tests := []struct {
count int
succeed bool
}{
{
count: 65534,
succeed: true,
},
{
count: 65535,
succeed: true,
},
{
count: 65536,
succeed: false,
},
{
count: 65537,
succeed: false,
},
}
for i, tt := range tests {
params := make([]string, 0, tt.count)
args := make([]interface{}, 0, tt.count)
for j := 0; j < tt.count; j++ {
params = append(params, fmt.Sprintf("($%d::text)", j+1))
args = append(args, strconv.Itoa(j))
}
sql := "values" + strings.Join(params, ", ")
psName := fmt.Sprintf("manyParams%d", i)
_, err := conn.Prepare(psName, sql)
if err != nil {
if tt.succeed {
t.Errorf("%d. %v", i, err)
}
continue
}
if !tt.succeed {
t.Errorf("%d. Expected error but succeeded", i)
continue
}
rows, err := conn.Query(psName, args...)
if err != nil {
t.Errorf("conn.Query failed: %v", err)
continue
}
for rows.Next() {
var s string
rows.Scan(&s)
}
if rows.Err() != nil {
t.Errorf("Reading query result failed: %v", err)
}
}
ensureConnValid(t, conn)
}
func TestPrepareIdempotency(t *testing.T) {
t.Parallel()

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.12
require (
github.com/cockroachdb/apd v1.1.0
github.com/jackc/pgconn v0.0.0-20190330221323-ed7d91dc9873
github.com/jackc/pgconn v0.0.0-20190405170659-7ad3625edd3b
github.com/jackc/pgio v1.0.0
github.com/jackc/pgproto3 v1.0.0
github.com/pkg/errors v0.8.1

2
go.sum
View File

@ -6,6 +6,8 @@ github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZb
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
github.com/jackc/pgconn v0.0.0-20190330221323-ed7d91dc9873 h1:M68R77AKFS7dub7R7WgJ9D6yiNuExOYhBuGtazlbr10=
github.com/jackc/pgconn v0.0.0-20190330221323-ed7d91dc9873/go.mod h1:8Bzf8vzi/ZpcgLgrq8IUHjZX4ZU+Hf6N6/AJ85+fDeE=
github.com/jackc/pgconn v0.0.0-20190405170659-7ad3625edd3b h1:EFVP6CIXsShWT+mEeoVGMvJz1a1SAKqw8zQ15bz7cw8=
github.com/jackc/pgconn v0.0.0-20190405170659-7ad3625edd3b/go.mod h1:8Bzf8vzi/ZpcgLgrq8IUHjZX4ZU+Hf6N6/AJ85+fDeE=
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/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=