88use Amp \Postgres \PostgresConfig ;
99use Amp \Postgres \PostgresListener ;
1010use Amp \Postgres \PostgresNotification ;
11+ use Amp \Postgres \PostgresQueryError ;
1112use Amp \Postgres \PostgresResult ;
1213use Amp \Postgres \PostgresStatement ;
13- use Amp \Postgres \QueryExecutionError ;
14- use Amp \Sql \ConnectionException ;
15- use Amp \Sql \QueryError ;
14+ use Amp \Sql \SqlConnectionException ;
1615use Amp \Sql \SqlException ;
16+ use Amp \Sql \SqlQueryError ;
1717use Revolt \EventLoop ;
1818use function Amp \async ;
1919
@@ -88,11 +88,11 @@ public function __construct(
8888
8989 try {
9090 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 " );
9292 }
9393
9494 if (!\pg_consume_input ($ handle )) {
95- throw new ConnectionException (\pg_last_error ($ handle ));
95+ throw new SqlConnectionException (\pg_last_error ($ handle ));
9696 }
9797
9898 while ($ result = \pg_get_notify ($ handle , \PGSQL_ASSOC )) {
@@ -120,7 +120,7 @@ public function __construct(
120120 if (empty ($ listeners )) {
121121 EventLoop::unreference ($ watcher );
122122 }
123- } catch (ConnectionException $ exception ) {
123+ } catch (SqlConnectionException $ exception ) {
124124 $ handle = null ; // Marks connection as dead.
125125 EventLoop::disable ($ watcher );
126126
@@ -152,9 +152,9 @@ public function __construct(
152152 EventLoop::disable ($ watcher );
153153
154154 if ($ flush === false ) {
155- throw new ConnectionException (\pg_last_error ($ handle ));
155+ throw new SqlConnectionException (\pg_last_error ($ handle ));
156156 }
157- } catch (ConnectionException $ exception ) {
157+ } catch (SqlConnectionException $ exception ) {
158158 $ handle = null ; // Marks connection as dead.
159159 EventLoop::disable ($ watcher );
160160
@@ -193,7 +193,7 @@ private static function fetchTypes(\PgSql\Connection $handle): array
193193 private static function getErrorHandler (): \Closure
194194 {
195195 return self ::$ errorHandler ??= static function (int $ code , string $ message ): never {
196- throw new ConnectionException ($ message , $ code );
196+ throw new SqlConnectionException ($ message , $ code );
197197 };
198198 }
199199
@@ -227,7 +227,7 @@ private function send(\Closure $function, mixed ...$args): mixed
227227 }
228228
229229 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 " );
231231 }
232232
233233 while ($ result = \pg_get_result ($ this ->handle )) {
@@ -255,7 +255,7 @@ private function send(\Closure $function, mixed ...$args): mixed
255255 * @param string $sql Query SQL.
256256 *
257257 * @throws SqlException
258- * @throws QueryError
258+ * @throws SqlQueryError
259259 */
260260 private function createResult (\PgSql \Result $ result , string $ sql ): PostgresResult
261261 {
@@ -265,7 +265,7 @@ private function createResult(\PgSql\Result $result, string $sql): PostgresResul
265265
266266 switch (\pg_result_status ($ result )) {
267267 case \PGSQL_EMPTY_QUERY :
268- throw new QueryError ("Empty query string " );
268+ throw new SqlQueryError ("Empty query string " );
269269
270270 case \PGSQL_COMMAND_OK :
271271 return new PostgresCommandResult (
@@ -290,7 +290,7 @@ private function createResult(\PgSql\Result $result, string $sql): PostgresResul
290290 }
291291 } finally {
292292 \restore_error_handler ();
293- throw new QueryExecutionError ($ message , $ diagnostics , $ sql );
293+ throw new PostgresQueryError ($ message , $ diagnostics , $ sql );
294294 }
295295
296296 case \PGSQL_BAD_RESPONSE :
@@ -428,7 +428,7 @@ public function prepare(string $sql): PostgresStatement
428428 foreach (self ::DIAGNOSTIC_CODES as $ fieldCode => $ description ) {
429429 $ diagnostics [$ description ] = \pg_result_error_field ($ result , $ fieldCode );
430430 }
431- throw new QueryExecutionError (\pg_result_error ($ result ), $ diagnostics , $ sql );
431+ throw new PostgresQueryError (\pg_result_error ($ result ), $ diagnostics , $ sql );
432432
433433 case \PGSQL_BAD_RESPONSE :
434434 throw new SqlException (\pg_result_error ($ result ));
@@ -465,7 +465,7 @@ public function notify(string $channel, string $payload = ""): PostgresResult
465465 public function listen (string $ channel ): PostgresListener
466466 {
467467 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 ));
469469 }
470470
471471 $ this ->listeners [$ channel ] = $ source = new Queue ();
0 commit comments