|
|
sybperl-l Archive
Up Prev Next
From: "Durairaj K dot Avasi" <webdurai at webdurai dot com>
Subject: RE: Problem with DBD::Sybase using Sybase IQ
Date: Mar 23 2005 5:25PM
Well said Raju!
Joe,
Here is an another example you can parse through param:
use strict;
use DBI qw(:sql_types);
my $dbh = DBI->connect( 'dbi:Oracle:orcl',
'jeffrey',
'jeffspassword',
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made: $DBI::errstr";
my @names = ( "Larry%", "Tim%", "Randal%", "Doug%" );
my $sql = qq{ SELECT id, name, title, phone FROM employees WHERE name LIKE ? };
my $sth = $dbh->prepare( $sql );
for( @names ) {
$sth->bind_param( 1, $_, SQL_VARCHAR );
$sth->execute();
my( $id, $name, $title, $phone );
$sth->bind_columns( undef, \$id, \$name, \$title, \$phone );
while( $sth->fetch() ) {
print "$name, $title, $phone\n";
}
}
$sth->finish();
$dbh->disconnect();
Thanks and kind regards
Durairaj K. Avasi
Quoting "Raju, Ramakrishna (Equity)" :
> Joe,
>
> You should be using the bind_param() to specify the type of the
> parameter, like
>
> $stmt->bind_param( 1, "jc", SQL_VARCHAR );
> $stmt->bind_param( 2, "2005-02-28", SQL_DATETIME );
> ...
> ...
>
> and then,
>
> $stmt->execute();
>
> At the top, instead of "use DBI;" , say "use DBI qw(:sql_types);" . This
> should import the sql types into your .pl .
>
> Ram
>
> [Raju, Ramakrishna (Equity)] -----Original Message-----
> From: owner-sybperl-l@peppler.org [mailto:owner-sybperl-l@peppler.org]On
> Behalf Of Cumming, Joe
> Sent: Wednesday, March 23, 2005 9:17 AM
> To: sybperl-l@peppler.org
> Subject: Problem with DBD::Sybase using Sybase IQ
>
>
>
>
>
> Hello,
>
>
>
> I have a problem running execute() in DBD::Sybase when it has bind
> parameters.
>
>
>
> The following code
>
>
>
> my $sqlstmt =<<'EOST';
>
> INSERT INTO creditqr.Tenor (MartModifiedID, MartSnapDate, ShortName, Tenor,
> TenorID)
>
> VALUES (?,?,?,?,?);
>
> EOST
>
>
>
> my $stmt = $dbi->prepare($sqlstmt);
>
>
>
> my @values = ('jc', "2005-02-28", "Test", 100, 500);
>
>
>
> $stmt->execute(@values);
>
>
>
> Produces the error:
>
>
>
> DBD::Sybase::st execute failed: Server message number=21 severity=14 state=0
> line=0 text=ASA Error -1000187: Unable to implicitly convert column
> 'MartModifiedID' to datatype (varchar) from datatype (integer).
>
> * (db_sqlins.cxx 10136) at dbitst.pl line 16.
>
>
>
>
>
> However, the code
>
>
>
> my $sqlstmt =<<'EOST';
>
> INSERT INTO creditqr.Tenor (MartModifiedID, MartSnapDate, ShortName, Tenor,
> TenorID)
>
> VALUES = ('jc', "2005-02-28", "Test", 100, 500);
>
> EOST
>
>
>
> my $stmt = $dbi->prepare($sqlstmt);
>
>
>
> $stmt->execute();
>
>
>
> works fine.
>
>
>
>
>
> Has anyone come across anything similar and know of a fix?
>
>
>
> Thanks,
>
>
>
> Joe
> --------------------------------------------------------
>
> If you are not an intended recipient of this e-mail, please notify the
> sender, delete it and do not read, act upon, print, disclose, copy, retain or
> redistribute it. Click here for important additional terms relating to this
> e-mail. http://www.ml.com/email_terms/
> --------------------------------------------------------
>
--
======================
Catch the mars if you can!!!
|