You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by John English <je...@brighton.ac.uk> on 2006/02/28 23:16:00 UTC

Create function problem

I have a function to round a Double to a specified number of decimal places:

   public static final Double derbyDouble (Double value, Integer places) {
     ...
   }

I've declared it to Derby like so:

   CREATE FUNCTION DoubleFormat (value  FLOAT,
                                 places INTEGER)
   RETURNS FLOAT
   PARAMETER STYLE Java
   LANGUAGE Java
   EXTERNAL NAME 'utils.Utils.derbyDouble';

This works if I use "double" and "int" but not Double and Integer (as in,
the methos is found & used corrrectly if I use primitive types but it isn't
found if I use the corresponding wrapper types). I've also tried Float, which
is no better.

The big difference is that, using primitive types, I can't handle nulls...

Anyone got any ideas whhat I'm doing wrong?

----------------------------------------------------------------------
  John English              | mailto:je@brighton.ac.uk
  Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
  School of Computing & MIS | "Those who don't know their history
  University of Brighton    |  are condemned to relive it" (Santayana)
----------------------------------------------------------------------

Re: Create function problem

Posted by John English <je...@brighton.ac.uk>.
Daniel John Debrunner wrote:

> There are two options for a function:
> 
> 1) Declare the function RETURNS NULL ON NULL INPUT, this means that if
> any parameter is NULL the result is NULL and the Java method is never
> called. There are a couple of bugs outstanding on this which will be
> fixed in 10.2.
> http://issues.apache.org/jira/browse/DERBY-479
> http://issues.apache.org/jira/browse/DERBY-1030

This works fine for me. Thanks!

----------------------------------------------------------------------
  John English              | mailto:je@brighton.ac.uk
  Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
  School of Computing & MIS | "Those who don't know their history
  University of Brighton    |  are condemned to relive it" (Santayana)
----------------------------------------------------------------------

Re: Create function problem

Posted by "Jean T. Anderson" <jt...@bristowhill.com>.
Jean T. Anderson wrote:
> Daniel John Debrunner wrote:
> 
>>Jean T. Anderson wrote:
>>
>>>...
>>>Derby maps a SQL INTEGER to Java int (a primitive) and passing SQL NULLs
>>>isn't supported for primitive types. There's an FAQ on this at
>>>http://db.apache.org/derby/faq.html#null_args that also points to the
>>>mail list topic that fed the FAQ.
>>
>>That FAQ is a bit out of date (I think, I can't see it now, get timeouts
>>connecting to the site).
>>
>>There are two options for a function:
>>
>>1) Declare the function RETURNS NULL ON NULL INPUT, 
>> ...
>>2) In the external name clause define the Java method signature, e.g.
...
> 
> thanks! I'll update the FAQ.

I updated http://db.apache.org/derby/faq.html#null_args -- you may need
to refresh the page in your browser to see the updated page. Please let
me know if this needs any changes.

thanks,

 -jean


Re: Create function problem

Posted by "Jean T. Anderson" <jt...@bristowhill.com>.
Daniel John Debrunner wrote:
> Jean T. Anderson wrote:
>> ...
>>Derby maps a SQL INTEGER to Java int (a primitive) and passing SQL NULLs
>>isn't supported for primitive types. There's an FAQ on this at
>>http://db.apache.org/derby/faq.html#null_args that also points to the
>>mail list topic that fed the FAQ.
> 
> 
> That FAQ is a bit out of date (I think, I can't see it now, get timeouts
> connecting to the site).
> 
> There are two options for a function:
> 
> 1) Declare the function RETURNS NULL ON NULL INPUT, this means that if
> any parameter is NULL the result is NULL and the Java method is never
> called. There are a couple of bugs outstanding on this which will be
> fixed in 10.2.
> http://issues.apache.org/jira/browse/DERBY-479
> http://issues.apache.org/jira/browse/DERBY-1030
> 
> CREATE FUNCTION DoubleFormat (value  FLOAT,
>                                places INTEGER)
> RETURNS FLOAT
> PARAMETER STYLE Java
> LANGUAGE Java
> RETURNS NULL ON NULL INPUT
> EXTERNAL NAME 'utils.Utils.derbyDouble'
> 
> 2) In the external name clause define the Java method signature, e.g.
> 
> CREATE FUNCTION DoubleFormat (value  FLOAT,
>                                places INTEGER)
> RETURNS FLOAT
> PARAMETER STYLE Java
> LANGUAGE Java
> EXTERNAL NAME
> 'utils.Utils.derbyDouble(java.lang.Float,java.lang.Integer)'
> 
> This will then resolve to the method with that signature (assuming it
> exists).
> 
> Method signature support was added in 10.1.

thanks! I'll update the FAQ.

-jean

Re: Create function problem

Posted by Daniel John Debrunner <dj...@apache.org>.
Jean T. Anderson wrote:

> John English wrote:
> 
>>I have a function to round a Double to a specified number of decimal
>>places:
>>
>>  public static final Double derbyDouble (Double value, Integer places) {
>>    ...
>>  }
>>
>>I've declared it to Derby like so:
>>
>>  CREATE FUNCTION DoubleFormat (value  FLOAT,
>>                                places INTEGER)
>>  RETURNS FLOAT
>>  PARAMETER STYLE Java
>>  LANGUAGE Java
>>  EXTERNAL NAME 'utils.Utils.derbyDouble';
>>
>>This works if I use "double" and "int" but not Double and Integer (as in,
>>the methos is found & used corrrectly if I use primitive types but it isn't
>>found if I use the corresponding wrapper types). I've also tried Float,
>>which
>>is no better.
>>
>>The big difference is that, using primitive types, I can't handle nulls...
>>
>>Anyone got any ideas whhat I'm doing wrong?
> 
> 
> Derby maps a SQL INTEGER to Java int (a primitive) and passing SQL NULLs
> isn't supported for primitive types. There's an FAQ on this at
> http://db.apache.org/derby/faq.html#null_args that also points to the
> mail list topic that fed the FAQ.

That FAQ is a bit out of date (I think, I can't see it now, get timeouts
connecting to the site).

There are two options for a function:

1) Declare the function RETURNS NULL ON NULL INPUT, this means that if
any parameter is NULL the result is NULL and the Java method is never
called. There are a couple of bugs outstanding on this which will be
fixed in 10.2.
http://issues.apache.org/jira/browse/DERBY-479
http://issues.apache.org/jira/browse/DERBY-1030

CREATE FUNCTION DoubleFormat (value  FLOAT,
                               places INTEGER)
RETURNS FLOAT
PARAMETER STYLE Java
LANGUAGE Java
RETURNS NULL ON NULL INPUT
EXTERNAL NAME 'utils.Utils.derbyDouble'

2) In the external name clause define the Java method signature, e.g.

CREATE FUNCTION DoubleFormat (value  FLOAT,
                               places INTEGER)
RETURNS FLOAT
PARAMETER STYLE Java
LANGUAGE Java
EXTERNAL NAME
'utils.Utils.derbyDouble(java.lang.Float,java.lang.Integer)'

This will then resolve to the method with that signature (assuming it
exists).

Method signature support was added in 10.1.

Dan.



Re: Create function problem

Posted by "Jean T. Anderson" <jt...@bristowhill.com>.
John English wrote:
> I have a function to round a Double to a specified number of decimal
> places:
> 
>   public static final Double derbyDouble (Double value, Integer places) {
>     ...
>   }
> 
> I've declared it to Derby like so:
> 
>   CREATE FUNCTION DoubleFormat (value  FLOAT,
>                                 places INTEGER)
>   RETURNS FLOAT
>   PARAMETER STYLE Java
>   LANGUAGE Java
>   EXTERNAL NAME 'utils.Utils.derbyDouble';
> 
> This works if I use "double" and "int" but not Double and Integer (as in,
> the methos is found & used corrrectly if I use primitive types but it isn't
> found if I use the corresponding wrapper types). I've also tried Float,
> which
> is no better.
> 
> The big difference is that, using primitive types, I can't handle nulls...
> 
> Anyone got any ideas whhat I'm doing wrong?

Derby maps a SQL INTEGER to Java int (a primitive) and passing SQL NULLs
isn't supported for primitive types. There's an FAQ on this at
http://db.apache.org/derby/faq.html#null_args that also points to the
mail list topic that fed the FAQ.

I hope this helps,

-jean