roxen.lists.roxen.general

Subject Author Date
Re: [PATCH 02/17] Simplify logic, drop redundant code Henrik_Grubbström <grubba[at]roxen[dot]com> 20-01-2009
On Tue, 20 Jan 2009, Stephen R. van den Berg wrote:

> Henrik Grubbstr?m wrote:
>> On Tue, 20 Jan 2009, Stephen R. van den Berg wrote:
>>> -		       if (x) return x;
>>> -		       if ((x != 0) && stringp(x->type))
>>> -			 return x->type;
>>> -		       return RXML.nil;
>
>> This patch is unsafe, since it changes the handling of "" for results from
>> Oracle (Oracle doesn't differentiate between "" and NULL for string fields).
>
> The first if (x) return x; always catches if (x != 0), or am I missing
> something subtle here?

The subtlety here is that the StringNULL class has an lfun::`!() that 
returns true, ie it won't be returned by the first if statement. The 
second if statement tests if x is equal to zero by calling lfun::`==(), 
which isn't implemented by StringNULL , and thus will fall back to the 
low-level implementation of predef::`==(), which will see that the two 
svalues have different types and thus aren't equal.

> I.e. it only gets to the Oracle "if" when x == 0.
> If my simplification is unsafe for Oracle, then maybe the existing logic
> needs to be fixed?

The existing code works as intended, but might be a bit obscure (thus the 
comments).

> -- 
> Sincerely,
>           Stephen R. van den Berg.

--
Henrik Grubbström					<grubba[at]roxen.com>
Roxen Internet Software AB