I'm royally confused right now. This is something I've looked at on and
off but never followed through with and eventually would always forget
about.
I have several objects that have been created using Class::Struct. The
structure is filled by splitting a tab delimited record and feeding that
to the structure array:
@{$struct} = split("\t", $record);
The structure is scrubbed so leading/trailing whitespace, soft quotes and
dollar signs are all removed. Next, the structure array is run through a
loop to turn NULL fields (i.e. '', ' ', ' ', undef) into SQL NULLs:
for (my $i = 0; $i <= @#{$struct}; $i++;)
{
if ((!DBI::looks_like_number(${$struct}[$i]) && (!${$struct}[$i]))
{
${$struct}[$i] = undef;
${$struct}[$i] = $dbh->quote(${$struct}[$i]);
}
}
Next, the structure array is mapped to another structure array that
matches the columns of a db table I'm populating. If there's nothing to
map to one of the columns, I was doing this:
$outObj->param1("NULL");
where $outObj is the output structure and $outObj->param1() is its mutator
method.
The output structure is then scrubbed like the input structure was and
null/empty fields converted to SQL nulls. The the output structure array
is passed as an argument list to an insert statement:
my $cmd = sprintf("exec sales2..sa_ext_tran_dly %s%s%s.....", @$outObj);
my $rc = $dbh->do("$cmd");
Now, what has me scratching my head is why when I define an input argument
to this stored proc as "NULL" the string, it is showing up in the database
as [NULL]... this is what I want, but I'm wondering why it is working... I
would think that the database would've interpreted it as the string NULL.
Obviously I could make sure that I'm getting an SQL NULL by scrubbing
"NULL" values and using quote(undef) as the value. But now I'm concerned
that I might have made 2 mistakes that are cancelling each other out.
I realize that this could be a rather confusing post, if there's something
that I'm not getting across clearly, please let me know.
BTW: I'm using Perl 5.00404, DBI 1.13 and DBD::Sybase 0.21 on Solaris 2.6
with Sybase 11.9.2.
Thank you,
Curt