Hi Thomas,
I noticed in the latest build the following behavior for user-defined
Java functions with primitive arguments. If at least one of the actual
arguments is NULL the Java function is not called at all and NULL
silently returned as a result. The end user has no control over this
behavior and the such result can be unexpected. I propose to throw an
exception in this case to alert user about the potential problem. Even
better approach would be to be able to customize the behavior.
Proposal. In CREATE ALIAS statement specify what to do for primitive
types if the actual argument value is NULL. There are three choices:
1. THROW -- throw an exception (default)
2. NULL – do not call Java function and just return NULL
3. NAN – for double and real replace NULL with Double.NaN/Float.NaN
and call the function, in all other cases throw an exception.
I am ready to implement the feature and submit a patch.
In my case all I need is an option 3 so simple and less flexible
approach would be to use a new system property. In the latter case
the change is really small. Line 350 in FunctionAlias should be
replace like this:
if (SysProperties.REPLACE_NULL_WITH_NAN) {
if (paramClass.equals(Double.TYPE)) {
o = Double.NaN;
} else if
(paramClass.equals(Float.TYPE)) {
o = Float.NaN;
} else
throw
DbException.get(ErrorCode.NULL_FOR_JAVA_PRIMITIVE, method.toString(),
String.valueOf(a));
} else {
// NULL for a java primitive: return
NULL
return ValueNull.INSTANCE;
}
Sincerely,
Pavel
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.