Skip to content

Commit f5bfc17

Browse files
committed
Support for fb_info_creation_timestamp_tz (#936)
1 parent 2ea703d commit f5bfc17

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient.Tests/FbDatabaseInfoTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void CompleteDatabaseInfoTest()
5151
nameof(FbDatabaseInfo.GetReplicaModeAsync),
5252
nameof(FbDatabaseInfo.GetDbFileIdAsync),
5353
nameof(FbDatabaseInfo.GetDbGuidAsync),
54+
nameof(FbDatabaseInfo.GetCreationTimestampAsync),
5455
}.Contains(m.Name))
5556
continue;
5657

Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscHelper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ public static List<object> ParseDatabaseInfo(byte[] buffer)
166166
}
167167
break;
168168

169+
case IscCodes.fb_info_creation_timestamp_tz:
170+
{
171+
var date = TypeDecoder.DecodeDate((int)VaxInteger(buffer, pos, 4));
172+
var time = TypeDecoder.DecodeTime((int)VaxInteger(buffer, pos + 4, 4));
173+
var tzId = (ushort)VaxInteger(buffer, pos + 4 + 4, 4);
174+
var dt = date.Add(time);
175+
dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
176+
info.Add(TypeHelper.CreateZonedDateTime(dt, tzId, null));
177+
}
178+
break;
179+
169180
default:
170181
throw new ArgumentOutOfRangeException(nameof(type), $"{nameof(type)}={type}");
171182
}

Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbDatabaseInfo.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Threading;
2323
using System.Threading.Tasks;
2424
using FirebirdSql.Data.Common;
25+
using FirebirdSql.Data.Types;
2526

2627
namespace FirebirdSql.Data.FirebirdClient
2728
{
@@ -440,6 +441,15 @@ public Task<Guid> GetDbGuidAsync(CancellationToken cancellationToken = default)
440441
return GetValueAsync<Guid>(IscCodes.fb_info_db_guid, cancellationToken);
441442
}
442443

444+
public FbZonedDateTime GeCreationTimestamp()
445+
{
446+
return GetValue<FbZonedDateTime>(IscCodes.fb_info_creation_timestamp_tz);
447+
}
448+
public Task<FbZonedDateTime> GetCreationTimestampAsync(CancellationToken cancellationToken = default)
449+
{
450+
return GetValueAsync<FbZonedDateTime>(IscCodes.fb_info_creation_timestamp_tz, cancellationToken);
451+
}
452+
443453
#endregion
444454

445455
#region Constructors
@@ -463,7 +473,7 @@ private T GetValue<T>(byte item)
463473
IscCodes.isc_info_end
464474
};
465475
var info = Connection.InnerConnection.Database.GetDatabaseInfo(items);
466-
return info.Any() ? (T)Convert.ChangeType(info[0], typeof(T)) : default;
476+
return info.Any() ? (T)info[0]: default;
467477
}
468478
private async Task<T> GetValueAsync<T>(byte item, CancellationToken cancellationToken = default)
469479
{
@@ -475,7 +485,7 @@ private async Task<T> GetValueAsync<T>(byte item, CancellationToken cancellation
475485
IscCodes.isc_info_end
476486
};
477487
var info = await Connection.InnerConnection.Database.GetDatabaseInfoAsync(items, cancellationToken).ConfigureAwait(false);
478-
return info.Any() ? (T)Convert.ChangeType(info[0], typeof(T)) : default;
488+
return info.Any() ? (T)info[0] : default;
479489
}
480490

481491
private List<T> GetList<T>(byte item)

0 commit comments

Comments
 (0)