Skip to content

Commit 0020c4d

Browse files
committed
wip
1 parent 6bf5c06 commit 0020c4d

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

packages/database/src/GenericDatabase.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ public function fetch(BuildsQuery|Query $query): array
8282

8383
$bindings = $this->resolveBindings($query);
8484

85-
$pdoQuery = $this->connection->prepare($query->toSql());
85+
try {
86+
$pdoQuery = $this->connection->prepare($query->toSql());
8687

87-
$pdoQuery->execute($bindings);
88+
$pdoQuery->execute($bindings);
8889

89-
return $pdoQuery->fetchAll(PDO::FETCH_NAMED);
90+
return $pdoQuery->fetchAll(PDO::FETCH_NAMED);
91+
} catch (PDOException $pdoException) {
92+
throw new QueryWasInvalid($query, $bindings, $pdoException);
93+
}
9094
}
9195

9296
public function fetchFirst(BuildsQuery|Query $query): ?array

tests/Integration/Database/GenericDatabaseTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Exception;
88
use Tempest\Database\Database;
9+
use Tempest\Database\Exceptions\QueryWasInvalid;
910
use Tempest\Database\Migrations\CreateMigrationsTable;
1011
use Tempest\Database\Query;
1112
use Tests\Tempest\Fixtures\Migrations\CreateAuthorTable;
@@ -67,4 +68,18 @@ public function test_query_with_semicolons(): void
6768

6869
$this->assertSame(1, query(Publisher::class)->count()->execute());
6970
}
71+
72+
public function test_query_was_invalid_exception_is_thrown_on_fetch(): void
73+
{
74+
$this->assertException(QueryWasInvalid::class, function () {
75+
query('books')->select()->orderBy('title DES')->first();
76+
});
77+
}
78+
79+
public function test_query_was_invalid_exception_is_thrown_on_execute(): void
80+
{
81+
$this->assertException(QueryWasInvalid::class, function () {
82+
query('books')->update(title: 'Timeline Taxi')->where('title = ?')->execute();
83+
});
84+
}
7085
}

0 commit comments

Comments
 (0)