Skip to content

Commit

Permalink
fixup! Support evaluation of Random.Next and NextDouble on db side
Browse files Browse the repository at this point in the history
Fix random Oracle overflows.
  • Loading branch information
fredericDelaporte committed Oct 7, 2018
1 parent a911809 commit e5b2cf8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/NHibernate/Dialect/Oracle10gDialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,23 @@ protected override void RegisterFunctions()

// DBMS_RANDOM package was available in previous versions, but it was requiring initialization and
// was not having the value function.
RegisterFunction("random", new NoArgSQLFunction("DBMS_RANDOM.VALUE", NHibernateUtil.Double));
// It yields a decimal between 0 included and 1 excluded, with 38 significant digits. It sometimes
// causes an overflow when read by the Oracle provider as a .Net Decimal, so better explicitly cast
// it to double.
RegisterFunction("random", new SQLFunctionTemplate(NHibernateUtil.Double, "cast(DBMS_RANDOM.VALUE() as binary_double)"));
}

/* 6.0 TODO: consider redefining float and double registrations
protected override void RegisterNumericTypeMappings()
{
base.RegisterNumericTypeMappings();
// Use binary_float (available since 10g) instead of float. With Oracle, float is a decimal but
// with a precision expressed in number of bytes instead of digits.
RegisterColumnType(DbType.Single, "binary_float");
// Using binary_double (available since 10g) instead of double precision. With Oracle, double
// precision is a float(126), which is a decimal with a 126 bytes precision.
RegisterColumnType(DbType.Double, "binary_double");
}*/
}
}

0 comments on commit e5b2cf8

Please sign in to comment.