|Think about Loose Coupling|
DBI Prepared Update and NULLsby paulbort (Hermit)
|on Jul 28, 2004 at 19:57 UTC||Need Help??|
paulbort has asked for the wisdom of the Perl Monks concerning the following question:
I'm quite happy with DBI except one gaping hole, and I am hoping that someone has a solution for this. I would like to prepare an SQL UPDATE statement, and be able to pass undef as a parameter when I execute that statement, and have the underlying database (PostgreSQL) set that field to NULL. It seems a reasonable request, given that a SELECT will return a NULL field as undef.
I've searched and super-searched, and read through the docs in perldoc and CPAN, and only found one good match: 137005 suggests using '' (empty string) instead of undef, but '' and NULL are different values.
I know I can construct an UPDATE statement and $dbh->do() it, but a prepared statement makes for much more readable code, IMHO.
Any ideas? I would be very happy to find that I'm missing something obvious.
UPDATE: Problem Solved. PEBCAK (Problem Exists Between Chair And Keyboard.) Once I reduced the update to one column , the undef to NULL mapping works for that column, so one of my other columns is doing something stupid. Thanks to all who helped.
Spring: Forces, Coiled Again!