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

Function cursorLifecycleFlow

tests/integration/cursor_test.go:108–129  ·  view source on GitHub ↗

cursorLifecycleFlow covers DECLARE → FETCH n → FETCH n (position advances) → FETCH ALL (drains the rest) → FETCH on exhausted cursor (zero rows) → CLOSE → FETCH after CLOSE (clean missing-cursor error).

(t *testing.T, db *sql.DB)

Source from the content-addressed store, hash-verified

106// FETCH ALL (drains the rest) → FETCH on exhausted cursor (zero rows) →
107// CLOSE → FETCH after CLOSE (clean missing-cursor error).
108func cursorLifecycleFlow(t *testing.T, db *sql.DB) {
109 tx := beginCursorTx(t, db)
110
111 mustExecTx(t, tx, "DECLARE cur_lifecycle CURSOR FOR SELECT id, name FROM users ORDER BY id")
112
113 assertCursorRows(t, "FETCH 3", fetchCursorRows(t, tx, "FETCH 3 FROM cur_lifecycle"), cursorUsers(1, 3))
114 assertCursorRows(t, "FETCH 3 (resumes)", fetchCursorRows(t, tx, "FETCH 3 FROM cur_lifecycle"), cursorUsers(4, 6))
115 assertCursorRows(t, "FETCH ALL", fetchCursorRows(t, tx, "FETCH ALL FROM cur_lifecycle"), cursorUsers(7, 10))
116 // An exhausted cursor returns zero rows, not an error.
117 assertCursorRows(t, "FETCH 3 (exhausted)", fetchCursorRows(t, tx, "FETCH 3 FROM cur_lifecycle"), nil)
118
119 mustExecTx(t, tx, "CLOSE cur_lifecycle")
120
121 rows, err := tx.Query("FETCH 3 FROM cur_lifecycle")
122 if err == nil {
123 _ = rows.Close()
124 t.Fatal("FETCH after CLOSE succeeded, want missing-cursor error")
125 }
126 if !strings.Contains(err.Error(), `cursor "cur_lifecycle" does not exist`) {
127 t.Errorf("FETCH after CLOSE: error = %q, want it to mention the missing cursor", err)
128 }
129}
130
131// cursorMoveFlow covers MOVE n advancing the position without returning rows.
132func cursorMoveFlow(t *testing.T, db *sql.DB) {

Callers 2

TestCursorSimpleQueryFunction · 0.85
TestCursorPostgresParityFunction · 0.85

Calls 8

beginCursorTxFunction · 0.85
mustExecTxFunction · 0.85
assertCursorRowsFunction · 0.85
fetchCursorRowsFunction · 0.85
cursorUsersFunction · 0.85
QueryMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected