33using System . Diagnostics ;
44using System . Globalization ;
55using System . Text ;
6+ using System . Threading ;
67using System . Threading . Tasks ;
78using Microsoft . Extensions . Logging ;
89using Microsoft . Extensions . Logging . Abstractions ;
@@ -24,10 +25,10 @@ namespace Npgsql;
2425sealed class PostgresDatabaseInfoFactory : INpgsqlDatabaseInfoFactory
2526{
2627 /// <inheritdoc />
27- public async Task < NpgsqlDatabaseInfo ? > Load ( NpgsqlConnector conn , NpgsqlTimeout timeout , bool async )
28+ public async Task < NpgsqlDatabaseInfo ? > Load ( NpgsqlConnector conn , NpgsqlTimeout timeout , bool async , CancellationToken cancellationToken )
2829 {
2930 var db = new PostgresDatabaseInfo ( conn ) ;
30- await db . LoadPostgresInfo ( conn , timeout , async ) . ConfigureAwait( false) ;
31+ await db . LoadPostgresInfo ( conn , timeout , async , cancellationToken ) . ConfigureAwait( false) ;
3132 Debug. Assert( db. LongVersion != null ) ;
3233 return db ;
3334 }
@@ -80,7 +81,7 @@ class PostgresDatabaseInfo : NpgsqlDatabaseInfo
8081 public virtual bool HasTypeCategory => Version . IsGreaterOrEqual ( 8 , 4 ) ;
8182
8283 internal PostgresDatabaseInfo ( NpgsqlConnector conn )
83- : base ( conn . Host ! , conn . Port , conn . Database ! , conn . PostgresParameters [ "server_version" ] )
84+ : base ( conn . Host , conn . Port , conn . Database ! , conn . PostgresParameters [ "server_version" ] )
8485 => _connectionLogger = conn . LoggingConfiguration . ConnectionLogger ;
8586
8687 private protected PostgresDatabaseInfo ( string host , int port , string databaseName , string serverVersion )
@@ -93,16 +94,20 @@ private protected PostgresDatabaseInfo(string host, int port, string databaseNam
9394 /// <param name="conn">The database connection.</param>
9495 /// <param name="timeout">The timeout while loading types from the backend.</param>
9596 /// <param name="async">True to load types asynchronously.</param>
97+ /// <param name="cancellationToken">An optional token to cancel the asynchronous operation. The default value is <see cref="CancellationToken.None"/>.</param>
9698 /// <returns>
9799 /// A task representing the asynchronous operation.
98100 /// </returns>
99- internal async Task LoadPostgresInfo ( NpgsqlConnector conn , NpgsqlTimeout timeout , bool async )
101+ internal async Task LoadPostgresInfo ( NpgsqlConnector conn , NpgsqlTimeout timeout , bool async , CancellationToken cancellationToken )
100102 {
101- HasIntegerDateTimes =
102- conn . PostgresParameters . TryGetValue ( "integer_datetimes" , out var intDateTimes ) &&
103- intDateTimes == "on" ;
103+ using ( conn . StartUserAction ( ConnectorState . Executing , cancellationToken ) )
104+ {
105+ HasIntegerDateTimes =
106+ conn . PostgresParameters . TryGetValue ( "integer_datetimes" , out var intDateTimes ) &&
107+ intDateTimes == "on" ;
104108
105- _types = await LoadBackendTypes ( conn , timeout , async ) . ConfigureAwait ( false ) ;
109+ _types = await LoadBackendTypes ( conn , timeout , async ) . ConfigureAwait ( false ) ;
110+ }
106111 }
107112
108113 const string BuiltinSchemaListSqlFragment = "'pg_catalog', 'information_schema', 'pg_toast'" ;
@@ -205,7 +210,7 @@ FROM pg_enum
205210 /// </returns>
206211 /// <exception cref="TimeoutException" />
207212 /// <exception cref="ArgumentOutOfRangeException">Unknown typtype for type '{internalName}' in pg_type: {typeChar}.</exception>
208- internal async Task < List < PostgresType > > LoadBackendTypes ( NpgsqlConnector conn , NpgsqlTimeout timeout , bool async )
213+ async Task < List < PostgresType > > LoadBackendTypes ( NpgsqlConnector conn , NpgsqlTimeout timeout , bool async )
209214 {
210215 var versionQuery = "SELECT version();" ;
211216 var typeLoading = conn . DataSource . Configuration . TypeLoading ;
0 commit comments