I don't know about mySQL in particular, but in general DBI interprets
undef as a NULL.  So if I have a place-holder query like that I'll often
load everything into an array and then do something like:

for (my $i = 0; $i < scalar(@array); $i++) {
        if (!$array[$i]) { $array[$i] = undef; }
        $sth->execute(@array);
        }

Do:
perldoc DBI
and you'll find more detail on this there.

Paul

On Fri, 29 Nov 2002, Eric wrote:

> Hi,
> 
> Using DBI 1.30 on FreeBSD 4.6 with mySQL 4.04, DBD::mysql 2.0416, and Perl 5.06
> 
> Is it possible to insert a NULL with query like this?
> 
> $insert = qq!
> 
> INSERT INTO blah a,b,c VALUES (?,?,?)
> 
> !;
>       
> $insert_hnd = $dbh->prepare($insert_orders);
> 
> $insert_hnd->execute($var1,$var2,$var3);
> 
> 
> 
> Ok, so I have three vars to place in my execute statement, how can I make 
> one of them at least potentially insert a NULL?
> 
> 
> Or is there no way to do this with this form?
> I am trying to keep some logic out of a query module, but I can't get this 
> to work. Most of the time $var3 will have data. Some of the time it needs 
> to be left NULL.  Setting $var3 = 'NULL' or '"" doesn't work. What if I 
> undef ed $var3?
> 
> 
> 
> Thanks,
> 
> 
> Eric 
> 

Reply via email to