Re: 4gl question
Posted in 2008
Topics: SQL Development & Query Writing, Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL
Denham, Mark wrote:
>
>> -----Original Message-----
>> From: informix-list-bounces@iiug.org
>> [mailto:informix-list-bounces@iiug.org]On Behalf Of Art S.
>> Kagel (Oninit
>> LLC)
>> Sent: Monday, February 04, 2008 8:04 AM
>> Cc: informix-list@iiug.org
>> Subject: Re: 4gl question
>>
>>
>> Jonathan Leffler wrote:
>>
>>> Denham, Mark wrote:
>>>
>>>
>>>
>>>
>>>> Doing the same in a stored procedure:
>>>>
>>>> create procedure my_proc()
>>>> returning char(2);>>>>
>>>> define ws_sec_type char(2);
>>>>
>>>> let ws_sec_type = 'OA';
>>>>
>>>> select desc
>>>> into ws_sec_type
>>>> from code_desc
>>>> where code = "999"
>>>> and type = 'SECTYP';>>>>
>>>> return ws_sec_type;
>>>>
>>>> end procedure;
>>>>
>>>> execute procedure my_proc();>>>>
>>>> returns nothing. Shouldn't both have the same outcome?
>>>>
>>>> Mark
>>>>
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: malcolm.iiug [mailto:maliiug@btopenworld.com]
>>>>> Sent: Friday, February 01, 2008 12:57 PM
>>>>> To: Denham, Mark
>>>>>
>>>>> A Null value could lead you to infer there was one row in the
>>>>> table, which
>>>>> is not the case, SQL and 4GL have got it right, as usual.
>>>>>
>>>>>
>>>>> Malcolm
>>>>> -----Original Message-----
>>>>> From: [...] On Behalf Of Denham, Mark
>>>>> Sent: 01 February 2008 17:54
>>>>>
>>>>> IBM INFORMIX-4GL Version 7.32.FC2X5
>>>>> Pcode Version 732
>>>>>
>>>>> This test sample prints "OA" when executed which surprised
>>>>> me. The code_desc
>>>>> table is empty. I would have expected a null value.
>>>>>
>>>>> main
>>>>>
>>>>> define ws_input char(2),
>>>>> ws_sec_type char(2)
>>>>>
>>>>> let ws_sec_type = 'OA'
>>>>>
>>>>> select desc
>>>>> into ws_sec_type
>>>>> from code_desc
>>>>> where code = 1
>>>>> and type = 'SECTYP'>>>>>
>>>>> display ws_sec_type
>>>>>
>>>>> end main
>>>>>
>>>>> Or am I losing it?
>>>>>
>>>>>
>>> I think that in both cases, you are treading into murky
>>>
>> water. Yes, I
>>
>>> would prefer them to behave the same, and I think the I4GL
>>>
>> behaviour is
>>
>>> reasonable -- better, if you prefer -- but can anyone point
>>>
>> me to the
>>
>>> documented behaviour where is says what happens if a
>>>
>> singleton SELECT
>>
>>> such as the one shown fails to return any data (do the host
>>>
>> variables
>>
>>> designated to receive the values get overwritten or not)?
>>>
>> The opposite
>>
>>> problem could also be faced - if the SELECT statement is
>>>
>> not a singleton
>>
>>> after all, are the values of the host variables clobbered or not?
>>>
>>> It is probably best to consider the result undefined - until you've
>>> checked that you actually got a row returned, you don't
>>>
>> know what the
>>
>>> value in the host vars will be.
>>>
>> IB the underlying ESQL/C states that the contents of host
>> variables is
>> 'undefined' if a select returns no rows. That would apply equally to
>> compiled 4GL. Behavior for the RDS version and for any 3rd party
>> versions may be different.
>>
>>
> I've tested RDS and stored procedures. RDS behaves in accordance with the rules for esql/c. Stored procedures do not. I don't have a 4gl compiler available so I cannot confirm what actually happens.
>
> I can think of some situations where this is going to cause problems that have been overlooked in our code because I know i've seen code that translates roughly as shown below. Clearly this code is going to produce the wrong results because the status of the singleton select is not being checked.
>
> globals
> define var char(1)
> define myrec record like mytable.*
> end golbals
>
> function initialize()
> let var = null
> end function
>
> function one()
>
> foreach select * into myrec.* from mytable
> call two()
> end foreach
>
> end function
>
> function two()
>
> select anothersomething
> into var
> from bla blah
> where myrec.var2 = "fred">
> if var = "y" then
> ...
> else
> ..
> end if
> end function
>
Yes, function two is definitely problematic code at best and poor code
when I'm not feeling charitable.
Compiled 4GL definitely behaves that way, the host variable's contents
are undefined, usually unmodified but even that's not guaranteed. And
when you through 3rd party 4GL's into the mix, all bets are off.
Example: Aubit4GL will initialize the host variable in many
circumstances where 4GL will not (compared to earlier 4GL releases, even
some circumstances where the manual says C4GL will initialize) as I
found out porting an app to Aubit4GL a few years ago.
Art S. Kagel
Oninit
===========================================================================================
Please access the attached hyperlink for an important electronic communications disclaimer:
http://www.oninit.com/home/disclaimer.php
===========================================================================================