develooper Front page | perl.dbi.users | Postings from July 2006

Re: [DBD-ADO] bind_param broken in version 2.95?

Thread Previous
From:
Steffen Goeldner
Date:
July 24, 2006 01:25
Subject:
Re: [DBD-ADO] bind_param broken in version 2.95?
Message ID:
20060724T102500sgoeldner@cpan.org
jderrick wrote:

> Hi Everybody,
>
> DBD-ADO version 2.95 appears to have a problem with the bind_param =
> command when using the SQL type constants.  The problem does not occur =
> with version 2.94.  See the dbi-users posting "Possible bug in DBD-ADO =
> 2.94 bind_param" from September 24, 2005 for more info.  See below for =
> example code, error message received, and the source line in DBD-ADO =
> that is causing the error.  MS Access is the database being used by the =
> example code.=20
>
> Thanks and regards,
> John
>
>
> Error:
> Can't use string ("3") as a HASH ref while "strict refs" in use at =
> C:/Perl/site/lib/DBD/ADO.pm line 1022.
>
> ADO.pm Source line 1022:
> $i->{Size}  =3D defined $attr->{ado_size} ? $attr->{ado_size} : length =
> $value;
>
>
> Example code:
>
> use DBI qw(:sql_types);
>
> my $provider =3D "Microsoft.Jet.OLEDB.4.0";
> my $datasource =3D "db1.mdb";
>
> my $createSQL =3D <<END;
> CREATE TABLE test1 (
>     col1  COUNTER PRIMARY KEY,
>     col2  DECIMAL(9,2),
>     col3  VARCHAR(20)
> )
> END
>
> my $insertSQL =3D "INSERT INTO test1 (col2, col3) VALUES (?, ?)";
>
> my $dbh =3D DBI->connect("dbi:ADO:Provider=3D$provider;Data =
> Source=3D$datasource", "", "", {PrintError =3D> 1});
> die "could not connect to db $datasource" unless $dbh;
>
> $dbh->do($createSQL) or print "error on create table";
> my $sth =3D $dbh->prepare($insertSQL) or die "could not prepare SQL =
> insert";
>
> $sth->bind_param(1, 383874379.99, SQL_DECIMAL);
> $sth->bind_param(2, "this is a string", SQL_VARCHAR);
> $sth->execute();
>
> $dbh->disconnect();

Thanks for the report! I'll fix this in the next release -
something like

        if ( defined $attr && ref $attr && exists $attr->{ado_size} ) {
          $i->{Size}  = $attr->{ado_size};
        }
        else {
          $i->{Size}  = length $value;
        }

In the meantime, you can use

  { TYPE => SQL_... }


Steffen

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About