do() converts undef bound params to 0 for server side prepared statements

"Rob Mueller" <[email protected]> Tue, 15 Apr 2008 13:30:12 +1000
Newsgroups gmane.comp.db.mysql.perl
Message-ID <112801c89ea9$05e7ad30$8900a8c0@robmhp>
This is in DBD::mysql 4.006 and debian mysql client lib 5.0.32-7~bpo.1

---
#!/usr/bin/perl

use DBI;
use Data::Dumper;

my $dbh = 
DBI->connect('dbi:mysql:fastmail:127.0.0.1;mysql_server_prepare=1', 'root', 
'testpw');

$dbh->do('DROP TABLE IF EXISTS tmp_testnull');
$dbh->do('CREATE TABLE tmp_testnull (C1 int(11)) ENGINE=INNODB');

$dbh->do("INSERT INTO tmp_testnull values (?)", {}, 1);
$dbh->do("INSERT INTO tmp_testnull values (?)", {}, 2);
$dbh->do("INSERT INTO tmp_testnull values (?)", {}, undef);

print Dumper $dbh->selectcol_arrayref("SELECT c1 FROM tmp_testnull");
---

Output:

---
$VAR1 = [
          1,
          2,
          0
        ];
---

Expected output:

---
$VAR1 = [
          1,
          2,
          undef
        ];
---

Replacing do() with a prepare() + excute() call fixed the problem, or 
changing the connect string to mysql_server_prepare=0.

I'm surprised no one else ran into this bug yet...

Rob


-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]