For example:
Assume a CAL table with the following rows: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"; }
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).id CAL_DS -------- -------------------- 1 A 2 AM 3 AMS 4 AMSTEL 5 DSTEL
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBD::Sybase bug
by VSarkiss (Monsignor) on Mar 12, 2002 at 20:09 UTC |