MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestCursorExtendedQuery

Function TestCursorExtendedQuery

tests/integration/cursor_test.go:255–356  ·  view source on GitHub ↗

TestCursorExtendedQuery exercises the extended-query-protocol cursor path (cursorOpDeclare/cursorOpFetch/cursorOpClose) with pgx.

(t *testing.T)

Source from the content-addressed store, hash-verified

253// TestCursorExtendedQuery exercises the extended-query-protocol cursor path
254// (cursorOpDeclare/cursorOpFetch/cursorOpClose) with pgx.
255func TestCursorExtendedQuery(t *testing.T) {
256 ctx := context.Background()
257
258 t.Run("declare_fetch_close", func(t *testing.T) {
259 conn := pgxConnect(t)
260 defer func() { _ = conn.Close(ctx) }()
261
262 _, tag, err := pgxCursorRows(ctx, conn, "DECLARE cur_ext CURSOR FOR SELECT id, name FROM users ORDER BY id")
263 if err != nil {
264 t.Fatalf("DECLARE: %v", err)
265 }
266 if tag.String() != "DECLARE CURSOR" {
267 t.Errorf("DECLARE tag = %q, want %q", tag, "DECLARE CURSOR")
268 }
269
270 got, tag, err := pgxCursorRows(ctx, conn, "FETCH 4 FROM cur_ext")
271 if err != nil {
272 t.Fatalf("FETCH 4: %v", err)
273 }
274 assertCursorRows(t, "FETCH 4", got, cursorUsers(1, 4))
275 if tag.String() != "FETCH 4" {
276 t.Errorf("FETCH 4 tag = %q, want %q", tag, "FETCH 4")
277 }
278
279 got, tag, err = pgxCursorRows(ctx, conn, "FETCH ALL FROM cur_ext")
280 if err != nil {
281 t.Fatalf("FETCH ALL: %v", err)
282 }
283 assertCursorRows(t, "FETCH ALL", got, cursorUsers(5, 10))
284 if tag.String() != "FETCH 6" {
285 t.Errorf("FETCH ALL tag = %q, want %q", tag, "FETCH 6")
286 }
287
288 _, tag, err = pgxCursorRows(ctx, conn, "CLOSE cur_ext")
289 if err != nil {
290 t.Fatalf("CLOSE: %v", err)
291 }
292 if tag.String() != "CLOSE CURSOR" {
293 t.Errorf("CLOSE tag = %q, want %q", tag, "CLOSE CURSOR")
294 }
295
296 // FETCH after CLOSE: clean SQLSTATE 34000 missing-cursor error.
297 _, _, err = pgxCursorRows(ctx, conn, "FETCH 4 FROM cur_ext")
298 var pgErr *pgconn.PgError
299 if !errors.As(err, &pgErr) {
300 t.Fatalf("FETCH after CLOSE: error = %v, want *pgconn.PgError", err)
301 }
302 if pgErr.Code != "34000" || !strings.Contains(pgErr.Message, `cursor "cur_ext" does not exist`) {
303 t.Errorf("FETCH after CLOSE: code=%s message=%q, want 34000 missing-cursor", pgErr.Code, pgErr.Message)
304 }
305 })
306
307 t.Run("move_advances_position", func(t *testing.T) {
308 conn := pgxConnect(t)
309 defer func() { _ = conn.Close(ctx) }()
310
311 _, _, err := pgxCursorRows(ctx, conn, "DECLARE cur_ext_move CURSOR FOR SELECT id, name FROM users ORDER BY id")
312 if err != nil {

Callers

nothing calls this directly

Calls 7

pgxConnectFunction · 0.85
pgxCursorRowsFunction · 0.85
assertCursorRowsFunction · 0.85
cursorUsersFunction · 0.85
RunMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected