Skip to content

Commit

Permalink
nhibernateGH-3530: Firebird incorrectly uses the current culture to c…
Browse files Browse the repository at this point in the history
…onvert dates stores as strings. Address this issue by adding a FirebirdDbDataReader.
  • Loading branch information
David Ellingsworth authored and David Ellingsworth committed Jun 11, 2024
1 parent ec49d5f commit 4b010ce
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/NHibernate/AdoNet/FirebirdDbDataReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate.Id.Insert;

namespace NHibernate.AdoNet
{
public class FirebirdDbDataReader : DbDataReaderWrapper
{
public FirebirdDbDataReader(DbDataReader reader) : base(reader) { }

public override DateTime GetDateTime(int ordinal)
{
var value = DataReader[ordinal];

return value switch
{
string s => DateTime.Parse(s, CultureInfo.InvariantCulture),
_ => (DateTime) value
};
}
}
}
40 changes: 40 additions & 0 deletions src/NHibernate/Async/Driver/FirebirdClientDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using NHibernate.AdoNet;
using NHibernate.Dialect;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;
using NHibernate.Util;
using Environment = NHibernate.Cfg.Environment;

namespace NHibernate.Driver
{
using System.Threading.Tasks;
using System.Threading;
public partial class FirebirdClientDriver : ReflectionBasedDriver
{

public override async Task<DbDataReader> ExecuteReaderAsync(DbCommand command, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var reader = await (command.ExecuteReaderAsync(cancellationToken)).ConfigureAwait(false);

return new FirebirdDbDataReader(reader);
}
}
}
10 changes: 9 additions & 1 deletion src/NHibernate/Driver/FirebirdClientDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using NHibernate.AdoNet;
using NHibernate.Dialect;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;
Expand All @@ -17,7 +18,7 @@ namespace NHibernate.Driver
/// A NHibernate Driver for using the Firebird data provider located in
/// <c>FirebirdSql.Data.FirebirdClient</c> assembly.
/// </summary>
public class FirebirdClientDriver : ReflectionBasedDriver
public partial class FirebirdClientDriver : ReflectionBasedDriver
{
private const string SELECT_CLAUSE_EXP = @"(?<=\bselect\b|\bwhere\b).*";
private const string CAST_PARAMS_EXP =
Expand Down Expand Up @@ -212,5 +213,12 @@ public void ClearPool(string connectionString)
/// See http://tracker.firebirdsql.org/browse/DNET-766.
/// </summary>
public override bool SupportsEnlistmentWhenAutoEnlistmentIsDisabled => false;

public override DbDataReader ExecuteReader(DbCommand command)
{
var reader = command.ExecuteReader();

return new FirebirdDbDataReader(reader);
}
}
}

0 comments on commit 4b010ce

Please sign in to comment.