8
8
use Amp \Postgres \PostgresConfig ;
9
9
use Amp \Postgres \PostgresListener ;
10
10
use Amp \Postgres \PostgresNotification ;
11
+ use Amp \Postgres \PostgresQueryError ;
11
12
use Amp \Postgres \PostgresResult ;
12
13
use Amp \Postgres \PostgresStatement ;
13
- use Amp \Postgres \QueryExecutionError ;
14
- use Amp \Sql \ConnectionException ;
15
- use Amp \Sql \QueryError ;
14
+ use Amp \Sql \SqlConnectionException ;
16
15
use Amp \Sql \SqlException ;
16
+ use Amp \Sql \SqlQueryError ;
17
17
use Revolt \EventLoop ;
18
18
use function Amp \async ;
19
19
@@ -88,11 +88,11 @@ public function __construct(
88
88
89
89
try {
90
90
if (\pg_connection_status ($ handle ) !== \PGSQL_CONNECTION_OK ) {
91
- throw new ConnectionException ("The connection closed during the operation " );
91
+ throw new SqlConnectionException ("The connection closed during the operation " );
92
92
}
93
93
94
94
if (!\pg_consume_input ($ handle )) {
95
- throw new ConnectionException (\pg_last_error ($ handle ));
95
+ throw new SqlConnectionException (\pg_last_error ($ handle ));
96
96
}
97
97
98
98
while ($ result = \pg_get_notify ($ handle , \PGSQL_ASSOC )) {
@@ -120,7 +120,7 @@ public function __construct(
120
120
if (empty ($ listeners )) {
121
121
EventLoop::unreference ($ watcher );
122
122
}
123
- } catch (ConnectionException $ exception ) {
123
+ } catch (SqlConnectionException $ exception ) {
124
124
$ handle = null ; // Marks connection as dead.
125
125
EventLoop::disable ($ watcher );
126
126
@@ -152,9 +152,9 @@ public function __construct(
152
152
EventLoop::disable ($ watcher );
153
153
154
154
if ($ flush === false ) {
155
- throw new ConnectionException (\pg_last_error ($ handle ));
155
+ throw new SqlConnectionException (\pg_last_error ($ handle ));
156
156
}
157
- } catch (ConnectionException $ exception ) {
157
+ } catch (SqlConnectionException $ exception ) {
158
158
$ handle = null ; // Marks connection as dead.
159
159
EventLoop::disable ($ watcher );
160
160
@@ -193,7 +193,7 @@ private static function fetchTypes(\PgSql\Connection $handle): array
193
193
private static function getErrorHandler (): \Closure
194
194
{
195
195
return self ::$ errorHandler ??= static function (int $ code , string $ message ): never {
196
- throw new ConnectionException ($ message , $ code );
196
+ throw new SqlConnectionException ($ message , $ code );
197
197
};
198
198
}
199
199
@@ -227,7 +227,7 @@ private function send(\Closure $function, mixed ...$args): mixed
227
227
}
228
228
229
229
if ($ this ->handle === null ) {
230
- throw new ConnectionException ("The connection to the database has been closed " );
230
+ throw new SqlConnectionException ("The connection to the database has been closed " );
231
231
}
232
232
233
233
while ($ result = \pg_get_result ($ this ->handle )) {
@@ -255,7 +255,7 @@ private function send(\Closure $function, mixed ...$args): mixed
255
255
* @param string $sql Query SQL.
256
256
*
257
257
* @throws SqlException
258
- * @throws QueryError
258
+ * @throws SqlQueryError
259
259
*/
260
260
private function createResult (\PgSql \Result $ result , string $ sql ): PostgresResult
261
261
{
@@ -265,7 +265,7 @@ private function createResult(\PgSql\Result $result, string $sql): PostgresResul
265
265
266
266
switch (\pg_result_status ($ result )) {
267
267
case \PGSQL_EMPTY_QUERY :
268
- throw new QueryError ("Empty query string " );
268
+ throw new SqlQueryError ("Empty query string " );
269
269
270
270
case \PGSQL_COMMAND_OK :
271
271
return new PostgresCommandResult (
@@ -290,7 +290,7 @@ private function createResult(\PgSql\Result $result, string $sql): PostgresResul
290
290
}
291
291
} finally {
292
292
\restore_error_handler ();
293
- throw new QueryExecutionError ($ message , $ diagnostics , $ sql );
293
+ throw new PostgresQueryError ($ message , $ diagnostics , $ sql );
294
294
}
295
295
296
296
case \PGSQL_BAD_RESPONSE :
@@ -428,7 +428,7 @@ public function prepare(string $sql): PostgresStatement
428
428
foreach (self ::DIAGNOSTIC_CODES as $ fieldCode => $ description ) {
429
429
$ diagnostics [$ description ] = \pg_result_error_field ($ result , $ fieldCode );
430
430
}
431
- throw new QueryExecutionError (\pg_result_error ($ result ), $ diagnostics , $ sql );
431
+ throw new PostgresQueryError (\pg_result_error ($ result ), $ diagnostics , $ sql );
432
432
433
433
case \PGSQL_BAD_RESPONSE :
434
434
throw new SqlException (\pg_result_error ($ result ));
@@ -465,7 +465,7 @@ public function notify(string $channel, string $payload = ""): PostgresResult
465
465
public function listen (string $ channel ): PostgresListener
466
466
{
467
467
if (isset ($ this ->listeners [$ channel ])) {
468
- throw new QueryError (\sprintf ("Already listening on channel '%s' " , $ channel ));
468
+ throw new SqlQueryError (\sprintf ("Already listening on channel '%s' " , $ channel ));
469
469
}
470
470
471
471
$ this ->listeners [$ channel ] = $ source = new Queue ();
0 commit comments