mje has asked for the wisdom of the Perl Monks concerning the following question:
I was just writing a bug off in DBD::ODBC when I needed to check the ParamTypes documentation and discovered it had a mistake:
# assuming $sth1 is a previously prepared statement handle my $sth2 = $dbh->prepare( $sth1->{Statement} ); my $ParamValues = $sth1->{ParamValues} || {}; my $ParamTypes = $sth1->{ParamTypes} || {}; $sth2->bind_param($_, $PV->{$_} $PT->{$_}) for keys %{ %$PV, %$PT }; $sth2->execute();
which should I guessed was just a typo and should be
# assuming $sth1 is a previously prepared statement handle my $sth2 = $dbh->prepare( $sth1->{Statement} ); my $ParamValues = $sth1->{ParamValues} || {}; my $ParamTypes = $sth1->{ParamTypes} || {}; $sth2->bind_param($_, $ParamValues->{$_} $ParamTypes->{$_}) for keys %{ %$ParamValues, %$ParamTypes }; $sth2->execute();
Before I committed the fix to DBI pod I thought I'd better check it out so I wrote:
use strict; use Data::Dumper; use DBI; my $h = DBI->connect; my $s = $h->prepare(q/insert into mje values(?)/); $s->bind_param(1, 2); $s->execute; my $ParamValues = $s->{ParamValues} || {}; my $ParamTypes = $s->{ParamTypes} || {}; print Dumper($ParamValues); print Dumper($ParamTypes); my $s2 = $h->prepare(q/insert into mje2 values(?)/); $s2->bind_param($_, $ParamValues->{$_}, $ParamTypes->{$_}) for keys %{ %$ParamValues, %$ParamTypes };
and it fails with "Can't use string ("1/8") as a HASH ref while "strict refs" in use at /tmp/z.pl line 18.". I've no idea why - any ideas?
The output which will make it easier to reproduce without DBI is:
UPDATE: posted wrong code at first - sorry.$VAR1 = { '1' => 2 }; $VAR1 = { '1' => { 'TYPE' => 4 } }; Can't use string ("1/8") as a HASH ref while "strict refs" in use at / +tmp/z.pl line 18.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with hash dereferencing from DBI example
by moritz (Cardinal) on Mar 08, 2011 at 13:56 UTC | |
by mje (Curate) on Mar 08, 2011 at 14:06 UTC | |
by moritz (Cardinal) on Mar 08, 2011 at 14:19 UTC |