Subject: | DBD::mysql - multiple statements/more_results undefined behaviour |
Date: | Wed, 11 May 2011 16:07:23 +0100 |
To: | <bug-dbd-mysql [...] rt.cpan.org> |
From: | Michael Ramnarine <m.ramnarine [...] hotmail.co.uk> |
Hi guys,
I've been using DBD::mysql recently and have come across an (as far as I can tell) undocumented use case:(Details of my system are listed below.)
With multiple statements enabled a second execute, even from a separate statement handle, will overwrite any unfetched result sets.
Is this intentional or desirable? Caching on a per handle basis would have an overhead, but would lead to more deterministic behaviour.
Depending on what the best course of action is I may be in a position to aid with development. However, my current skill set would likely limit me to a pure Perl implementation; I've only read XS code and my C is a bit rusty.
Any feedback or advice would be appreciated. Thanks in advance,
Mike
System:
Red Hat Enterprise Linux Server v5.3
DBD::mysql v4.017
DBI v1.614
MySQL V5.1.42
Example:
#! perl
use Data::Dumper;
use strict;
use warnings;
use DBI ();
use vars qw($table $test_dsn $test_user $test_password);
my $dbh;
eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
{ RaiseError => 1, PrintError => 1, AutoCommit => 0,
mysql_multi_statements => 1 });};
if ($@) {die}
my ($sth1, $sth2);
$sth1 = $dbh->prepare('SELECT "First Set"; SELECT "Never Seen"');
$sth2 = $dbh->prepare('SELECT "First Set too";SELECT "Overwrites with impunity"');
$sth1->execute();
$sth2->execute();
print "sth1 1st:\n".Dumper $sth1->fetchrow_arrayref();
print "sth2 1st:\n".Dumper $sth2->fetchrow_arrayref();
$sth1->more_results();
$sth2->more_results();
print "sth1 2nd: replaced\n".Dumper $sth1->fetchrow_arrayref();
print "sth2 2nd: nothing left\n".Dumper $sth2->fetchrow_arrayref();
$sth1->finish();#still active
$sth2->finish();#inactive
$dbh->disconnect();
Output:
sth1 1st:
$VAR1 = [
'First Set'
];
sth2 1st
$VAR1 = [
'First Set too'
];
sth1 2nd - replaced
$VAR1 = [
'Overwrites with impunity'
];
sth2 2nd - nothing left
$VAR1 = undef;