@@ -47,8 +47,10 @@ protected virtual void RegisterColumnTypes()
47
47
RegisterColumnType ( DbType . UInt16 , "INTEGER" ) ;
48
48
RegisterColumnType ( DbType . UInt32 , "INTEGER" ) ;
49
49
RegisterColumnType ( DbType . UInt64 , "INTEGER" ) ;
50
- RegisterColumnType ( DbType . Currency , "NUMERIC" ) ;
51
- RegisterColumnType ( DbType . Decimal , "NUMERIC" ) ;
50
+ RegisterColumnType ( DbType . Currency , "REAL" ) ;
51
+ // NUMERIC is not an option here, because it can store the value as INTEGER when it does not contain a decimal point,
52
+ // which causes an invalid result when using division operator (e.g. 19/2 would return 9 if NUMERIC is used)
53
+ RegisterColumnType ( DbType . Decimal , "REAL" ) ;
52
54
RegisterColumnType ( DbType . Double , "DOUBLE" ) ;
53
55
RegisterColumnType ( DbType . Single , "DOUBLE" ) ;
54
56
RegisterColumnType ( DbType . VarNumeric , "NUMERIC" ) ;
@@ -100,7 +102,7 @@ protected virtual void RegisterFunctions()
100
102
RegisterFunction ( "bxor" , new SQLFunctionTemplate ( null , "((?1 | ?2) - (?1 & ?2))" ) ) ;
101
103
102
104
// NH-3787: SQLite requires the cast in SQL too for not defaulting to string.
103
- RegisterFunction ( "transparentcast" , new CastFunction ( ) ) ;
105
+ RegisterFunction ( "transparentcast" , new SQLiteCastFunction ( ) ) ;
104
106
105
107
if ( _binaryGuid )
106
108
RegisterFunction ( "strguid" , new SQLFunctionTemplate ( NHibernateUtil . String , "substr(hex(?1), 7, 2) || substr(hex(?1), 5, 2) || substr(hex(?1), 3, 2) || substr(hex(?1), 1, 2) || '-' || substr(hex(?1), 11, 2) || substr(hex(?1), 9, 2) || '-' || substr(hex(?1), 15, 2) || substr(hex(?1), 13, 2) || '-' || substr(hex(?1), 17, 4) || '-' || substr(hex(?1), 21) " ) ) ;
@@ -473,8 +475,10 @@ protected class SQLiteCastFunction : CastFunction
473
475
{
474
476
protected override bool CastingIsRequired ( string sqlType )
475
477
{
476
- // SQLite doesn't support casting to datetime types. It assumes you want an integer and destroys the date string.
477
- if ( StringHelper . ContainsCaseInsensitive ( sqlType , "date" ) || StringHelper . ContainsCaseInsensitive ( sqlType , "time" ) )
478
+ // SQLite doesn't support casting to datetime or uniqueidentifier types. It assumes you want an integer and destroys the date or uniqueidentifier string.
479
+ if ( StringHelper . ContainsCaseInsensitive ( sqlType , "date" ) ||
480
+ StringHelper . ContainsCaseInsensitive ( sqlType , "time" ) ||
481
+ StringHelper . ContainsCaseInsensitive ( sqlType , "uniqueidentifier" ) )
478
482
return false ;
479
483
return true ;
480
484
}
0 commit comments