@@ -16,14 +16,13 @@ use diesel::pg::{
16
16
} ;
17
17
use diesel:: query_builder:: bind_collector:: RawBytesBindCollector ;
18
18
use diesel:: query_builder:: { AsQuery , QueryBuilder , QueryFragment , QueryId } ;
19
- use diesel:: result:: DatabaseErrorKind ;
19
+ use diesel:: result:: { DatabaseErrorKind , Error } ;
20
20
use diesel:: { ConnectionError , ConnectionResult , QueryResult } ;
21
21
use futures_util:: future:: BoxFuture ;
22
22
use futures_util:: future:: Either ;
23
23
use futures_util:: stream:: { BoxStream , TryStreamExt } ;
24
24
use futures_util:: TryFutureExt ;
25
25
use futures_util:: { Future , FutureExt , StreamExt } ;
26
- use std:: borrow:: Cow ;
27
26
use std:: collections:: HashMap ;
28
27
use std:: sync:: Arc ;
29
28
use tokio:: sync:: broadcast;
@@ -432,6 +431,7 @@ impl AsyncPgConnection {
432
431
PgTypeMetadata :: from_result ( Ok ( type_metadata) )
433
432
} ;
434
433
let ( fake_oid, fake_array_oid) = metadata_lookup. fake_oids ( index) ;
434
+ let [ real_oid, real_array_oid] = unwrap_oids ( & real_metadata) ;
435
435
real_oids. extend ( [
436
436
( fake_oid, real_metadata. oid ( ) ?) ,
437
437
( fake_array_oid, real_metadata. array_oid ( ) ?) ,
@@ -440,7 +440,7 @@ impl AsyncPgConnection {
440
440
441
441
// Replace fake OIDs with real OIDs in `bind_collector.metadata`
442
442
for m in & mut bind_collector. metadata {
443
- let [ oid, array_oid] = [ m . oid ( ) ? , m . array_oid ( ) ? ]
443
+ let [ oid, array_oid] = unwrap_oids ( & m )
444
444
. map ( |oid| {
445
445
real_oids
446
446
. get ( & oid)
@@ -453,8 +453,8 @@ impl AsyncPgConnection {
453
453
* m = PgTypeMetadata :: new ( oid, array_oid) ;
454
454
}
455
455
// Replace fake OIDs with real OIDs in `bind_collector.binds`
456
- for location in fake_oid_locations {
457
- replace_fake_oid ( & mut bind_collector. binds , & real_oids, location )
456
+ for ( bind_index , byte_index ) in fake_oid_locations {
457
+ replace_fake_oid ( & mut bind_collector. binds , & real_oids, bind_index , byte_index )
458
458
. ok_or_else ( || {
459
459
Error :: SerializationError (
460
460
format ! ( "diesel_async failed to replace a type OID serialized in bind value {bind_index}" ) . into ( ) ,
@@ -577,10 +577,16 @@ async fn lookup_type(
577
577
Ok ( ( r. get ( 0 ) , r. get ( 1 ) ) )
578
578
}
579
579
580
+ fn unwrap_oids ( metadata : & PgTypeMetadata ) -> [ u32 ; 2 ] {
581
+ [ metadata. oid ( ) , metadata. array_oid ( ) ]
582
+ . map ( |oid| oid. expect ( "PgTypeMetadata is supposed to always be Ok here" ) )
583
+ }
584
+
580
585
fn replace_fake_oid (
581
586
binds : & mut [ Option < Vec < u8 > > ] ,
582
- real_oids : HashMap < u32 , u32 > ,
583
- ( bind_index, byte_index) : ( usize , usize ) ,
587
+ real_oids : & HashMap < u32 , u32 > ,
588
+ bind_index : usize ,
589
+ byte_index : usize ,
584
590
) -> Option < ( ) > {
585
591
let serialized_oid = binds
586
592
. get_mut ( bind_index) ?
0 commit comments