From 12c109b4b62a27e20178a1cbdb8c0454d158cfe6 Mon Sep 17 00:00:00 2001 From: smeghead Date: Wed, 22 May 2024 20:04:20 +0900 Subject: [PATCH] feat: Add debug-dump-params to statement. --- CHANGELOG.md | 1 + README.md | 8 ++++++++ src/statement.phel | 9 +++++++-- tests/feature/statement.phel | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8e235e..e43298d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features * Implemented statement bind-value method. + * Implemented statement debug-dump-params method. ## v0.0.2 (2024-05-17) diff --git a/README.md b/README.md index 8f5a467..be9adfd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/statement.phel b/src/statement.phel index f8014a3..68533f4 100644 --- a/src/statement.phel +++ b/src/statement.phel @@ -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 diff --git a/tests/feature/statement.phel b/tests/feature/statement.phel index fdce3f7..0c6361d 100644 --- a/tests/feature/statement.phel +++ b/tests/feature/statement.phel @@ -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)))))) +