1313using Xtensive . Orm ;
1414using Xtensive . Sql . Info ;
1515using Xtensive . Sql . Drivers . PostgreSql . Resources ;
16- using System . Collections . Generic ;
1716
1817namespace Xtensive . Sql . Drivers . PostgreSql
1918{
@@ -67,9 +66,9 @@ protected override SqlDriver CreateDriver(string connectionString, SqlDriverConf
6766 else
6867 OpenConnectionFast ( connection , configuration , false ) . GetAwaiter ( ) . GetResult ( ) ;
6968 var version = GetVersion ( configuration , connection ) ;
70- var serverTimezones = GetServerTimeZones ( connection , false ) . GetAwaiter ( ) . GetResult ( ) ;
7169 var defaultSchema = GetDefaultSchema ( connection ) ;
72- return CreateDriverInstance ( connectionString , version , defaultSchema , serverTimezones , connection . Timezone ) ;
70+ var defaultTimeZoneInfo = PostgreSqlHelper . GetTimeZoneInfoForServerTimeZone ( connection . Timezone ) ;
71+ return CreateDriverInstance ( connectionString , version , defaultSchema , defaultTimeZoneInfo ) ;
7372 }
7473
7574 /// <inheritdoc/>
@@ -87,9 +86,9 @@ protected override async Task<SqlDriver> CreateDriverAsync(
8786 else
8887 await OpenConnectionFast ( connection , configuration , true , token ) . ConfigureAwait ( false ) ;
8988 var version = GetVersion ( configuration , connection ) ;
90- var serverTimezones = await GetServerTimeZones ( connection , true , token ) . ConfigureAwait ( false ) ;
9189 var defaultSchema = await GetDefaultSchemaAsync ( connection , token : token ) . ConfigureAwait ( false ) ;
92- return CreateDriverInstance ( connectionString , version , defaultSchema , serverTimezones , connection . Timezone ) ;
90+ var defaultTimeZoneInfo = PostgreSqlHelper . GetTimeZoneInfoForServerTimeZone ( connection . Timezone ) ;
91+ return CreateDriverInstance ( connectionString , version , defaultSchema , defaultTimeZoneInfo ) ;
9392 }
9493 }
9594
@@ -103,7 +102,7 @@ private static Version GetVersion(SqlDriverConfiguration configuration, NpgsqlCo
103102
104103 private static SqlDriver CreateDriverInstance (
105104 string connectionString , Version version , DefaultSchemaInfo defaultSchema ,
106- Dictionary < string , TimeSpan > timezones , string defaultTimeZone )
105+ TimeZoneInfo defaultTimeZone )
107106 {
108107 var coreServerInfo = new CoreServerInfo {
109108 ServerVersion = version ,
@@ -116,7 +115,6 @@ private static SqlDriver CreateDriverInstance(
116115 var pgsqlServerInfo = new PostgreServerInfo ( ) {
117116 InfinityAliasForDatesEnabled = InfinityAliasForDatesEnabled ,
118117 LegacyTimestampBehavior = LegacyTimestamptBehaviorEnabled ,
119- ServerTimeZones = timezones ,
120118 DefaultTimeZone = defaultTimeZone
121119 } ;
122120
@@ -204,44 +202,7 @@ await SqlHelper.NotifyConnectionInitializingAsync(accessors,
204202 }
205203 }
206204
207- private static async ValueTask < Dictionary < string , TimeSpan > > GetServerTimeZones ( NpgsqlConnection connection , bool isAsync , CancellationToken token = default )
208- {
209- var resultZones = new Dictionary < string , TimeSpan > ( ) ;
210-
211- var command = connection . CreateCommand ( ) ;
212- command . CommandText = "SELECT \" name\" , \" abbrev\" , \" utc_offset\" , \" is_dst\" FROM pg_timezone_names" ;
213- if ( isAsync ) {
214- await using ( command )
215- await using ( var reader = await command . ExecuteReaderAsync ( ) ) {
216- while ( await reader . ReadAsync ( ) ) {
217- ReadTimezoneRow ( reader , resultZones ) ;
218- }
219- }
220- }
221- else {
222- using ( command )
223- using ( var reader = command . ExecuteReader ( ) ) {
224- while ( reader . Read ( ) ) {
225- ReadTimezoneRow ( reader , resultZones ) ;
226- }
227- }
228- }
229- return resultZones ;
230-
231-
232- static void ReadTimezoneRow ( NpgsqlDataReader reader , Dictionary < string , TimeSpan > zones )
233- {
234- var name = reader . GetString ( 0 ) ;
235- var abbrev = reader . GetString ( 1 ) ;
236- var utcOffset = PostgreSqlHelper . ResurrectTimeSpanFromNpgsqlInterval ( reader . GetFieldValue < NpgsqlTypes . NpgsqlInterval > ( 2 ) ) ;
237-
238- _ = zones . TryAdd ( name , utcOffset ) ;
239- //flatten results for search convinience
240- if ( ! string . IsNullOrEmpty ( abbrev ) ) {
241- _ = zones . TryAdd ( abbrev , utcOffset ) ;
242- }
243- }
244- }
205+ #region Helpers
245206
246207 private static bool SetOrGetExistingDisableInfinityAliasForDatesSwitch ( bool valueToSet ) =>
247208 GetSwitchValueOrSet ( Orm . PostgreSql . WellKnown . DateTimeToInfinityConversionSwitchName , valueToSet ) ;
@@ -260,6 +221,8 @@ private static bool GetSwitchValueOrSet(string switchName, bool valueToSet)
260221 }
261222 }
262223
224+ #endregion
225+
263226 static DriverFactory ( )
264227 {
265228 // Starging from Npgsql 6.0 they broke compatibility by forcefully replacing
0 commit comments