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

Function TestConnQueryRawValues

query_test.go:310–341  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

308}
309
310func TestConnQueryRawValues(t *testing.T) {
311 t.Parallel()
312
313 conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
314 defer closeConn(t, conn)
315
316 var rowCount int32
317
318 rows, err := conn.Query(
319 context.Background(),
320 "select 'foo'::text, 'bar'::varchar, n, null, n from generate_series(1,$1) n",
321 pgx.QueryExecModeSimpleProtocol,
322 10,
323 )
324 require.NoError(t, err)
325 defer rows.Close()
326
327 for rows.Next() {
328 rowCount++
329
330 rawValues := rows.RawValues()
331 assert.Len(t, rawValues, 5)
332 assert.Equal(t, "foo", string(rawValues[0]))
333 assert.Equal(t, "bar", string(rawValues[1]))
334 assert.Equal(t, strconv.FormatInt(int64(rowCount), 10), string(rawValues[2]))
335 assert.Nil(t, rawValues[3])
336 assert.Equal(t, strconv.FormatInt(int64(rowCount), 10), string(rawValues[4]))
337 }
338
339 require.NoError(t, rows.Err())
340 assert.EqualValues(t, 10, rowCount)
341}
342
343// Test that a connection stays valid when query results are closed early
344func TestConnQueryCloseEarly(t *testing.T) {

Callers

nothing calls this directly

Calls 8

mustConnectStringFunction · 0.85
closeConnFunction · 0.70
QueryMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.65
RawValuesMethod · 0.65
LenMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected