dbTalk Databases Forums  

Re: [Info-Ingres] how to return a null value in OME?

comp.databases.ingres comp.databases.ingres


Discuss Re: [Info-Ingres] how to return a null value in OME? in the comp.databases.ingres forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rob Leather
 
Posts: n/a

Default Re: [Info-Ingres] how to return a null value in OME? - 03-11-2009 , 03:11 AM









This e-mail and any files transmitted with it are the property of the
London Borough of Havering, are confidential, may be subject to legal privilege
and are intended only for the person(s) or organisation(s) named above.
Any unauthorised use, retention, distribution, copying or disclosure
is strictly prohibited. If you receive this email in error, please notify
the sender immediately and delete this e-mail from your system.
WARNING: It is your responsibility to take all necessary steps to
ensure this e-mail and any attachments to it are free from viruses.

Reply With Quote
  #2  
Old   
Ian Kirkham
 
Posts: n/a

Default Re: [Info-Ingres] how to return a null value in OME? - 03-11-2009 , 04:06 AM






If you are worried about being passed a NULL parameter then don't as you
won't. The DBMS will short-circuit expressions in general that would
otherwise need to propagate NULLs.
Regards,
Ian
-----Original Message-----
From: info-ingres-bounces (AT) kettleriver...ting (DOT) com
[mailto:info-ingres-bounces (AT) kettleriverconsulting (DOT) com] On Behalf Of
zhenchen17
Sent: 11 March 2009 08:50
To: info-ingres (AT) kettleriverconsulting (DOT) com
Subject: [Info-Ingres] how to return a null value in OME?

Hi everyone,
I wonder how to return a null value in OME. The struture
II_DATA_VALUE used in OME is without a member variable to indicate it
is representing a null value. So how can i do if i want to return a
null in OME?
Thanks.
Chenzhen
_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://www.kettleriverconsulting.com...fo/info-ingres


Reply With Quote
  #3  
Old   
Ian Kirkham
 
Posts: n/a

Default Re: [Info-Ingres] how to return a null value in OME? - 03-12-2009 , 03:24 AM



That is correct but don’t forget to make the advertised length greater by one for the NULL byte.
Regards,
Ian

-----Original Message-----
From: info-ingres-bounces (AT) kettleriver...ting (DOT) com [mailto:info-ingres-bounces (AT) kettleriverconsulting (DOT) com] On Behalf Of zhenchen17
Sent: 12 March 2009 01:54
To: info-ingres (AT) kettleriverconsulting (DOT) com
Subject: Re: [Info-Ingres] how to return a null value in OME?

Hi Karl,
In my case, i don't want a null input but actually i want a null
output.
so what i do is:
1. define fi with a negative result value
2. mark the last byte of the return data to nonzero
Is that right?

Thanks
Chenzhen

On 3月11日, 下午8时31分, Karl & Betty Schendel <schen... (AT) kbcomputer (DOT) com>
wrote:
Quote:
A few misconceptions here.

First, a null is indicated by the last byte of a nullable value
being nonzero. Nullable types have negative type codes.
So, for example, a nullable i4 would have db_datatype of
-II_INTEGER (using OME style names), a db_length of 5 instead
of the non-nullable 4, and the 5th byte of the value would be
zero for a non-null value and nonzero for NULL.

Second, you can indeed pass nullable parameters to OME functions.
but you need to define the function instance with the
II_FID_F256_NONULLSKIP flag. If you don't use that flag, the
query compiler assumes that the function should be treated like
an operator instead of an ordinary function, and any null
input skips the function call entirely giving a null result.
The NONULLSKIP flag tells it to just pass the parameters,
whatever they are, and let the function worry about it.

Third, simply define the FI with a negative result type, meaning
nullable, and you can return nulls.

Karl

On Mar 11, 2009, at 6:20 AM, Martin Bowes wrote:



Hi Ian,

Yes OME (and all normal) functions won't take nulls as input
parameters,
but what about returning a null value?

Although, other that an aggregate function I couldn't honestly
think of
a reason to return a null.

I'm interested in what Chenzen is trying to achieve.

Marty

-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of
Ian
Kirkham
Sent: 11 March 2009 10:06
To: Ingres and related product discussion forum
Subject: Re: [Info-Ingres] how to return a null value in OME?

If you are worried about being passed a NULL parameter then don't
as you
won't. The DBMS will short-circuit expressions in general that would
otherwise need to propagate NULLs.
Regards,
Ian
-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of
zhenchen17
Sent: 11 March 2009 08:50
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: [Info-Ingres] how to return a null value in OME?

Hi everyone,
I wonder how to return a null value in OME. The struture
II_DATA_VALUE used in OME is without a member variable to indicate it
is representing a null value. So how can i do if i want to return a
null in OME?
Thanks.
Chenzhen
_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://www.kettleriverconsulting.com...fo/info-ingres



Reply With Quote
  #4  
Old   
zhenchen17
 
Posts: n/a

Default Re: how to return a null value in OME? - 03-12-2009 , 07:02 AM



Hi Ian,
What you said makes me confused.

If i want to return a nullabe integer(i4), what actual length would i
define in FI definiton? sizeof(i4) or sizeof(i4)+1?. Wouldn't DBMS
automatically add 1 byte more when calling the function if it
recognize the function could return a nullable value?

Thanks
Chenzhen

On 3鏈12鏃, 涓嬪崍5鏃24鍒, "Ian Kirkham" <Ian.Kirk... (AT) ingres (DOT) com> wrote:
Quote:
That is correct but don鈥檛 forget to make the advertised length greater by one for the NULL byte.
Regards,
Ian



-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com [mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of zhenchen17
Sent: 12 March 2009 01:54
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: Re: [Info-Ingres] how to return a null value in OME?

Hi Karl,
In my case, i don't want a null input but actually i want a null
output.
so what i do is:
1. define fi with a negative result value
2. mark the last byte of the return data to nonzero
Is that right?

Thanks
Chenzhen

On 3鏈11鏃, 涓嬪崍8鏃31鍒, Karl &Betty Schendel <schen... (AT) kbcomputer (DOT) com
wrote:
A few misconceptions here.

First, a null is indicated by the last byte of a nullable value
being nonzero. *Nullable types have negative type codes.
So, for example, a nullable i4 would have db_datatype of
-II_INTEGER (using OME style names), a db_length of 5 instead
of the non-nullable 4, and the 5th byte of the value would be
zero for a non-null value and nonzero for NULL.

Second, you can indeed pass nullable parameters to OME functions.
but you need to define the function instance with the
II_FID_F256_NONULLSKIP flag. *If you don't use that flag, the
query compiler assumes that the function should be treated like
an operator instead of an ordinary function, and any null
input skips the function call entirely giving a null result.
The NONULLSKIP flag tells it to just pass the parameters,
whatever they are, and let the function worry about it.

Third, simply define the FI with a negative result type, meaning
nullable, and you can return nulls.

Karl

On Mar 11, 2009, at 6:20 AM, Martin Bowes wrote:

Hi Ian,

Yes OME (and all normal) functions won't take nulls as input *
parameters,
but what about returning a null value?

Although, other that an aggregate function I couldn't honestly *
think of
a reason to return a null.

I'm interested in what Chenzen is trying to achieve.

Marty

-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of *
Ian
Kirkham
Sent: 11 March 2009 10:06
To: Ingres and related product discussion forum
Subject: Re: [Info-Ingres] how to return a null value in OME?

If you are worried about being passed a NULL parameter then don't *
as you
won't. The DBMS will short-circuit expressions in general that would
otherwise need to propagate NULLs.
Regards,
Ian
-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of
zhenchen17
Sent: 11 March 2009 08:50
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: [Info-Ingres] how to return a null value in OME?

Hi everyone,
*I wonder how to return a null value in OME. The struture
II_DATA_VALUE used in OME is without a member variable to indicate it
is representing a null value. So how can i do if i want to return a
null in OME?
*Thanks.
Chenzhen

_______________________________________________
Info-Ingres mailing list
Info-Ing... (AT) kettleriverconsulting (DOT) comhttp://www.kettleriverconsulting.com/mailman/listinfo/info-ingres


Reply With Quote
  #5  
Old   
Ian Kirkham
 
Posts: n/a

Default Re: [Info-Ingres] how to return a null value in OME? - 03-12-2009 , 07:22 AM



Hi Chenzhen,
You need to say sizeof(i4)+1. This is the convention adopted otherwise the DBMS would be forever checking the sign of the datatype to work out how many bytes needed moving. For a more complicated example returning a 3 byte result 'ABC' in a nullable varchar(10) would be like this:

/varlen\ / used \ / unused \ /NVL
+---+---+---+---+---+---+---+---+---+---+---+---+---+
Quote:
3 | A | B | C | ? | ? | ? | ? | ? | ? | ? | 0 |
+---+---+---+---+---+---+---+---+---+---+---+---+---+

In this case the data type would be -21 and the length would be 13 (2 byte varchar length, 10 bytes for the data plus 1 byte for null value)

Regards,
Ian

-----Original Message-----
From: info-ingres-bounces (AT) kettleriver...ting (DOT) com [mailto:info-ingres-bounces (AT) kettleriverconsulting (DOT) com] On Behalf Of zhenchen17
Sent: 12 March 2009 13:02
To: info-ingres (AT) kettleriverconsulting (DOT) com
Subject: Re: [Info-Ingres] how to return a null value in OME?

Hi Ian,
What you said makes me confused.

If i want to return a nullabe integer(i4), what actual length would i
define in FI definiton? sizeof(i4) or sizeof(i4)+1?. Wouldn't DBMS
automatically add 1 byte more when calling the function if it
recognize the function could return a nullable value?

Thanks
Chenzhen

On 3鏈12鏃, 涓嬪崍5鏃24鍒, "Ian Kirkham" <Ian.Kirk... (AT) ingres (DOT) com> wrote:
Quote:
That is correct but don鈥檛 forget to make the advertised length greater by one for the NULL byte.
Regards,
Ian



-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com [mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of zhenchen17
Sent: 12 March 2009 01:54
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: Re: [Info-Ingres] how to return a null value in OME?

Hi Karl,
In my case, i don't want a null input but actually i want a null
output.
so what i do is:
1. define fi with a negative result value
2. mark the last byte of the return data to nonzero
Is that right?

Thanks
Chenzhen

On 3鏈11鏃, 涓嬪崍8鏃31鍒, Karl & Betty Schendel <schen... (AT) kbcomputer (DOT) com
wrote:
A few misconceptions here.

First, a null is indicated by the last byte of a nullable value
being nonzero. *Nullable types have negative type codes.
So, for example, a nullable i4 would have db_datatype of
-II_INTEGER (using OME style names), a db_length of 5 instead
of the non-nullable 4, and the 5th byte of the value would be
zero for a non-null value and nonzero for NULL.

Second, you can indeed pass nullable parameters to OME functions.
but you need to define the function instance with the
II_FID_F256_NONULLSKIP flag. *If you don't use that flag, the
query compiler assumes that the function should be treated like
an operator instead of an ordinary function, and any null
input skips the function call entirely giving a null result.
The NONULLSKIP flag tells it to just pass the parameters,
whatever they are, and let the function worry about it.

Third, simply define the FI with a negative result type, meaning
nullable, and you can return nulls.

Karl

On Mar 11, 2009, at 6:20 AM, Martin Bowes wrote:

Hi Ian,

Yes OME (and all normal) functions won't take nulls as input *
parameters,
but what about returning a null value?

Although, other that an aggregate function I couldn't honestly *
think of
a reason to return a null.

I'm interested in what Chenzen is trying to achieve.

Marty

-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of *
Ian
Kirkham
Sent: 11 March 2009 10:06
To: Ingres and related product discussion forum
Subject: Re: [Info-Ingres] how to return a null value in OME?

If you are worried about being passed a NULL parameter then don't *
as you
won't. The DBMS will short-circuit expressions in general that would
otherwise need to propagate NULLs.
Regards,
Ian
-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of
zhenchen17
Sent: 11 March 2009 08:50
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: [Info-Ingres] how to return a null value in OME?

Hi everyone,
*I wonder how to return a null value in OME. The struture
II_DATA_VALUE used in OME is without a member variable to indicate it
is representing a null value. So how can i do if i want to return a
null in OME?
*Thanks.
Chenzhen

_______________________________________________
Info-Ingres mailing list
Info-Ing... (AT) kettleriverconsulting (DOT) comhttp://www.kettleriverconsulting.com/mailman/listinfo/info-ingres
_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://www.kettleriverconsulting.com...fo/info-ingres



Reply With Quote
  #6  
Old   
Karl & Betty Schendel
 
Posts: n/a

Default Re: [Info-Ingres] how to return a null value in OME? - 03-12-2009 , 07:29 AM




On Mar 12, 2009, at 9:02 AM, zhenchen17 wrote:

Quote:
Hi Ian,
What you said makes me confused.

If i want to return a nullabe integer(i4), what actual length would i
define in FI definiton? sizeof(i4) or sizeof(i4)+1?. Wouldn't DBMS
automatically add 1 byte more when calling the function if it
recognize the function could return a nullable value?


Nope. You have to use sizeof(i4)+1 in your FI definition.
The DBMS doesn't assume the extra byte for the null indicator.

Karl


Quote:
On 3鏈12鏃, 涓嬪崍5鏃24鍒, "Ian Kirkham"
Ian.Kirk... (AT) ingres (DOT) com> wrote:
That is correct but don鈥檛 forget to make the advertised length
greater by one for the NULL byte.
Regards,
Ian



-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com [mailto:info-
ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of zhenchen17
Sent: 12 March 2009 01:54
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: Re: [Info-Ingres] how to return a null value in OME?

Hi Karl,
In my case, i don't want a null input but actually i want a null
output.
so what i do is:
1. define fi with a negative result value
2. mark the last byte of the return data to nonzero
Is that right?

Thanks
Chenzhen

On 3鏈11鏃, 涓嬪崍8鏃31鍒, Karl & Betty Schendel
schen... (AT) kbcomputer (DOT) com
wrote:
A few misconceptions here.

First, a null is indicated by the last byte of a nullable value
being nonzero. Nullable types have negative type codes.
So, for example, a nullable i4 would have db_datatype of
-II_INTEGER (using OME style names), a db_length of 5 instead
of the non-nullable 4, and the 5th byte of the value would be
zero for a non-null value and nonzero for NULL.

Second, you can indeed pass nullable parameters to OME functions.
but you need to define the function instance with the
II_FID_F256_NONULLSKIP flag. If you don't use that flag, the
query compiler assumes that the function should be treated like
an operator instead of an ordinary function, and any null
input skips the function call entirely giving a null result.
The NONULLSKIP flag tells it to just pass the parameters,
whatever they are, and let the function worry about it.

Third, simply define the FI with a negative result type, meaning
nullable, and you can return nulls.

Karl

On Mar 11, 2009, at 6:20 AM, Martin Bowes wrote:

Hi Ian,

Yes OME (and all normal) functions won't take nulls as input
parameters,
but what about returning a null value?

Although, other that an aggregate function I couldn't honestly
think of
a reason to return a null.

I'm interested in what Chenzen is trying to achieve.

Marty

-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of
Ian
Kirkham
Sent: 11 March 2009 10:06
To: Ingres and related product discussion forum
Subject: Re: [Info-Ingres] how to return a null value in OME?

If you are worried about being passed a NULL parameter then don't
as you
won't. The DBMS will short-circuit expressions in general that
would
otherwise need to propagate NULLs.
Regards,
Ian
-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of
zhenchen17
Sent: 11 March 2009 08:50
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: [Info-Ingres] how to return a null value in OME?

Hi everyone,
I wonder how to return a null value in OME. The struture
II_DATA_VALUE used in OME is without a member variable to
indicate it
is representing a null value. So how can i do if i want to return a
null in OME?
Thanks.
Chenzhen

_______________________________________________
Info-Ingres mailing list
Info-Ing... (AT) kettleriverconsulting (DOT) comhttp://
http://www.kettleriverconsulting.com...fo/info-ingres

_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://www.kettleriverconsulting.com...fo/info-ingres



Reply With Quote
  #7  
Old   
zhenchen17
 
Posts: n/a

Default Re: how to return a null value in OME? - 03-12-2009 , 07:40 AM



Hi Ian
I c.
Thanks very much.
On 3鏈12鏃, 涓嬪崍9鏃22鍒, "Ian Kirkham" <Ian.Kirk... (AT) ingres (DOT) com> wrote:
Quote:
Hi Chenzhen,
You need to say sizeof(i4)+1. This is the convention adopted otherwise the DBMS would be forever checking the sign of the datatype to work out how many bytes needed moving. For a more complicated example returning a 3 byte result 'ABC' in a nullable varchar(10) would be like this:

/varlen\ / *used * \ / unused * * * * * * * * *\ /NVL
+---+---+---+---+---+---+---+---+---+---+---+---+---+
| * 3 * | A | B | C | ? | ? | ? | ? | ? | ? | ? | 0 |
+---+---+---+---+---+---+---+---+---+---+---+---+---+

In this case the data type would be -21 and the length would be 13 (2 byte varchar length, 10 bytes for the data plus 1 byte for null value)

Regards,
Ian



-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com [mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of zhenchen17
Sent: 12 March 2009 13:02
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: Re: [Info-Ingres] how to return a null value in OME?

Hi Ian,
What you said makes me confused.

If i want to return a nullabe integer(i4), what actual length would i
define in FI definiton? sizeof(i4) or sizeof(i4)+1?. *Wouldn't DBMS
automatically add 1 byte more when calling the function if it
recognize the function could return a nullable value?

Thanks
Chenzhen

On 3鏈12鏃, 涓嬪崍5鏃24鍒, "Ian Kirkham" <Ian.Kirk... (AT) ingres (DOT) com> wrote:
That is correct but don鈥檛 forget to make the advertised length greater by one for the NULL byte.
Regards,
Ian

-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com [mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of zhenchen17
Sent: 12 March 2009 01:54
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: Re: [Info-Ingres] how to return a null value in OME?

Hi Karl,
In my case, i don't want a null input but actually i want a null
output.
so what i do is:
1. define fi with a negative result value
2. mark the last byte of the return data to nonzero
Is that right?

Thanks
Chenzhen

On 3鏈11鏃, 涓嬪崍8鏃31鍒, Karl& Betty Schendel <schen... (AT) kbcomputer (DOT) com
wrote:
A few misconceptions here.

First, a null is indicated by the last byte of a nullable value
being nonzero. *Nullable types have negative type codes.
So, for example, a nullable i4 would have db_datatype of
-II_INTEGER (using OME style names), a db_length of 5 instead
of the non-nullable 4, and the 5th byte of the value would be
zero for a non-null value and nonzero for NULL.

Second, you can indeed pass nullable parameters to OME functions.
but you need to define the function instance with the
II_FID_F256_NONULLSKIP flag. *If you don't use that flag, the
query compiler assumes that the function should be treated like
an operator instead of an ordinary function, and any null
input skips the function call entirely giving a null result.
The NONULLSKIP flag tells it to just pass the parameters,
whatever they are, and let the function worry about it.

Third, simply define the FI with a negative result type, meaning
nullable, and you can return nulls.

Karl

On Mar 11, 2009, at 6:20 AM, Martin Bowes wrote:

Hi Ian,

Yes OME (and all normal) functions won't take nulls as input *
parameters,
but what about returning a null value?

Although, other that an aggregate function I couldn't honestly *
think of
a reason to return a null.

I'm interested in what Chenzen is trying to achieve.

Marty

-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of*
Ian
Kirkham
Sent: 11 March 2009 10:06
To: Ingres and related product discussion forum
Subject: Re: [Info-Ingres] how to return a null value in OME?

If you are worried about being passed a NULL parameter then don't *
as you
won't. The DBMS will short-circuit expressions in general that would
otherwise need to propagate NULLs.
Regards,
Ian
-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of
zhenchen17
Sent: 11 March 2009 08:50
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: [Info-Ingres] how to return a null value in OME?

Hi everyone,
*I wonder how to return a null value in OME. The struture
II_DATA_VALUE used in OME is without a member variable to indicate it
is representing a null value. So how can i do if i want to return a
null in OME?
*Thanks.
Chenzhen

_______________________________________________
Info-Ingres mailing list
Info-Ing... (AT) kettleriverconsulting (DOT) comhttp://www.kettleriverconsulting.com/mailman/listinfo/info-ingres

_______________________________________________
Info-Ingres mailing list
Info-Ing... (AT) kettleriverconsulting (DOT) comhttp://www.kettleriverconsulting.com/mailman/listinfo/info-ingres


Reply With Quote
  #8  
Old   
zhenchen17
 
Posts: n/a

Default Re: how to return a null value in OME? The length need not extrabyte? - 03-18-2009 , 07:12 AM



Hi Karl and Ian,
What you said seems have some problems. I tried to return a null
float, so i define fi with -II_FLOAT and the length sizeof(f8)+1. But
when the function is called, DBMS will a return a error code:
"E_AD2005 ADF routine found DB_DATA_VALUE with an invalid length."
But if i define the length only sizeof(f8) , it works fine and return
NULL as i want.

I have no idea what happened, could u take a look and give any reason?
Thanks
Chenzhen

On 3鏈12鏃, 涓嬪崍9鏃29鍒, Karl & Betty Schendel <schen... (AT) kbcomputer (DOT) com>
wrote:
Quote:
On Mar 12, 2009, at 9:02 AM, zhenchen17 wrote:

Hi Ian,
What you said makes me confused.

If i want to return a nullabe integer(i4), what actual length would i
define in FI definiton? sizeof(i4) or sizeof(i4)+1?. *Wouldn't DBMS
automatically add 1 byte more when calling the function if it
recognize the function could return a nullable value?

Nope. *You have to use sizeof(i4)+1 in your FI definition.
The DBMS doesn't assume the extra byte for the null indicator.

Karl



On 3鏈12鏃, 涓嬪崍5鏃24鍒, "IanKirkham" *
Ian.Kirk... (AT) ingres (DOT) com> wrote:
That is correct but don鈥檛 forget to make the advertised length*
greater by one for the NULL byte.
Regards,
Ian

-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com [mailto:info-
ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of zhenchen17
Sent: 12 March 2009 01:54
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: Re: [Info-Ingres] how to return a null value in OME?

Hi Karl,
In my case, i don't want a null input but actually i want a null
output.
so what i do is:
1. define fi with a negative result value
2. mark the last byte of the return data to nonzero
Is that right?

Thanks
Chenzhen

On 3鏈11鏃, 涓嬪崍8鏃31鍒, Karl & Betty Schendel *
schen... (AT) kbcomputer (DOT) com
wrote:
A few misconceptions here.

First, a null is indicated by the last byte of a nullable value
being nonzero. *Nullable types have negative type codes.
So, for example, a nullable i4 would have db_datatype of
-II_INTEGER (using OME style names), a db_length of 5 instead
of the non-nullable 4, and the 5th byte of the value would be
zero for a non-null value and nonzero for NULL.

Second, you can indeed pass nullable parameters to OME functions.
but you need to define the function instance with the
II_FID_F256_NONULLSKIP flag. *If you don't use that flag, the
query compiler assumes that the function should be treated like
an operator instead of an ordinary function, and any null
input skips the function call entirely giving a null result.
The NONULLSKIP flag tells it to just pass the parameters,
whatever they are, and let the function worry about it.

Third, simply define the FI with a negative result type, meaning
nullable, and you can return nulls.

Karl

On Mar 11, 2009, at 6:20 AM, Martin Bowes wrote:

Hi Ian,

Yes OME (and all normal) functions won't take nulls as input
parameters,
but what about returning a null value?

Although, other that an aggregate function I couldn't honestly
think of
a reason to return a null.

I'm interested in what Chenzen is trying to achieve.

Marty

-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of
Ian
Kirkham
Sent: 11 March 2009 10:06
To: Ingres and related product discussion forum
Subject: Re: [Info-Ingres] how to return a null value in OME?

If you are worried about being passed a NULL parameter then don't
as you
won't. The DBMS will short-circuit expressions in general that *
would
otherwise need to propagate NULLs.
Regards,
Ian
-----Original Message-----
From: info-ingres-boun... (AT) kettleriverconsulting (DOT) com
[mailto:info-ingres-boun... (AT) kettleriverconsulting (DOT) com] On Behalf Of
zhenchen17
Sent: 11 March 2009 08:50
To: info-ing... (AT) kettleriverconsulting (DOT) com
Subject: [Info-Ingres] how to return a null value in OME?

Hi everyone,
*I wonder how to return a null value in OME. The struture
II_DATA_VALUE used in OME is without a member variable to *
indicate it
is representing a null value. So how can i do if i want to return a
null in OME?
*Thanks.
Chenzhen

_______________________________________________
Info-Ingres mailing list
Info-Ing... (AT) kettleriverconsulting (DOT) comhttp://
http://www.kettleriverconsulting.com...fo/info-ingres

_______________________________________________
Info-Ingres mailing list
Info-Ing... (AT) kettleriverconsulting (DOT) com
http://www.kettleriverconsulting.com...fo/info-ingres


Reply With Quote
  #9  
Old   
Karl & Betty Schendel
 
Posts: n/a

Default Re: [Info-Ingres] how to return a null value in OME? The lengthneed not extra byte? - 03-18-2009 , 08:03 AM




On Mar 18, 2009, at 9:12 AM, zhenchen17 wrote:

Quote:
Hi Karl and Ian,
What you said seems have some problems. I tried to return a null
float, so i define fi with -II_FLOAT and the length sizeof(f8)+1. But
when the function is called, DBMS will a return a error code:
"E_AD2005 ADF routine found DB_DATA_VALUE with an invalid length."
But if i define the length only sizeof(f8) , it works fine and return
NULL as i want.
Did you set the NONULLSKIP flag? I had forgotten this, but you need
to pass NONULLSKIP if the function can return null, whether it can
accept nullable parameters or not. I forget why I did it that way.

Without the NONULLSKIP flag, ad0_fiinit (in adgstartup.c) forces the
result type of the user defined FI's to positive, which would explain
why
you get the AD2005.

If you did set NONULLSKIP, then I'm not sure what is going on, and would
need more details.

Karl



Quote:
Second, you can indeed pass nullable parameters to OME functions.
but you need to define the function instance with the
II_FID_F256_NONULLSKIP flag. If you don't use that flag, the
query compiler assumes that the function should be treated like
an operator instead of an ordinary function, and any null
input skips the function call entirely giving a null result.
The NONULLSKIP flag tells it to just pass the parameters,
whatever they are, and let the function worry about it.


Reply With Quote
  #10  
Old   
zhenchen17
 
Posts: n/a

Default Re: how to return a null value in OME? The length need not extrabyte? - 03-19-2009 , 01:46 AM



Hi Karl,
Of cuz i set the NONULLSKIP. But it still failed.

I doubt the error comes from the len_check function(adclenchk.c)

case DB_FLT_TYPE:
/* Float datatype, which can either be 4 or 8 bytes long */

/* set default length to 4, in case check fails */
if (adc_rdv != NULL)
{
adc_rdv->db_datatype = DB_FLT_TYPE;
adc_rdv->db_length = 4;
adc_rdv->db_prec = 0;
}

if (adc_dv->db_length != 4 && adc_dv->db_length != 8)
{
/* Precision check is done in adi_encode_... for its callers
** (e.g. PSF), or here for others (such as ABF). */
if (adc_is_usr && adc_rdv != NULL)
{
if (adc_dv->db_length > DB_MAX_F8PREC ||
adc_dv->db_length < 0)
db_stat = adu_error(adf_scb, E_AD2006_BAD_DTUSRLEN, 0);
else
{
/* Do the length to F4 and F8 mapping */
if(adc_dv->db_length <= DB_MAX_F4PREC)
adc_rdv->db_length = 4;
else
adc_rdv->db_length = 8;
}
}
else
{
db_stat = adu_error(adf_scb, E_AD2005_BAD_DTLEN, 0);
}
}
else
{
if (adc_rdv != NULL)
adc_rdv->db_length = adc_dv->db_length;
}
break;

From the code above, it seems the length of float should be 4 or 8.
If I set the length 8+1, the statement:
db_stat = adu_error(adf_scb, E_AD2005_BAD_DTLEN, 0)
is executed and error returned.

Any idea?
Thanks.

Chenzhen

On 3月18日, 下午10时03分, Karl & Betty Schendel <schen... (AT) kbcomputer (DOT) com>
wrote:
Quote:
On Mar 18, 2009, at 9:12 AM, zhenchen17 wrote:

Hi Karl and Ian,
What you said seems have some problems. I tried to return a null
float, so i define fi with -II_FLOAT and the length sizeof(f8)+1. But
when the function is called, DBMS will a return a error code:
"E_AD2005 ADF routine found DB_DATA_VALUE with an invalid length."
But if i define the length only sizeof(f8) , it works fine and return
NULL as i want.

Did you set the NONULLSKIP flag? I had forgotten this, but you need
to pass NONULLSKIP if the function can return null, whether it can
accept nullable parameters or not. I forget why I did it that way.

Without the NONULLSKIP flag, ad0_fiinit (in adgstartup.c) forces the
result type of the user defined FI's to positive, which would explain
why
you get the AD2005.

If you did set NONULLSKIP, then I'm not sure what is going on, and would
need more details.

Karl



Second, you can indeed pass nullable parameters to OME functions.
but you need to define the function instance with the
II_FID_F256_NONULLSKIP flag. If you don't use that flag, the
query compiler assumes that the function should be treated like
an operator instead of an ordinary function, and any null
input skips the function call entirely giving a null result.
The NONULLSKIP flag tells it to just pass the parameters,
whatever they are, and let the function worry about it.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.