@@ -395,71 +395,69 @@ internal void DeriveParameters()
395395
396396 void DeriveParametersForFunction ( )
397397 {
398- using ( var c = new NpgsqlCommand ( DeriveParametersForFunctionQuery , _connection ) )
399- {
400- c . Parameters . Add ( new NpgsqlParameter ( "proname" , NpgsqlDbType . Text ) ) ;
401- c . Parameters [ 0 ] . Value = CommandText ;
398+ using var c = new NpgsqlCommand ( DeriveParametersForFunctionQuery , _connection ) ;
399+ c . Parameters . Add ( new NpgsqlParameter ( "proname" , NpgsqlDbType . Text ) ) ;
400+ c . Parameters [ 0 ] . Value = CommandText ;
402401
403- string [ ] ? names = null ;
404- uint [ ] ? types = null ;
405- char [ ] ? modes = null ;
402+ string [ ] ? names = null ;
403+ uint [ ] ? types = null ;
404+ char [ ] ? modes = null ;
406405
407- using ( var rdr = c . ExecuteReader ( CommandBehavior . SingleRow | CommandBehavior . SingleResult ) )
406+ using ( var rdr = c . ExecuteReader ( CommandBehavior . SingleRow | CommandBehavior . SingleResult ) )
407+ {
408+ if ( rdr . Read ( ) )
408409 {
409- if ( rdr . Read ( ) )
410+ if ( ! rdr . IsDBNull ( 0 ) )
411+ names = rdr . GetValue ( 0 ) as string [ ] ;
412+ if ( ! rdr . IsDBNull ( 2 ) )
413+ types = rdr . GetValue ( 2 ) as uint [ ] ;
414+ if ( ! rdr . IsDBNull ( 3 ) )
415+ modes = rdr . GetValue ( 3 ) as char [ ] ;
416+ if ( types == null )
410417 {
411- if ( ! rdr . IsDBNull ( 0 ) )
412- names = rdr . GetValue ( 0 ) as string [ ] ;
413- if ( ! rdr . IsDBNull ( 2 ) )
414- types = rdr . GetValue ( 2 ) as uint [ ] ;
415- if ( ! rdr . IsDBNull ( 3 ) )
416- modes = rdr . GetValue ( 3 ) as char [ ] ;
417- if ( types == null )
418- {
419- if ( rdr . IsDBNull ( 1 ) || rdr . GetFieldValue < uint [ ] > ( 1 ) . Length == 0 )
420- return ; // Parameter-less function
421- types = rdr . GetFieldValue < uint [ ] > ( 1 ) ;
422- }
418+ if ( rdr . IsDBNull ( 1 ) || rdr . GetFieldValue < uint [ ] > ( 1 ) . Length == 0 )
419+ return ; // Parameter-less function
420+ types = rdr . GetFieldValue < uint [ ] > ( 1 ) ;
423421 }
424- else
425- throw new InvalidOperationException ( $ "{ CommandText } does not exist in pg_proc") ;
426422 }
423+ else
424+ throw new InvalidOperationException ( $ "{ CommandText } does not exist in pg_proc") ;
425+ }
427426
428- var typeMapper = c . _connection ! . Connector ! . TypeMapper ;
427+ var typeMapper = c . _connection ! . Connector ! . TypeMapper ;
429428
430- for ( var i = 0 ; i < types . Length ; i ++ )
431- {
432- var param = new NpgsqlParameter ( ) ;
429+ for ( var i = 0 ; i < types . Length ; i ++ )
430+ {
431+ var param = new NpgsqlParameter ( ) ;
433432
434- var ( npgsqlDbType , postgresType ) = typeMapper . GetTypeInfoByOid ( types [ i ] ) ;
433+ var ( npgsqlDbType , postgresType ) = typeMapper . GetTypeInfoByOid ( types [ i ] ) ;
435434
436- param . DataTypeName = postgresType . DisplayName ;
437- param . PostgresType = postgresType ;
438- if ( npgsqlDbType . HasValue )
439- param . NpgsqlDbType = npgsqlDbType . Value ;
435+ param . DataTypeName = postgresType . DisplayName ;
436+ param . PostgresType = postgresType ;
437+ if ( npgsqlDbType . HasValue )
438+ param . NpgsqlDbType = npgsqlDbType . Value ;
440439
441- if ( names != null && i < names . Length )
442- param . ParameterName = names [ i ] ;
443- else
444- param . ParameterName = "parameter" + ( i + 1 ) ;
440+ if ( names != null && i < names . Length )
441+ param . ParameterName = names [ i ] ;
442+ else
443+ param . ParameterName = "parameter" + ( i + 1 ) ;
445444
446- if ( modes == null ) // All params are IN, or server < 8.1.0 (and only IN is supported)
447- param . Direction = ParameterDirection . Input ;
448- else
445+ if ( modes == null ) // All params are IN, or server < 8.1.0 (and only IN is supported)
446+ param . Direction = ParameterDirection . Input ;
447+ else
448+ {
449+ param . Direction = modes [ i ] switch
449450 {
450- param . Direction = modes [ i ] switch
451- {
452- 'i' => ParameterDirection . Input ,
453- 'o' => ParameterDirection . Output ,
454- 't' => ParameterDirection . Output ,
455- 'b' => ParameterDirection . InputOutput ,
456- 'v' => throw new NotSupportedException ( "Cannot derive function parameter of type VARIADIC" ) ,
457- _ => throw new ArgumentOutOfRangeException ( "Unknown code in proargmodes while deriving: " + modes [ i ] )
458- } ;
459- }
460-
461- Parameters . Add ( param ) ;
451+ 'i' => ParameterDirection . Input ,
452+ 'o' => ParameterDirection . Output ,
453+ 't' => ParameterDirection . Output ,
454+ 'b' => ParameterDirection . InputOutput ,
455+ 'v' => throw new NotSupportedException ( "Cannot derive function parameter of type VARIADIC" ) ,
456+ _ => throw new ArgumentOutOfRangeException ( "Unknown code in proargmodes while deriving: " + modes [ i ] )
457+ } ;
462458 }
459+
460+ Parameters . Add ( param ) ;
463461 }
464462 }
465463
@@ -974,12 +972,12 @@ public override Task<int> ExecuteNonQueryAsync(CancellationToken cancellationTok
974972 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
975973 async Task < int > ExecuteNonQuery ( bool async , CancellationToken cancellationToken )
976974 {
977- using ( var reader = await ExecuteReaderAsync ( CommandBehavior . Default , async, cancellationToken ) )
978- {
979- while ( async ? await reader . NextResultAsync ( cancellationToken ) : reader . NextResult ( ) ) { }
980- reader . Close ( ) ;
981- return reader . RecordsAffected ;
982- }
975+ using var reader = await ExecuteReaderAsync ( CommandBehavior . Default , async, cancellationToken ) ;
976+ while ( async ? await reader . NextResultAsync ( cancellationToken ) : reader . NextResult ( ) ) ;
977+
978+ reader . Close ( ) ;
979+
980+ return reader . RecordsAffected ;
983981 }
984982
985983 #endregion Execute Non Query
@@ -1018,8 +1016,9 @@ public override Task<object> ExecuteScalarAsync(CancellationToken cancellationTo
10181016 var behavior = CommandBehavior . SingleRow ;
10191017 if ( ! Parameters . HasOutputParameters )
10201018 behavior |= CommandBehavior . SequentialAccess ;
1021- using ( var reader = await ExecuteReaderAsync ( behavior , async , cancellationToken ) )
1022- return reader. Read( ) && reader. FieldCount != 0 ? reader . GetValue ( 0 ) : null ;
1019+
1020+ using var reader = await ExecuteReaderAsync ( behavior , async , cancellationToken ) ;
1021+ return reader . Read ( ) && reader . FieldCount != 0 ? reader . GetValue ( 0 ) : null ;
10231022 }
10241023
10251024 #endregion Execute Scalar
0 commit comments