@@ -2,9 +2,15 @@ use crate::error::Error;
22use crate :: executor:: { Execute , Executor } ;
33use crate :: io:: { PortalId , StatementId } ;
44use crate :: logger:: QueryLogger ;
5- use crate :: message:: { self , BackendMessageFormat , Bind , Close , CommandComplete , DataRow , ParameterDescription , Parse , ParseComplete , ReceivedMessage , RowDescription } ;
5+ use crate :: message:: {
6+ self , BackendMessageFormat , Bind , Close , CommandComplete , DataRow , ParameterDescription , Parse ,
7+ ParseComplete , RowDescription ,
8+ } ;
69use crate :: statement:: PgStatementMetadata ;
7- use crate :: { statement:: PgStatement , PgArguments , PgConnection , PgDatabaseError , PgQueryResult , PgRow , PgTypeInfo , PgValueFormat , Postgres } ;
10+ use crate :: {
11+ statement:: PgStatement , PgArguments , PgConnection , PgDatabaseError , PgQueryResult , PgRow ,
12+ PgTypeInfo , PgValueFormat , Postgres ,
13+ } ;
814use futures_core:: future:: BoxFuture ;
915use futures_core:: stream:: BoxStream ;
1016use futures_core:: Stream ;
@@ -13,7 +19,6 @@ use sqlx_core::arguments::Arguments;
1319use sqlx_core:: sql_str:: SqlStr ;
1420use sqlx_core:: Either ;
1521use std:: { pin:: pin, sync:: Arc } ;
16- use sqlx_core:: connection:: Connection ;
1722
1823async fn prepare (
1924 conn : & mut PgConnection ,
@@ -196,7 +201,7 @@ impl PgConnection {
196201 sql : & str ,
197202 arguments : Option < & mut PgArguments > ,
198203 persistent : bool ,
199- metadata_opt : Option < Arc < PgStatementMetadata > >
204+ metadata_opt : Option < Arc < PgStatementMetadata > > ,
200205 ) -> Result < ( PgValueFormat , Arc < PgStatementMetadata > ) , Error > {
201206 let metadata: Arc < PgStatementMetadata > ;
202207
@@ -297,12 +302,9 @@ impl PgConnection {
297302 // before we continue, wait until we are "ready" to accept more queries
298303 self . wait_until_ready ( ) . await ?;
299304
300- let ( mut format, mut metadata) = self . try_get_or_prepare (
301- sql,
302- arguments. as_mut ( ) ,
303- persistent,
304- metadata_opt. clone ( )
305- ) . await ?;
305+ let ( mut format, mut metadata) = self
306+ . try_get_or_prepare ( sql, arguments. as_mut ( ) , persistent, metadata_opt. clone ( ) )
307+ . await ?;
306308
307309 let mut message = match self . inner . stream . recv ( ) . await {
308310 Ok ( msg) => msg,
@@ -311,26 +313,29 @@ impl PgConnection {
311313 // Save transaction mode. It will be lost after invalidating
312314 let is_in_tx = self . in_transaction ( ) ;
313315
314- self . invalidate_cached_statement ( sql, clear_backend_cache) . await ?;
316+ self . invalidate_cached_statement ( sql, clear_backend_cache)
317+ . await ?;
315318
316319 // If we were in transaction mode we can't retry statement,
317320 // so we can immediately return err
318321 if is_in_tx {
319- return Err ( err)
322+ return Err ( err) ;
320323 }
321324
322325 // Otherwise we can retry statement in hope everything is ok.
323- ( format, metadata) = self . try_get_or_prepare (
324- sql,
325- // It should be safe to retry `patch` on the same arguments
326- arguments. as_mut ( ) ,
327- persistent,
328- metadata_opt. clone ( )
329- ) . await ?;
326+ ( format, metadata) = self
327+ . try_get_or_prepare (
328+ sql,
329+ // It should be safe to retry `patch` on the same arguments
330+ arguments. as_mut ( ) ,
331+ persistent,
332+ metadata_opt. clone ( ) ,
333+ )
334+ . await ?;
330335
331336 self . inner . stream . recv ( ) . await ?
332337 } else {
333- return Err ( err)
338+ return Err ( err) ;
334339 }
335340 }
336341 } ;
@@ -536,19 +541,15 @@ impl<'c> Executor<'c> for &'c mut PgConnection {
536541// transaction pooling mode
537542// - `Some(true)` - if we should invalidate both backend and frontend caches
538543fn check_stale_plan ( error : & Error ) -> Option < bool > {
539- let Some ( db_err) = error. as_database_error ( ) else {
540- return None ;
541- } ;
542- let Some ( pg) = db_err. try_downcast_ref :: < PgDatabaseError > ( ) else {
543- return None ;
544- } ;
544+ let error = error
545+ . as_database_error ( ) ?
546+ . try_downcast_ref :: < PgDatabaseError > ( ) ?;
545547
546- match ( pg . code ( ) , pg . routine ( ) ) {
548+ match ( error . code ( ) , error . routine ( ) ) {
547549 // "cached plan must not change result type"
548550 ( "0A000" , Some ( "RevalidateCachedQuery" ) ) => Some ( true ) ,
549551 // DISCARD ALL / DEALLOCATE / pgbouncer
550552 ( "26000" , _) => Some ( false ) ,
551553 _ => None ,
552554 }
553555}
554-
0 commit comments