Skip to content

Commit e5b2cf8

Browse files
fixup! Support evaluation of Random.Next and NextDouble on db side
Fix random Oracle overflows.
1 parent a911809 commit e5b2cf8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/NHibernate/Dialect/Oracle10gDialect.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,23 @@ protected override void RegisterFunctions()
2323

2424
// DBMS_RANDOM package was available in previous versions, but it was requiring initialization and
2525
// was not having the value function.
26-
RegisterFunction("random", new NoArgSQLFunction("DBMS_RANDOM.VALUE", NHibernateUtil.Double));
26+
// It yields a decimal between 0 included and 1 excluded, with 38 significant digits. It sometimes
27+
// causes an overflow when read by the Oracle provider as a .Net Decimal, so better explicitly cast
28+
// it to double.
29+
RegisterFunction("random", new SQLFunctionTemplate(NHibernateUtil.Double, "cast(DBMS_RANDOM.VALUE() as binary_double)"));
2730
}
31+
32+
/* 6.0 TODO: consider redefining float and double registrations
33+
protected override void RegisterNumericTypeMappings()
34+
{
35+
base.RegisterNumericTypeMappings();
36+
37+
// Use binary_float (available since 10g) instead of float. With Oracle, float is a decimal but
38+
// with a precision expressed in number of bytes instead of digits.
39+
RegisterColumnType(DbType.Single, "binary_float");
40+
// Using binary_double (available since 10g) instead of double precision. With Oracle, double
41+
// precision is a float(126), which is a decimal with a 126 bytes precision.
42+
RegisterColumnType(DbType.Double, "binary_double");
43+
}*/
2844
}
2945
}

0 commit comments

Comments
 (0)