![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
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 |
#5
| |||
| |||
|
|
3 | A | B | C | ? | ? | ? | ? | ? | ? | ? | 0 | +---+---+---+---+---+---+---+---+---+---+---+---+---+ |
|
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 |
#6
| |||
| |||
|
|
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? |
|
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 |
#7
| |||
| |||
|
|
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 |
#8
| |||
| |||
|
|
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 |
#9
| |||
| |||
|
|
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. |
|
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. |
#10
| |||
| |||
|
|
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. |
![]() |
| Thread Tools | |
| Display Modes | |
| |