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 @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `pdo/close-cursor` - wrap `PDOStatement::closeCursor`; frees the cursor so the statement can be re-executed ([#9]).
- `pdo/fetch-object` - wrap `PDOStatement::fetchObject`; returns the next row as an object (`stdClass` or a named class), or `nil` when exhausted ([#11]).
- `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]).

### Changed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Returned by `pdo/query` and `pdo/prepare`.
| `bind-param` | `(bind-param stmt column value & [type])` | Bind a parameter, applied at execution time. Returns the statement. |
| `column-count` | `(column-count stmt)` | Number of columns in the result set. |
| `row-count` | `(row-count stmt)` | Rows affected by the last DML. |
| `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. |
| `debug-dump-params` | `(debug-dump-params stmt)` | Dump prepared statement info as a string. |
Expand Down
7 changes: 6 additions & 1 deletion src/pdo/statement.phel
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
[stmt]
(php/-> (stmt :stmt) (rowCount)))

(defn column-meta
"Returns metadata for a 0-indexed column in the result set as a map, or nil if unavailable"
[stmt column]
(when-let [meta (php/-> (stmt :stmt) (getColumnMeta column))]
(row->map meta)))

(defn bind-value
"Binds a value to a parameter"
[stmt column value & [type]]
Expand All @@ -88,6 +94,5 @@
;; Not implemented yet:
;;
;; PDOStatement::bindColumn — Bind a column to a PHP variable
;; PDOStatement::getColumnMeta — Returns metadata for a column in a result set
;; PDOStatement::getIterator — Gets result set iterator
;; PDOStatement::nextRowset — Advances to the next rowset in a multi-rowset statement handle
7 changes: 7 additions & 0 deletions tests/pdo_test.phel
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
(let [stmt (pdo/query *conn* "select * from t1")]
(is (= 2 (pdo/column-count stmt)))))

(deftest column-meta-returns-map
(seed-t1 *conn*)
(let [stmt (pdo/query *conn* "select id, name from t1")
meta (pdo/column-meta stmt 1)]
(is (= "name" (meta :name)))
(is (= "t1" (meta :table)))))

(deftest row-count-on-insert
(create-t1 *conn*)
(let [stmt (pdo/query *conn* "insert into t1 (name) values ('phel'), ('php')")]
Expand Down
Loading