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.
[EMAIL PROTECTED] *or* [EMAIL PROTECTED]
http://www.mbay.net/~mpeppler
International Sybase User Group: http://www.isug.com