Hi, all. I've discovered some odd behavior in a script I've written that uses DBD::mysql, and I think it's related to the large number of resuts my query is returning. First, the sample code:

-----------

#!/usr/bin/perl -Tw

use strict;
use DBD::mysql;

$ENV{'PATH'} = '';
my $conn = DBI->connect("DBI:mysql:db_name:db_host", 'db_user', 'db_pw');
my ($prep, $exec);


my $get_uptime_sql = "SELECT host,state,date FROM uptime WHERE date>='$min_timestamp' AND date<='$max_timestamp' ORDER BY host,date ASC";

$prep = $conn->prepare($get_uptime_sql)
        or die "Can't prepare: $conn->errstr\n";
$exec = $prep->execute
        or die "Can't execute: $conn->errstr\n";

LOOP: while (my @sql = $prep->fetchrow_array) {
        my ($host, $state, $date) = @sql;
        blah blah blah
}

---------

When I run the script, the MySQL lookup does return some results, but it also throws an error: "DBD::mysql::st fetchrow_array failed: fetch() without execute() at ./load_executive_snapshot.pl line [line number]". Since there is quite obviously an execute statement there, this would seem to indicate a problem with my SQL statement. However, I'm fairly confident that this isn't the case, because of the following:

1) I've had the script print out the SQL it's generating for $get_uptime_sql, and I've run that query at a MySQL prompt. It functions properly, returning 305,403 rows in just over a minute.

2) Simply adding a "LIMIT 500" to the end of the SQL query, or using a more restrictive set of dates than the script is meant to use, eliminates the error.

It seems to me, then, that DBD::mysql (or, at least, my particular DBD:mysql environment) isn't handling such a large result gracefully. I can think of workarounds for this, but I shouldn't have to, since I can get this to run just fine using, for example, a backticked reference to MySQL. Does anyone have any comments, or similar experiences?



Thanks,
Chris Braiotta
Web Services Manager
Network Operations Center
Harvard University

_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to