After migrating to a new server, upon executing a SELECT query, if a requested column value is NULL, Perl's DBI::fetchrow_array()
returns what appears to be an empty string: defined()
returns 1 and length()
returns 0.
Everything I read tells me that I should be getting undef from a NULL, and indeed this is the way it works on my old server. The new server has a copy of the MySQL database which I migrated using the Export SQL and Import SQL features of Sequel Pro, a MySQL gui which I run on my Mac. For both databases, the values in question are clearly indicated as gray NULL in Sequel Pro, and as NULL if I run mysql
interactively. For example, see name
in this transcript:
mysql> SELECT * from trials WHERE id = 26069 ;
+-------+----------+-----------+---------+--------+ ...
| id | language | numTrials | name | status | ...
+-------+----------+-----------+---------+--------+ ...
| 26069 | en | 3 | NULL | Done | ...
+-------+----------+-----------+---------+--------+ ...
1 row in set (0.00 sec)
My old server is running older packages:
- Perl 5.10.1 vs. 5.22.1
- DBI 1.634 vs. 1.636
- DBD::mysql 4.022 vs. 4.033
Here is my code around fetchrow_array
:
@result = $statementHandle->fetchrow_array ;
for my $value (@result) {
if (! utf8::is_utf8($value)) {
utf8::decode($value) ;
# Log values for debugging the NULL/undef issue:
my $aValue = $value ;
my $len = length($aValue) ;
if (!defined($value)) {
$aValue = "<unnndefined>" ;
}
print {*::STDLOG} info => "daValue l=$len : $daValue\n" ;
}
}
Big thanks to anyone who can suggest what might be going on here!