Skip to content

Commit

Permalink
feat: Add debug-dump-params to statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
smeghead committed May 22, 2024
1 parent 19d15f8 commit 12c109b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features

* Implemented statement bind-value method.
* Implemented statement debug-dump-params method.

## v0.0.2 (2024-05-17)

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ Binds a value to a parameter
(bind-value statement column value & [type])
```

#### debug-dump-params

Returns an SQL prepared command

```clojure
(debug-dump-params statement)
```

#### execute

Executes a prepared statement
Expand Down
9 changes: 7 additions & 2 deletions src/statement.phel
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@
(bindValue (str column) value (or type (php/:: \PDO PARAM_STR))))
statement)

(defn debug-dump-params
"Returns an SQL prepared command"
[statement]
(php/ob_start)
(php/-> (statement :stmt) (debugDumpParams))
(php/ob_get_clean))

# not implement yet.

#PDOStatement::bindColumn — Bind a column to a PHP variable
#PDOStatement::bindParam — Binds a parameter to the specified variable name
#PDOStatement::bindValue — Binds a value to a parameter
#PDOStatement::closeCursor — Closes the cursor, enabling the statement to be executed again
#PDOStatement::debugDumpParams — Dump an SQL prepared command
#PDOStatement::errorCode — Fetch the SQLSTATE associated with the last operation on the statement handle
#PDOStatement::errorInfo — Fetch extended error information associated with the last operation on the statement handle
#PDOStatement::fetchObject — Fetches the next row and returns it as an object
Expand Down
14 changes: 14 additions & 0 deletions tests/feature/statement.phel
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@
stmt (statement/execute stmt)]
(is (= {:id 1 :name "phel"} (statement/fetch stmt))))))

(deftest test-debug-dump-params
(let [conn (pdo/connect "sqlite::memory:")]
(is (= 0 (pdo/exec
conn
"create table t1 (id integer primary key autoincrement, name varchr(10))")))
(is (= 1 (pdo/exec
conn
"insert into t1 (name) values ('phel')")))
(let [stmt (pdo/prepare conn "select * from t1 where name = :name")
stmt (statement/bind-value stmt :name "phel" (php/:: \PDO PARAM_STR))
info (statement/debug-dump-params stmt)
lines (values (php-array-to-map (php/preg_split "/\r\n|\r|\n/" info)))]
(is (= "SQL: [35] select * from t1 where name = :name" (lines 0))))))

0 comments on commit 12c109b

Please sign in to comment.