Skip to content

Commit

Permalink
GH-3530: The SqlServer 2008 driver does not support the DbDataReader.…
Browse files Browse the repository at this point in the history
…GetChar method, wrap it in a SqlServerDbDataReader.
  • Loading branch information
David Ellingsworth authored and David Ellingsworth committed Jun 11, 2024
1 parent 1c18cfe commit cd6fa30
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/NHibernate/AdoNet/SqlServerDbDataReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

public override char GetChar(int ordinal)
{
// SQL Server does not support GetChar
var value = DataReader[ordinal];

return value switch
{
string { Length: > 0 } s => s[0],
_ => (char) value
};
}
}
}
37 changes: 37 additions & 0 deletions src/NHibernate/Async/Driver/Sql2008ClientDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
// <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.Data;
using System.Data.Common;
using NHibernate.Util;
using NHibernate.AdoNet;

namespace NHibernate.Driver
{
using System.Threading.Tasks;
using System.Threading;
public partial class Sql2008ClientDriver : SqlClientDriver
{

#if NETFX
#else

#endif

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

return new SqlServerDbDataReader(reader);
}
}
}
10 changes: 9 additions & 1 deletion src/NHibernate/Driver/Sql2008ClientDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
using System.Data;
using System.Data.Common;
using NHibernate.Util;
using NHibernate.AdoNet;

namespace NHibernate.Driver
{
public class Sql2008ClientDriver : SqlClientDriver
public partial class Sql2008ClientDriver : SqlClientDriver
{
const byte MaxTime = 5;

Expand Down Expand Up @@ -34,5 +35,12 @@ protected override void InitializeParameter(DbParameter dbParam, string name, Sq

/// <inheritdoc />
public override DateTime MinDate => DateTime.MinValue;

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

return new SqlServerDbDataReader(reader);
}
}
}

0 comments on commit cd6fa30

Please sign in to comment.