Alexey Gaidukov wrote : 
>
>Thanks.
>
>If there is no exception with $rc=100 why in the following example in 
>case of ROW NOT FOUND MaxDB will returns DBPROC by STOP(100)?
>create dbproc test(
>    OUT t varchar(10))
>AS
>begin
>    try
>        select field into :t from user.table where field2='123';
>    catch
>       if $rc=100 then
>           set t = 'not found'
>       else
>            stop($rc, $errmsg);
>end;
>
>
> From MaxDB 7.6 manual
>
>If an SQL error occurs in the statement list between TRY and 
>CATCH, the 
>system branches directly to the statement that follows CATCH.
>
>So 100 is a SQL error.
>
>In case of UDF $rc=100 is correct for context of UDF. This 
>means ROW NOT 
>FOUND in UDF. As for me when I get ROW NOT FOUND in select I 
>think that 
>select returns no data. I need some time to undestand that this error 
>code is from UDF.
>
>
>Thanks in advance,
>Alexey Gaidukov.
>
>
>Anhaus, Thomas пишет:
>
>>Alexey Gaidukov wrote :
>>
>>  
>>
>>>create function GIS.ret_test
>>>  returns varchar AS
>>>VAR
>>>  f varchar(10);
>>>begin
>>>      select resid into :f from gis.test2;
>>>      return f;
>>>end;
>>>//
>>>select resid,GIS.ret_test() from temp.test
>>>
>>>Returns two records. Where is in this case the exception 
>with $rc=100? 
>>>Very strange behavior.
>>>
>>>    
>>>
>>
>>Why do you think this behavior is strange ? Please note that 
>there's no
>>exception for error 100, there's just the variable $rc which contains
>>the value 100 after the select statement.
>>Since you didn't check this variable the function returns the initial
>>value of f, which is null. 
>>Even if you use try/catch you are responsible to check $rc in 
>the catch
>>block and you must decide whether this is an error to be ignored or to
>>be returned to the caller.
>>In the latter case you have to leave the function via a STOP 
>statement.
>>To avoid misunderstanding you should choose error codes that do not
>>conflict with existing MaxDB error codes.
>>
>>Best Regards,
>>Thomas
>>
>>  
>>
The MaxDB try/catch mechanism is no real exception handling. It just helps to 
write code without checking $rc after each sql statement. Internally the 
compiler generates these checks for you and skips to the catch block whenever 
$RC is not 0. 
But this happens in the scope of a try/catch block only. Since your function 
does not contain a try/catch block, no checks for $rc are done.
If $RC = 100 is ok in your function you should ignore it and leave the function 
without calling a STOP statement. If $RC = 100 is not ok in your function, you 
should leave the function with a stop statement, but not with STOP($RC). 
Instead you could for example leave by

STOP (-31000, 'unexpected error : ' || CHR($RC));

Best Regards,
Thomas

--
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to