Skip to content

Commit 1b65a97

Browse files
committed
Fix SQLite tests
1 parent dddfb6d commit 1b65a97

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
@@ -47,8 +47,10 @@ protected virtual void RegisterColumnTypes()
4747
RegisterColumnType(DbType.UInt16, "INTEGER");
4848
RegisterColumnType(DbType.UInt32, "INTEGER");
4949
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");
5254
RegisterColumnType(DbType.Double, "DOUBLE");
5355
RegisterColumnType(DbType.Single, "DOUBLE");
5456
RegisterColumnType(DbType.VarNumeric, "NUMERIC");
@@ -100,7 +102,7 @@ protected virtual void RegisterFunctions()
100102
RegisterFunction("bxor", new SQLFunctionTemplate(null, "((?1 | ?2) - (?1 & ?2))"));
101103

102104
// NH-3787: SQLite requires the cast in SQL too for not defaulting to string.
103-
RegisterFunction("transparentcast", new CastFunction());
105+
RegisterFunction("transparentcast", new SQLiteCastFunction());
104106

105107
if (_binaryGuid)
106108
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
473475
{
474476
protected override bool CastingIsRequired(string sqlType)
475477
{
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"))
478482
return false;
479483
return true;
480484
}

0 commit comments

Comments
 (0)