Perl DBI :: fetchrow_array () gives an empty value instead of undef for NULL

After moving to a new server after executing a SELECT query, if the requested column value is NULL , Perl 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 get undef from NULL , and indeed that is how it works on my old server. There is a copy of the MySQL database on the new server that I migrated using the Export SQL and Import SQL functions for Sequel Pro, the MySQL gui that I run on my Mac. For both databases, the indicated values ​​are clearly marked as gray NULL in Sequel Pro and as NULL if I run mysqlinteractively. For example, see namethis decryption:

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 works with 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" ;
    }
}

Many thanks to everyone who can offer what can be here!

+4
1

Use of uninitialized value in subroutine entry

utf8::decode($value) $value . undef, ( )

. ,

utf8::decode($value) if $value and not utf8::is_utf8($value);

?

, , DBI , {mysql_enable_utf8mb4 => 1} connect. CHARACTER SET utf8mb4 CREATE TABLE CREATE DATABASE. ( CHARACTER SET utf8, UTF-8, .) , ALTER TABLE , .

+4

Source: https://habr.com/ru/post/1656456/


All Articles