forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nhibernateGH-3530: The Oracle driver does not support DbDataReader.Ge…
…tChar 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 11, 2024
1 parent
4da33b7
commit b6b55f4
Showing
3 changed files
with
95 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,46 @@ | ||
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 value = DataReader[ordinal]; | ||
|
||
return value switch | ||
{ | ||
string { Length: > 0 } s => s[0], | ||
_ => (char) value | ||
}; | ||
} | ||
|
||
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