re-executing prepared statement leads to "Modification of a read-onlyvalue attempted"
am 12.06.2006 13:22:33 von paul lucassenHi,
While playing with the examples from the eg/ directory
(DBD-mysql-3.0006_1) I took proc_example3.pl and
copied the $sth->execute and the subsequent do-block.
The second execution then leads to a
Modification of a read-only value attempted
at the line with while (@row= $sth->fetchrow_array()). (The problem here
is with $sth)
My environment: SLES9 with stock perl (5.8.3), Mysql 5.0.21, DBI 1.51,
DBD::mysql 3.0006_1.
The test-script:
#!/usr/bin/perl
use DBI;
$DATABASE='test';
$HOST='localhost';
$PORT=3306; $USER='root';
$PASSWORD='';
$dbh = DBI->connect("DBI:mysql:$DATABASE:$HOST:$PORT",
"$USER", "$PASSWORD",
{ PrintError => 0}) || die $DBI::errstr;
$dbh->trace(3, "./dbd.log");
$dbh->do("drop procedure if exists testproc") or print $DBI::errstr;
$dbh->do("create procedure testproc() deterministic
begin
declare a,b,c,d,e,f int;
set a=1;
set b=2;
set c=3;
set d=4;
set e=5;
set f=6;
select a, b, c, d;
select d, c, b, a;
select b, a, c, d;
select c, b, d, a;
select a, d;
select a, b, c, d, e, f;
select f;
end") or print $DBI::errstr;
$sth=$dbh->prepare('call testproc()') || die $DBI::err.": ".$DBI::errstr;
$sth->execute || die DBI::err.": ".$DBI::errstr; $rowset=0;
do {
print "\nRowset ".++$i."\n---------------------------------------\n\n";
foreach $colno (0..$sth->{NUM_OF_FIELDS}) {
print $sth->{NAME}->[$colno]."\t";
}
print "\n";
while (@row= $sth->fetchrow_array()) {
foreach $field (0..$#row) {
print $row[$field]."\t";
}
print "\n";
}
} until (!$sth->more_results)
;
$sth->execute || die DBI::err.": ".$DBI::errstr; $rowset=0;
do {
print "\nRowset ".++$i."\n---------------------------------------\n\n";
foreach $colno (0..$sth->{NUM_OF_FIELDS}) {
print $sth->{NAME}->[$colno]."\t";
}
print "\n";
while (@row= $sth->fetchrow_array()) {
foreach $field (0..$#row) {
print $row[$field]."\t";
}
print "\n";
}
} until (!$sth->more_results)
;
The result:
Rowset 1
---------------------------------------
a b c d
1 2 3 4
Rowset 2
---------------------------------------
d c b a
4 3 2 1
Rowset 3
---------------------------------------
b a c d
2 1 3 4
Rowset 4
---------------------------------------
c b d a
3 2 4 1
Rowset 5
---------------------------------------
a d
1 4
Rowset 6
---------------------------------------
a b c d e
1 2 3 4 5 6
Rowset 7
---------------------------------------
f
6
Rowset 8
---------------------------------------
a b c d
Modification of a read-only value attempted at ./tt.pl line 62.
Is this faulty behavior or am I using it the wrong way?
Thanks for any help,
Paul Lucassen
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org