Skip to content

Commit c88b369

Browse files
committed
Fix SQLite tests
1 parent 6278b8c commit c88b369

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/NHibernate/Dialect/SQLiteDialect.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ protected virtual void RegisterColumnTypes()
4040
RegisterColumnType(DbType.UInt16, "INTEGER");
4141
RegisterColumnType(DbType.UInt32, "INTEGER");
4242
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");
4547
RegisterColumnType(DbType.Double, "DOUBLE");
4648
RegisterColumnType(DbType.Single, "DOUBLE");
4749
RegisterColumnType(DbType.VarNumeric, "NUMERIC");
@@ -93,7 +95,7 @@ protected virtual void RegisterFunctions()
9395
RegisterFunction("bxor", new SQLFunctionTemplate(null, "((?1 | ?2) - (?1 & ?2))"));
9496

9597
// NH-3787: SQLite requires the cast in SQL too for not defaulting to string.
96-
RegisterFunction("transparentcast", new CastFunction());
98+
RegisterFunction("transparentcast", new SQLiteCastFunction());
9799

98100
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) "));
99101
}
@@ -426,8 +428,10 @@ protected class SQLiteCastFunction : CastFunction
426428
{
427429
protected override bool CastingIsRequired(string sqlType)
428430
{
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"))
431435
return false;
432436
return true;
433437
}

0 commit comments

Comments
 (0)