[ic] Matrix options and set_row possible bug?

Jon Jensen jon at endpoint.com
Thu Jun 22 21:57:44 EDT 2006


On Thu, 22 Jun 2006, Peter wrote:

> Well I just figured out the problem.  I'm trying to think of the best 
> solution right now.  The problem is in this block of code in set_row:
>
>        if ($cfg->{PREFER_NULL}) {
>                for (keys %{$cfg->{PREFER_NULL}}) {
>                        my $i = $cfg->{COLUMN_INDEX}{$_};
>                        undef $fields[$i] if $fields[$i] eq '';
>                }
>        }
>
> I believe that is supposed to set any fields which are set as PREFER_NULL and 
> have the empty string to NULL. The problem is that the if $fields[$i] eq '' 
> returns true for undefined as well, so it causes $fields[i] to explicitly be 
> set to undefined which causes the array to be expanded out to i-1 elements, 
> and all of the expanded out elements are set to undefined by default which 
> DBI translates to NULL.
>
> I can think of a few simple solutions, moving this block down below the next 
> if(scalar @fields == 1) { block would probably fix it and I'm inclined to do 
> that which will probably be enough to fix the problem as long as @fields 
> either contains only one element or a number of elements to equal the number 
> of fields in the table.  If set_row is ever called with @fields having 
> somethign in between then there will still be problems.

Interesting. Perhaps a simple:

     undef $fields[$i] if exists $fields[$i] and $fields[$i] eq '';

would do the trick by not expanding the array.

Jon


-- 
Jon Jensen
End Point Corporation
http://www.endpoint.com/


More information about the interchange-users mailing list