Skip to content

Commit cd6fa30

Browse files
David EllingsworthDavid Ellingsworth
David Ellingsworth
authored and
David Ellingsworth
committed
GH-3530: The SqlServer 2008 driver does not support the DbDataReader.GetChar method, wrap it in a SqlServerDbDataReader.
1 parent 1c18cfe commit cd6fa30

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data.Common;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace NHibernate.AdoNet
9+
{
10+
public class SqlServerDbDataReader : DbDataReaderWrapper
11+
{
12+
public SqlServerDbDataReader(DbDataReader reader) : base(reader) { }
13+
14+
public override char GetChar(int ordinal)
15+
{
16+
// SQL Server does not support GetChar
17+
var value = DataReader[ordinal];
18+
19+
return value switch
20+
{
21+
string { Length: > 0 } s => s[0],
22+
_ => (char) value
23+
};
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Data;
13+
using System.Data.Common;
14+
using NHibernate.Util;
15+
using NHibernate.AdoNet;
16+
17+
namespace NHibernate.Driver
18+
{
19+
using System.Threading.Tasks;
20+
using System.Threading;
21+
public partial class Sql2008ClientDriver : SqlClientDriver
22+
{
23+
24+
#if NETFX
25+
#else
26+
27+
#endif
28+
29+
public override async Task<DbDataReader> ExecuteReaderAsync(DbCommand command, CancellationToken cancellationToken)
30+
{
31+
cancellationToken.ThrowIfCancellationRequested();
32+
var reader = await (command.ExecuteReaderAsync(cancellationToken)).ConfigureAwait(false);
33+
34+
return new SqlServerDbDataReader(reader);
35+
}
36+
}
37+
}

src/NHibernate/Driver/Sql2008ClientDriver.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
using System.Data;
33
using System.Data.Common;
44
using NHibernate.Util;
5+
using NHibernate.AdoNet;
56

67
namespace NHibernate.Driver
78
{
8-
public class Sql2008ClientDriver : SqlClientDriver
9+
public partial class Sql2008ClientDriver : SqlClientDriver
910
{
1011
const byte MaxTime = 5;
1112

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

3536
/// <inheritdoc />
3637
public override DateTime MinDate => DateTime.MinValue;
38+
39+
public override DbDataReader ExecuteReader(DbCommand command)
40+
{
41+
var reader = command.ExecuteReader();
42+
43+
return new SqlServerDbDataReader(reader);
44+
}
3745
}
3846
}

0 commit comments

Comments
 (0)