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.
In reply to Problem with hash dereferencing from DBI example by mje
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |