| 308 | } |
| 309 | |
| 310 | func 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 |
| 344 | func TestConnQueryCloseEarly(t *testing.T) { |