Skip to content

Commit

Permalink
Helpers: Fix dumpSql() for bool parameters (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
RiKap authored and dg committed Feb 4, 2020
1 parent 08d1da8 commit daccbd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Database/Helpers.php
Expand Up @@ -137,6 +137,9 @@ public static function dumpSql(string $sql, array $params = null, Connection $co
return '<i' . (isset($info['uri']) ? ' title="' . htmlspecialchars($info['uri'], ENT_NOQUOTES, 'UTF-8') . '"' : null)
. '>&lt;' . htmlspecialchars($type, ENT_NOQUOTES, 'UTF-8') . ' resource&gt;</i> ';

} elseif (is_bool($param)) {
return (string) (int) $param;

} else {
return htmlspecialchars((string) $param, ENT_NOQUOTES, 'UTF-8');
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Database/Helpers.dumpSql.phpt
Expand Up @@ -19,6 +19,11 @@ test(function () use ($connection) { // int check
"<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));
});

test(function () use ($connection) { // bool check
Assert::same(
"<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));
});

test(function () use ($connection) { // string check
Assert::same(
"<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));
Expand Down

0 comments on commit daccbd5

Please sign in to comment.