Skip Menu |
 

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

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

People
Owner: Nobody in particular
Requestors: mike [...] mikero.com
Cc:
AdminCc:

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



Subject: fetchall_arrayref error
Download (untitled) / with headers
text/plain 1.4k
I'm not entirely sure if this is a DBD or DBI problem. But since I cannot replicate it with SQLite I will file this with you... Let me know if I should really file this under DBI instead. In my test code below, fetchrow_arrayref gives the error: "DBD::mysql::st fetchall_arrayref failed: fetch() without execute() at ..." and loops forever. If I replace [0] with undef in the fetchall_arrayref() call, it works as expected. If I use SQLite, it works as expected. Thing is, I can see the individual rows of data being fetched when I turn on tracing. I'm using DBI 1.38, DBD::mysql 2.9003, libmysqlclient12 4.0.16-2, perl 5.8.2. All are the standard packages from debian unstable. test script: ###### use DBI; my $dbh = DBI->connect('dbi:mysql:test', 'test', 'test') or die; # my $dbh = DBI->connect('dbi:SQLite:dbname=testdb', '', '') or die; $dbh->do($_) for (split /\s*;\s*/, <<'END_OF_SQL'); drop table foo; create table foo ( bar int ); insert into foo (bar) values (5); insert into foo (bar) values (4); insert into foo (bar) values (7); insert into foo (bar) values (1); insert into foo (bar) values (3); END_OF_SQL my $sth = $dbh->prepare("select bar from foo") or die; $sth->execute or die; # fetchall_arrayref(undef, 3) works while (my $rows = $sth->fetchall_arrayref([0], 3)) { for (@$rows) { print "got @$_\n"; } print "---\n"; } $sth->finish; $dbh->disconnect;
From: patg [...] mysql.com
Download (untitled) / with headers
text/plain 2.2k
Hi there, Try this instead, it works as you intended: #!/usr/bin/perl use DBI; use Carp qw(croak); my $dbh = DBI->connect('dbi:mysql:test', '', '') or die; $dbh->do($_) for (split /\s*;\s*/, <<'END_OF_SQL'); drop table foo; create table foo ( bar int ); insert into foo (bar) values (5); insert into foo (bar) values (4); insert into foo (bar) values (7); insert into foo (bar) values (1); insert into foo (bar) values (3); END_OF_SQL my $sth = $dbh->prepare("select bar from foo") or die; $sth->execute or croak $DBI::errstr; my $rows = $sth->fetchall_arrayref([0], 3); for (@$rows) { print "bar $_->[0]\n"; } $sth->finish; $dbh->disconnect; [ROSULEK - Mon Jan 12 20:10:04 2004]: Show quoted text
> I'm not entirely sure if this is a DBD or DBI problem. But since I > cannot replicate it with SQLite I will file this with you... Let me > know if I should really file this under DBI instead. > > In my test code below, fetchrow_arrayref gives the error: > "DBD::mysql::st fetchall_arrayref failed: fetch() without execute() at > ..." > and loops forever. > > If I replace [0] with undef in the fetchall_arrayref() call, it works > as expected. If I use SQLite, it works as expected. > > Thing is, I can see the individual rows of data being fetched when I > turn on tracing. > > I'm using DBI 1.38, DBD::mysql 2.9003, libmysqlclient12 4.0.16-2, perl > 5.8.2. All are the standard packages from debian unstable. > > test script: > ###### > > use DBI; > my $dbh = DBI->connect('dbi:mysql:test', 'test', 'test') or die; > # my $dbh = DBI->connect('dbi:SQLite:dbname=testdb', '', '') or die; > > $dbh->do($_) for (split /\s*;\s*/, <<'END_OF_SQL'); > drop table foo; > create table foo ( bar int ); > insert into foo (bar) values (5); > insert into foo (bar) values (4); > insert into foo (bar) values (7); > insert into foo (bar) values (1); > insert into foo (bar) values (3); > END_OF_SQL > > my $sth = $dbh->prepare("select bar from foo") or die; > $sth->execute or die; > > # fetchall_arrayref(undef, 3) works > while (my $rows = $sth->fetchall_arrayref([0], 3)) { > for (@$rows) { > print "got @$_\n"; > } > print "---\n"; > } > > $sth->finish; > $dbh->disconnect; >
The suggested solution is right.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.