Skip to content

Commit daccbd5

Browse files
RiKapdg
authored andcommitted
Helpers: Fix dumpSql() for bool parameters (#251)
1 parent 08d1da8 commit daccbd5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Database/Helpers.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ public static function dumpSql(string $sql, array $params = null, Connection $co
137137
return '<i' . (isset($info['uri']) ? ' title="' . htmlspecialchars($info['uri'], ENT_NOQUOTES, 'UTF-8') . '"' : null)
138138
. '>&lt;' . htmlspecialchars($type, ENT_NOQUOTES, 'UTF-8') . ' resource&gt;</i> ';
139139

140+
} elseif (is_bool($param)) {
141+
return (string) (int) $param;
142+
140143
} else {
141144
return htmlspecialchars((string) $param, ENT_NOQUOTES, 'UTF-8');
142145
}

tests/Database/Helpers.dumpSql.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ test(function () use ($connection) { // int check
1919
"<pre class=\"dump\"><strong style=\"color:blue\">SELECT</strong> id \n<strong style=\"color:blue\">FROM</strong> author \n<strong style=\"color:blue\">WHERE</strong> id = 10 <strong style=\"color:green\">OR</strong> id = 11</pre>\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE id = ? OR id = ?', [10, 11], $connection));
2020
});
2121

22+
test(function () use ($connection) { // bool check
23+
Assert::same(
24+
"<pre class=\"dump\"><strong style=\"color:blue\">SELECT</strong> id \n<strong style=\"color:blue\">FROM</strong> author \n<strong style=\"color:blue\">WHERE</strong> deleted = 0</pre>\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE deleted = ?', [false], $connection));
25+
});
26+
2227
test(function () use ($connection) { // string check
2328
Assert::same(
2429
"<pre class=\"dump\"><strong style=\"color:blue\">SELECT</strong> id \n<strong style=\"color:blue\">FROM</strong> author \n<strong style=\"color:blue\">WHERE</strong> name = <span title=\"Length 15 characters\">'Alexej Chruščev'</span></pre>\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ['Alexej Chruščev'], $connection));

0 commit comments

Comments
 (0)