On Sun, Apr 29, 2001 at 04:22:08PM -0400, Curt Russell Crandall wrote:
> I'm getting conversion errors (VARCHAR to [SMALL]DATETIME) on an
> insert. I have a structure that contains a list of params that need to be
> inserted into a db table. Prior to insertion, I make sure that undef
> values are treated as SQL NULLs:
>
> for (my $i = 0; $i <= $#array; $i++)
> {
> if ((!DBI::looks_like_number($array[$i]) && (!$array[$i]))
> {
> $array[$i] = $dbh->quote($array[$i];
> }
> }
>
>
> Then I go through and use bind_param on all the array members, specifying
> each params SQL data type:
>
> $sth->bind_param(1, \$array[0], SQL_DATE);
> ....
>
You should use either $dbh->quote() OR $sth->bind_param(). If you use
both, then you are inserting the literal string 'NULL', not the special SQL
value NULL. With placeholders, the quoting is handled automatically.
Ronald