PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at peppler dot org>
Subject: DBD::Sybase bug
Date: Mar 12 2002 5:55PM

I've just been informed of a potentially nasty bug with DBD::Sybase
when using placeholders in conjunction with a LIKE clause. 

For example:

use DBI;

my $param = shift;

my $dbh = DBI->connect('dbi:Sybase:database=testdb', 'sa', '');
my $sth = $dbh->prepare("select * from CAL where CAL_DS like ? + '%'");
$sth->execute($param);
while(my $d = $sth->fetch) {
    print "@$d\n";
}

Assume a CAL table with the following rows:


id       CAL_DS              
 -------- --------------------
        1 A                   
        2 AM                  
        3 AMS                 
        4 AMSTEL              
        5 DSTEL               

Running the script with any argument starting with 'A' will return the
first 5 rows (so $sth->execute('ABC') and $sth->execute('A') have the
same effect). 

I've traced this to a bug in the Sybase OpenClient libraries, where
the input parameter description returns a parameter length of 1 for
this query, even though the CAL column is a varchar(20). 

The only work-around that I can think of is to move the '%' character
from the SQL string to the parameter (i.e. $sth->execute('AMS%'))
which will work as expected, but is not a generic solution for LIKE
queries if you always want to have the wildcard in the query. 

Michael
-- 
Michael Peppler                              Data Migrations, Inc.
mpeppler@peppler.org           *or*          mpeppler@mbay.net
http://www.mbay.net/~mpeppler
International Sybase User Group: http://www.isug.com