mirror of https://github.com/jackc/pgx.git
parent
ee0c64864e
commit
ee001a7cae
|
@ -25,7 +25,11 @@ func (dst *DataRow) Decode(src []byte) error {
|
||||||
// large reallocate. This is too avoid one row with many columns from
|
// large reallocate. This is too avoid one row with many columns from
|
||||||
// permanently allocating memory.
|
// permanently allocating memory.
|
||||||
if cap(dst.Values) < fieldCount || cap(dst.Values)-fieldCount > 32 {
|
if cap(dst.Values) < fieldCount || cap(dst.Values)-fieldCount > 32 {
|
||||||
dst.Values = make([][]byte, fieldCount, 32)
|
newCap := 32
|
||||||
|
if newCap < fieldCount {
|
||||||
|
newCap = fieldCount
|
||||||
|
}
|
||||||
|
dst.Values = make([][]byte, fieldCount, newCap)
|
||||||
} else {
|
} else {
|
||||||
dst.Values = dst.Values[:fieldCount]
|
dst.Values = dst.Values[:fieldCount]
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -46,6 +47,58 @@ func TestConnQueryScan(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConnQueryScanWithManyColumns(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
conn := mustConnect(t, *defaultConnConfig)
|
||||||
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
columnCount := 1000
|
||||||
|
sql := "select "
|
||||||
|
for i := 0; i < columnCount; i++ {
|
||||||
|
if i > 0 {
|
||||||
|
sql += ","
|
||||||
|
}
|
||||||
|
sql += fmt.Sprintf(" %d", i)
|
||||||
|
}
|
||||||
|
sql += " from generate_series(1,5)"
|
||||||
|
|
||||||
|
dest := make([]int, columnCount)
|
||||||
|
|
||||||
|
var rowCount int
|
||||||
|
|
||||||
|
rows, err := conn.Query(sql)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("conn.Query failed: %v", err)
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
destPtrs := make([]interface{}, columnCount)
|
||||||
|
for i := range destPtrs {
|
||||||
|
destPtrs[i] = &dest[i]
|
||||||
|
}
|
||||||
|
if err := rows.Scan(destPtrs...); err != nil {
|
||||||
|
t.Fatalf("rows.Scan failed: %v", err)
|
||||||
|
}
|
||||||
|
rowCount++
|
||||||
|
|
||||||
|
for i := range dest {
|
||||||
|
if dest[i] != i {
|
||||||
|
t.Errorf("dest[%d] => %d, want %d", i, dest[i], i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rows.Err() != nil {
|
||||||
|
t.Fatalf("conn.Query failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rowCount != 5 {
|
||||||
|
t.Errorf("rowCount => %d, want %d", rowCount, 5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestConnQueryValues(t *testing.T) {
|
func TestConnQueryValues(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue