On Wed, Apr 25, 2001 at 05:19:14PM +0200, Sean Carte wrote:
> I'm trying (unsuccessfully) to get DBI:Pg to insert NULL values into
> a table. The following works in psql (and dbish):
>
> 'UPDATE null_test SET dwarf_1=NULL WHERE dwarf_2='Grumpy';'
>
> It also works in a $dbh->do() statement:
>
> But when I attempt the same with placeholders:
>
> $cursor = $dbh->prepare( qq{UPDATE null_test SET dwarf_1=? WHERE
> dwarf_2=?} ) || die $dbh->errstr;
> $cursor->execute(NULL, 'Grumpy') || die $dbh->errstr;
>
> Perl complains about the bareword, NULL. Turning off strict results
> in the string 'NULL' being inserted.
>
> I'm stuck. Please help.
Perl complains because the word NULL doesn't mean anything to it. And
if you put quotes around it, you'll find the same behaviour as you're
seeing with strict disabled: it'll insert the literal value "NULL".
What you want is
$cursor->execute('', 'Grumpy') || die $dbh->errstr;
Oracle have mentioned in the past that they might differentiate
between NULL and an empty string, but it's going to break so much
code, that I think we're safe with this...
--
Tommy Wareing
Software Engineer
Oxford English Dictionary
Oxford University Press