Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `pdo/set-fetch-mode` - wrap `PDOStatement::setFetchMode`; sets the statement's default fetch mode, with mode-specific extra args ([#13]).
- `pdo/column-meta` - wrap `PDOStatement::getColumnMeta`; returns a 0-indexed column's metadata as a map, or `nil` when unavailable ([#15]).
- `pdo/statement-seq` - expose a statement's rows as a lazy seq of maps (the Phel-idiomatic take on `PDOStatement::getIterator`), so callers can `map`/`reduce`/`take` without materialising the whole result set ([#16]).
- `pdo/next-rowset` - wrap `PDOStatement::nextRowset`; advances a multi-rowset statement (e.g. stored procedures on MySQL/Postgres) ([#17]).

### Changed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Returned by `pdo/query` and `pdo/prepare`.
| `column-meta` | `(column-meta stmt column)` | Metadata map for a 0-indexed column, or `nil` if unavailable. |
| `close-cursor` | `(close-cursor stmt)` | Free the cursor so the statement can be re-executed. Returns the statement. |
| `set-fetch-mode` | `(set-fetch-mode stmt mode & args)` | Set the statement's default fetch mode (extra args match the mode). Returns the statement. |
| `next-rowset` | `(next-rowset stmt)` | Advance to the next rowset of a multi-rowset statement; `false` when none remain. |
| `debug-dump-params` | `(debug-dump-params stmt)` | Dump prepared statement info as a string. |

> [!NOTE]
Expand Down
6 changes: 5 additions & 1 deletion src/pdo/statement.phel
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
(php/-> (stmt :stmt) (closeCursor))
stmt)

(defn ^bool next-rowset
"Advances to the next rowset of a multi-rowset statement; false when none remain"
[stmt]
(php/-> (stmt :stmt) (nextRowset)))

(defn set-fetch-mode
"Sets the default fetch mode for the statement. Extra args match the mode
(e.g. column index for FETCH_COLUMN, class name + ctor args for FETCH_CLASS)"
Expand Down Expand Up @@ -101,4 +106,3 @@
;; Not implemented yet:
;;
;; PDOStatement::bindColumn — Bind a column to a PHP variable
;; PDOStatement::nextRowset — Advances to the next rowset in a multi-rowset statement handle
10 changes: 10 additions & 0 deletions tests/pdo_test.phel
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@
stmt (pdo/execute stmt)]
(is (= [1 "phel"] (php->phel (php/-> (stmt :stmt) (fetch)))))))

(deftest next-rowset-rejected-on-sqlite
(seed-t1 *conn*)
;; SQLite has no multi-rowset support; depending on the driver build this is
;; either a false return or a PDOException - both prove the call reached nextRowset.
(let [stmt (pdo/query *conn* "select * from t1")
outcome (try
(pdo/next-rowset stmt)
(catch \PDOException _e :unsupported))]
(is (or (= false outcome) (= :unsupported outcome)))))

(deftest set-attribute-dispatches-to-statement
(seed-t1 *conn*)
;; SQLite rejects statement attributes; depending on the driver build this is
Expand Down
Loading