@@ -40,8 +40,10 @@ protected virtual void RegisterColumnTypes()
40
40
RegisterColumnType ( DbType . UInt16 , "INTEGER" ) ;
41
41
RegisterColumnType ( DbType . UInt32 , "INTEGER" ) ;
42
42
RegisterColumnType ( DbType . UInt64 , "INTEGER" ) ;
43
- RegisterColumnType ( DbType . Currency , "NUMERIC" ) ;
44
- RegisterColumnType ( DbType . Decimal , "NUMERIC" ) ;
43
+ RegisterColumnType ( DbType . Currency , "REAL" ) ;
44
+ // NUMERIC is not an option here, because it can store the value as INTEGER when it does not contain a decimal point,
45
+ // which causes an invalid result when using division operator (e.g. 19/2 would return 9 if NUMERIC is used)
46
+ RegisterColumnType ( DbType . Decimal , "REAL" ) ;
45
47
RegisterColumnType ( DbType . Double , "DOUBLE" ) ;
46
48
RegisterColumnType ( DbType . Single , "DOUBLE" ) ;
47
49
RegisterColumnType ( DbType . VarNumeric , "NUMERIC" ) ;
@@ -93,7 +95,7 @@ protected virtual void RegisterFunctions()
93
95
RegisterFunction ( "bxor" , new SQLFunctionTemplate ( null , "((?1 | ?2) - (?1 & ?2))" ) ) ;
94
96
95
97
// NH-3787: SQLite requires the cast in SQL too for not defaulting to string.
96
- RegisterFunction ( "transparentcast" , new CastFunction ( ) ) ;
98
+ RegisterFunction ( "transparentcast" , new SQLiteCastFunction ( ) ) ;
97
99
98
100
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) " ) ) ;
99
101
}
@@ -426,8 +428,10 @@ protected class SQLiteCastFunction : CastFunction
426
428
{
427
429
protected override bool CastingIsRequired ( string sqlType )
428
430
{
429
- // SQLite doesn't support casting to datetime types. It assumes you want an integer and destroys the date string.
430
- if ( StringHelper . ContainsCaseInsensitive ( sqlType , "date" ) || StringHelper . ContainsCaseInsensitive ( sqlType , "time" ) )
431
+ // SQLite doesn't support casting to datetime or uniqueidentifier types. It assumes you want an integer and destroys the date or uniqueidentifier string.
432
+ if ( StringHelper . ContainsCaseInsensitive ( sqlType , "date" ) ||
433
+ StringHelper . ContainsCaseInsensitive ( sqlType , "time" ) ||
434
+ StringHelper . ContainsCaseInsensitive ( sqlType , "uniqueidentifier" ) )
431
435
return false ;
432
436
return true ;
433
437
}
0 commit comments