You need to change Perl-false values to undef.

From DBI:

NULL Values

Undefined values, or undef, are used to indicate NULL values. You can insert and update columns with a NULL value as you would a non-NULL value. These examples insert and update the column age with a NULL value:

$sth = $dbh->prepare(qq{ INSERT INTO people (fullname, age) VALUES (?, ?) }); $sth->execute("Joe Bloggs", undef);

Later

What I failed to say was that the first sentence quoted above would have been better written as:

Undefined values, or undef, are THE ONLY WAY used to indicate NULL values.
SQL, for reasons better understood by by its creators than me, makes a huge distinction between NULL values and either empty strings or zero values. Because of this, a WHERE clause that needs to account for both has to jump through hoops like
WHERE ISNULL(age, xx) = ISNULL(?, xx)
or
$where_clause = defined $age? "age = ?" : "age IS NULL";
My guess is that due to that NULL vs '' distinction the DBI module intentionally does not treat '' or 0 as NULL.

In reply to Re: Want DBI to load empty strings as NULL by keszler
in thread Want DBI to load empty strings as NULL by Narveson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.