@@ -421,86 +421,91 @@ internal Task UpdateModelAsync(bool suppressException, CancellationToken cancell
421421
422422 internal static async Task UpdateModelAsync ( string connectionString , string currentSchema , bool suppressException , CancellationToken cancellationToken , params IModelDataProvider [ ] updaters )
423423 {
424- using ( var connection = new OracleConnection ( ) )
424+ using ( var connection = new OracleConnection { ConnectionString = connectionString } )
425425 {
426- using ( var command = connection . CreateCommand ( ) )
427- {
428- command . BindByName = true ;
426+ await UpdateModelAsync ( connection , currentSchema , suppressException , cancellationToken , updaters ) ;
427+ await connection . CloseAsynchronous ( cancellationToken ) ;
428+ }
429+ }
430+
431+ internal static async Task UpdateModelAsync ( OracleConnection connection , string currentSchema , bool suppressException , CancellationToken cancellationToken , params IModelDataProvider [ ] updaters )
432+ {
433+ using ( var command = connection . CreateCommand ( ) )
434+ {
435+ command . BindByName = true ;
429436
430- OracleTransaction transaction = null ;
437+ OracleTransaction transaction = null ;
431438
432- try
439+ try
440+ {
441+ foreach ( var updater in updaters )
433442 {
434- foreach ( var updater in updaters )
435- {
436- command . ResetParametersToAvoidOdacBug ( ) ;
437- command . CommandText = String . Empty ;
438- command . CommandType = CommandType . Text ;
439- updater . InitializeCommand ( command ) ;
443+ command . ResetParametersToAvoidOdacBug ( ) ;
444+ command . CommandText = String . Empty ;
445+ command . CommandType = CommandType . Text ;
446+ updater . InitializeCommand ( command ) ;
440447
441- try
448+ try
449+ {
450+ if ( updater . IsValid )
442451 {
443- if ( updater . IsValid )
452+ if ( connection . State == ConnectionState . Closed )
444453 {
445- if ( await connection . EnsureConnectionOpen ( connectionString , cancellationToken ) )
446- {
447- connection . ModuleName = "SQLPad backround" ;
448- connection . ActionName = "Model data provider" ;
454+ await connection . OpenAsynchronous ( cancellationToken ) ;
455+ connection . ModuleName = "SQLPad backround" ;
456+ connection . ActionName = "Model data provider" ;
449457
450- if ( ! String . IsNullOrEmpty ( currentSchema ) )
458+ if ( ! String . IsNullOrEmpty ( currentSchema ) )
459+ {
460+ using ( var setSchemaCommand = connection . CreateCommand ( ) )
451461 {
452- using ( var setSchemaCommand = connection . CreateCommand ( ) )
453- {
454- await setSchemaCommand . SetSchema ( currentSchema , cancellationToken ) ;
455- }
462+ await setSchemaCommand . SetSchema ( currentSchema , cancellationToken ) ;
456463 }
457-
458- transaction = connection . BeginTransaction ( ) ;
459464 }
460465
461- if ( updater . HasScalarResult )
466+ transaction = connection . BeginTransaction ( ) ;
467+ }
468+
469+ if ( updater . HasScalarResult )
470+ {
471+ var result = await command . ExecuteScalarAsynchronous ( cancellationToken ) ;
472+ updater . MapScalarValue ( result ) ;
473+ }
474+ else
475+ {
476+ using ( var reader = await command . ExecuteReaderAsynchronous ( CommandBehavior . Default , cancellationToken ) )
462477 {
463- var result = await command . ExecuteScalarAsynchronous ( cancellationToken ) ;
464- updater . MapScalarValue ( result ) ;
465- }
466- else
467- {
468- using ( var reader = await command . ExecuteReaderAsynchronous ( CommandBehavior . Default , cancellationToken ) )
469- {
470- await updater . MapReaderData ( reader , cancellationToken ) ;
471- }
478+ await updater . MapReaderData ( reader , cancellationToken ) ;
472479 }
473480 }
474481 }
475- catch ( OracleException exception )
482+ }
483+ catch ( OracleException exception )
484+ {
485+ if ( exception . Number == ( int ) OracleErrorCode . UserInvokedCancellation )
476486 {
477- if ( exception . Number == ( int ) OracleErrorCode . UserInvokedCancellation )
478- {
479- break ;
480- }
481-
482- throw ;
487+ break ;
483488 }
484- }
485- }
486- catch ( Exception e )
487- {
488- Trace . WriteLine ( $ "Update model failed: { e } ") ;
489489
490- if ( ! suppressException )
491- {
492490 throw ;
493491 }
494492 }
495- finally
496- {
497- if ( transaction != null )
498- {
499- await transaction . RollbackAsynchronous ( ) ;
500- transaction . Dispose ( ) ;
501- }
493+ }
494+ catch ( Exception e )
495+ {
496+ Trace . WriteLine ( $ "Update model failed: { e } ") ;
502497
503- await connection . CloseAsynchronous ( cancellationToken ) ;
498+ if ( ! suppressException )
499+ {
500+ throw ;
501+ }
502+ }
503+ finally
504+ {
505+ if ( transaction != null )
506+ {
507+ await transaction . RollbackAsynchronous ( ) ;
508+ transaction . Dispose ( ) ;
504509 }
505510 }
506511 }
0 commit comments