Skip to content

Commit 0bcb385

Browse files
committed
added Connection::getLastQueryString()
1 parent 9a4a286 commit 0bcb385

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Database/Connection.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class Connection
4242
/** @var PDO */
4343
private $pdo;
4444

45+
/** @var string|null */
46+
private $sql;
47+
4548

4649
public function __construct(string $dsn, string $user = null, string $password = null, array $options = null)
4750
{
@@ -154,9 +157,9 @@ public function rollBack(): void
154157
*/
155158
public function query(string $sql, ...$params): ResultSet
156159
{
157-
[$sql, $params] = $this->preprocess($sql, ...$params);
160+
[$this->sql, $params] = $this->preprocess($sql, ...$params);
158161
try {
159-
$result = new ResultSet($this, $sql, $params);
162+
$result = new ResultSet($this, $this->sql, $params);
160163
} catch (PDOException $e) {
161164
$this->onQuery($this, $e);
162165
throw $e;
@@ -184,6 +187,12 @@ public function preprocess(string $sql, ...$params): array
184187
}
185188

186189

190+
public function getLastQueryString(): ?string
191+
{
192+
return $this->sql;
193+
}
194+
195+
187196
/********************* shortcuts ****************d*g**/
188197

189198

tests/Database/Connection.query.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ test(function () use ($connection) {
1919
Assert::type(Nette\Database\ResultSet::class, $res);
2020
Assert::same('SELECT id FROM author WHERE id = ?', $res->getQueryString());
2121
Assert::same([11], $res->getParameters());
22+
Assert::same('SELECT id FROM author WHERE id = ?', $connection->getLastQueryString());
2223
});
2324

2425

0 commit comments

Comments
 (0)