blokhead has asked for the wisdom of the Perl Monks concerning the following question:
OK. This code runs fine (for me)! But if I change undef to [0] in the fetchall_arrayref() line, I get this output:use DBI; my $dbh = DBI->connect('dbi:mysql:test', 'test', 'test') or die; $dbh->do($_) for (split /\s*;\s*/, <<'END_OF_SQL'); drop table if exists foo; create table foo ( bar int ); insert into foo set bar=5; insert into foo set bar=4; insert into foo set bar=7; insert into foo set bar=1; insert into foo set bar=3 END_OF_SQL ##### my $sth = $dbh->prepare("select bar from foo") or die; $sth->execute or die; # $sth->fetchall_arrayref([0], 3) while (my $rows = $sth->fetchall_arrayref(undef, 3)) { for (@$rows) { print "got @$_\n"; } print "---\n"; } __OUTPUT__ got 5 got 4 got 7 --- got 1 got 3 ---
What gives? The execute() is fine, and certainly is before the fetchall_arrayref() call. But some people even seem to get these errors with the undef in there! FWIW, I'm using DBI 1.38.__OUTPUT__ DBD::mysql::st fetchall_arrayref failed: fetch() without execute() at +foo.pl line 23. --- DBD::mysql::st fetchall_arrayref failed: fetch() without execute() at +foo.pl line 23. --- [... ad infinitum ..]
Since my query only returns one column, I should be able to use [0] as the first argument to fetchall_arrayref() to explicitly just fetch the one column. Right?
It's not a huge problem for me to fetch rows one at a time and avoid fetchall_*, but it would be kinda nice to use fetchall_*, as it seems to be the fastest way to get lots of a data.
Additional: It's not the infinite loop that bothers me so much -- that can be worked around. It's that with the [0] argument, the fetchall_arrayref() doesn't work at all and I can't get the query's results.
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI::fetchall_arrayref() error
by dbwiz (Curate) on Jan 12, 2004 at 00:35 UTC | |
|
Re: DBI::fetchall_arrayref() error
by bart (Canon) on Jan 11, 2004 at 23:17 UTC | |
by pg (Canon) on Jan 12, 2004 at 01:21 UTC | |
by Anonymous Monk on Jan 11, 2004 at 23:30 UTC | |
|
Re: DBI::fetchall_arrayref() error
by caedes (Pilgrim) on Jan 12, 2004 at 01:50 UTC | |
|
Re: DBI::fetchall_arrayref() error
by Roger (Parson) on Jan 12, 2004 at 00:35 UTC | |
by pg (Canon) on Jan 12, 2004 at 01:55 UTC | |
by Roger (Parson) on Jan 12, 2004 at 02:34 UTC | |
by pg (Canon) on Jan 12, 2004 at 03:02 UTC | |
|
Re: DBI::fetchall_arrayref() error
by sheep (Chaplain) on Jan 12, 2004 at 01:38 UTC | |
by pg (Canon) on Jan 12, 2004 at 02:27 UTC | |
|
Re: DBI::fetchall_arrayref() error
by Anonymous Monk on Jan 12, 2004 at 14:20 UTC | |
by Anonymous Monk on Jan 12, 2004 at 18:01 UTC |