-
Notifications
You must be signed in to change notification settings - Fork 933
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-3530: The Oracle driver does not support DbDataReader.GetChar and …
…does not convert strings to datetime values. Add a custom OracleDbDataReader to address these issues.
- Loading branch information
David Ellingsworth
authored and
David Ellingsworth
committed
Jun 10, 2024
1 parent
32a5034
commit b97a5cb
Showing
3 changed files
with
91 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Data.Common; | ||
|
||
namespace NHibernate.AdoNet | ||
{ | ||
public class OracleDbDataReader : DbDataReaderWrapper | ||
{ | ||
private readonly string _timestampFormat; | ||
|
||
public OracleDbDataReader(DbDataReader reader, string timestampFormat) | ||
: base(reader) | ||
{ | ||
_timestampFormat = timestampFormat; | ||
} | ||
|
||
// Oracle driver does not implement GetChar | ||
public override char GetChar(int ordinal) | ||
{ | ||
var str = GetString(ordinal); | ||
|
||
return str is null ? throw new InvalidCastException() : str[0]; | ||
} | ||
|
||
public override DateTime GetDateTime(int ordinal) | ||
{ | ||
var value = DataReader[ordinal]; | ||
|
||
if (value is string && _timestampFormat != null) | ||
{ | ||
return ParseDate((string)value); | ||
} | ||
|
||
return (DateTime) value; | ||
} | ||
|
||
private DateTime ParseDate(string value) | ||
{ | ||
// Need to implment rules according to https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Format-Models.html#GUID-49B32A81-0904-433E-B7FE-51606672183A | ||
throw new NotImplementedException($"Should parse '{value}' using '{_timestampFormat}'"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters