MCPcopy
hub / github.com/jackc/pgx / TestCollectOneRowIgnoresExtraRows

Function TestCollectOneRowIgnoresExtraRows

rows_test.go:248–261  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

246}
247
248func TestCollectOneRowIgnoresExtraRows(t *testing.T) {
249 defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
250 rows, _ := conn.Query(ctx, `select n from generate_series(42, 99) n`)
251 n, err := pgx.CollectOneRow(rows, func(row pgx.CollectableRow) (int32, error) {
252 var n int32
253 err := row.Scan(&n)
254 return n, err
255 })
256 require.NoError(t, err)
257
258 assert.NoError(t, err)
259 assert.Equal(t, int32(42), n)
260 })
261}
262
263// https://github.com/jackc/pgx/issues/1334
264func TestCollectOneRowPrefersPostgreSQLErrorOverErrNoRows(t *testing.T) {

Callers

nothing calls this directly

Calls 3

RunTestMethod · 0.80
QueryMethod · 0.65
ScanMethod · 0.65

Tested by

no test coverage detected