Oracle Dialect support for Unsigned Int (UInt32, UInt64)
Description
Environment
Activity
Brendan Kowitz July 15, 2008 at 12:29 AM
Just for the record, after some testing, I've refactored the code we are using to the following, which removes the need for a dependency on Oracle.DataAccess. The Oracle documentation states that DbType.Decimal also maps directly into the oracle provider's decimal type:
protected override void InitializeParameter(System.Data.IDbDataParameter dbParam, string name, NHibernate.SqlTypes.SqlType sqlType)
{
//more information about mapping to native oracle types:
//http://download.oracle.com/docs/cd/B28359_01/win.111/e10927/featOraCommand.htm#sthref279
switch(sqlType.DbType)
{
case DbType.UInt16:
case DbType.UInt32:
case DbType.UInt64:
//The Oracle provider does not know about 'unsigned int', however these values fit into DbType.Decimal
dbParam.DbType = DbType.Decimal;
break;
default:
//Let the base driver class in NHibernate handle the parameter initialisation
base.InitializeParameter(dbParam, name, sqlType);
return;
}
dbParam.ParameterName = FormatNameForParameter(name);
}
Fabio Maulo July 12, 2008 at 5:03 PM
Fixed the first part of this issue (Dialect)
For the second we prefer not introduce the dependency.
Like you sure know you can inherit from NHibernate.Driver.OracleDataClientDriver and override the method, then you must configure your derive trough session-factory configuration.
BTW your patch is now available to the community.
Thanks.
The Oracle9Dialect and OracleDataClientDriver do not support Unsigned ints
This can be fixed by registering the appropriate column types:
This will allow the schema export to succeed.
public class Oracle9Dialect : Dialect
{
public Oracle9Dialect()
{
RegisterColumnType(DbType.UInt16, "NUMBER(5,0)");
RegisterColumnType(DbType.UInt32, "NUMBER(10,0)");
RegisterColumnType(DbType.UInt64, "NUMBER(20,0)");
...
Getting the values back to NHibernate also requires the OracleDataClientDriver to be modified,
Don't know how this code will fit into the codebase with a dependency on Oracle.DataAccess..
protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
{
//more information about mapping to native oracle types:
//http://download-uk.oracle.com/docs/cd/B19306_01/win.102/b14306/appendixa.htm#BEHJHHJG
OracleDbType oraType;
if(sqlType.DbType == DbType.UInt16)
{
oraType = OracleDbType.Decimal;
}
else if(sqlType.DbType == DbType.UInt32)
{
oraType = OracleDbType.Decimal;
}
else if(sqlType.DbType == DbType.UInt64)
{
oraType = OracleDbType.Decimal;
}
else if(sqlType.DbType == DbType.Int64)
{
oraType = OracleDbType.Decimal;
}
else if(sqlType.DbType == DbType.DateTime)
{
oraType = OracleDbType.TimeStamp;
}
else
{
//Let the base driver class in NHibernate handle the parameter initialisation
base.InitializeParameter(dbParam, name, sqlType);
return;
}
dbParam.ParameterName = FormatNameForParameter(name);
((OracleParameter)dbParam).OracleDbType = oraType;
...