Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 80036
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: Nobody in particular
Requestors: mytram2 [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: When in async mode, fetchall_arrayref's $slice functionality is broken
Date: Sat, 6 Oct 2012 16:36:51 +1000
To: bug-DBD-mysql [...] rt.cpan.org
From: Marty <mytram2 [...] gmail.com>
Description: When in async mode, fetchall_arrayref's $slice functionality is broken because $sth's attributes cannot be fetched. Environment: perl 5.12.4 DBI::mysql 4.22 OS: Mac OSX 10.8.2, Linux Mint 12 Here is the code snippet to reproduce it my $dbh = DBI->connect($dsn, $user, $pass); my $sth = $dbh->prepare("select sleep(3) as sleep, 3 as number", { async => 1}); $sth->execute; my $attr = $sth->FETCH('FetchHashKeyName'); print Dumper($attr); # the NAME attribute is not populated my $names = $sth->FETCH($attr); # $names is undef. In sync mode, this will be populated with the column names [ 'sleep', 'number'] print Dumper($names), "\n"; until($sth->mysql_async_ready) { say 'not ready yet!'; sleep 1; } my $rows = $sth->fetchall_arrayref( {} ); # Fail with the following error # Can't use an undefined value as an ARRAY reference at /Library/Perl/5.12/darwin-thread-multi-2level/DBI.pm line 2054. Thanks
From: mytram2
The workaround is to call $sth->mysql_async_result once before any fetch calls when mysql_async_ready returns true. The call will have imp_sth->result properly assigned so that $sth- Show quoted text
>FETCH('NAME') can return correctly. This is because in the underlying
implementation of $sth->FETCH dbd_st_FETCH_attrib() is passed in imp_sth->result, and if this is not set, it will not call to get the table columns. On Sat Oct 06 02:37:05 2012, mytram2@gmail.com wrote: Show quoted text
> > Description: When in async mode, fetchall_arrayref's $slice > functionality is broken because $sth's attributes cannot be fetched. > > Environment: > > perl 5.12.4 > DBI::mysql 4.22 > OS: Mac OSX 10.8.2, Linux Mint 12 > > > Here is the code snippet to reproduce it > > my $dbh = DBI->connect($dsn, $user, $pass); > > my $sth = $dbh->prepare("select sleep(3) as sleep, 3 as number", { > async => 1}); > $sth->execute; > > my $attr = $sth->FETCH('FetchHashKeyName'); > print Dumper($attr); > > # the NAME attribute is not populated > my $names = $sth->FETCH($attr); # $names is undef. In sync mode, this > will be populated with the column names [ 'sleep', 'number'] > print Dumper($names), "\n"; > > > until($sth->mysql_async_ready) { > say 'not ready yet!'; > sleep 1; > } > > my $rows = $sth->fetchall_arrayref( {} ); # Fail with the following > error > # Can't use an undefined value as an ARRAY reference at > /Library/Perl/5.12/darwin-thread-multi-2level/DBI.pm line 2054. > > Thanks