fetchCursorRows runs a FETCH/MOVE statement on the transaction's connection (lib/pq sends it via the simple query protocol) and collects any rows it returned. Statements that return no result set yield an empty slice.
(t *testing.T, tx *sql.Tx, stmt string)
| 65 | // (lib/pq sends it via the simple query protocol) and collects any rows it |
| 66 | // returned. Statements that return no result set yield an empty slice. |
| 67 | func fetchCursorRows(t *testing.T, tx *sql.Tx, stmt string) []cursorRow { |
| 68 | t.Helper() |
| 69 | rows, err := tx.Query(stmt) |
| 70 | if err != nil { |
| 71 | t.Fatalf("%s: %v", stmt, err) |
| 72 | } |
| 73 | defer func() { _ = rows.Close() }() |
| 74 | var out []cursorRow |
| 75 | for rows.Next() { |
| 76 | var r cursorRow |
| 77 | if err := rows.Scan(&r.id, &r.name); err != nil { |
| 78 | t.Fatalf("%s: scan: %v", stmt, err) |
| 79 | } |
| 80 | out = append(out, r) |
| 81 | } |
| 82 | if err := rows.Err(); err != nil { |
| 83 | t.Fatalf("%s: rows: %v", stmt, err) |
| 84 | } |
| 85 | return out |
| 86 | } |
| 87 | |
| 88 | func mustExecTx(t *testing.T, tx *sql.Tx, stmt string) { |
| 89 | t.Helper() |
no test coverage detected