|Just another Perl shrine|
DBI (incorrectly) bound variablesby Xaositect (Friar)
|on Jan 31, 2003 at 19:36 UTC||Need Help??|
Xaositect has asked for the wisdom of the Perl Monks concerning the following question:
I'm hoping someone will just recognize this and know what the problem is, because if not it means a lot more work on my part to figure it out. I've run into a problem where it appears DBI is incorrectly binding a number as a string in the limit on a query.
I'm using DBI and CGI::Application in a website, part of which is a catalog / shopping cart / purchase system. Products in the catalog are broken into pages of 20 items each. This breaking of pages is done by encoding the number of prizes into a link, and limiting my select based on that number. So I have a link like:
where the startitem is set dynamicly based on the current page. (there are other params passed here too, but anyway) The actual query looks something like:
So what I want to do after that is:
However, DBI binds $start_item as a string, and quotes it. This causes an error, as limit doesn't take a string. Here's where it gets bizzare. I tried playing with $start_item in all sorts of ways, trying to figure out why DBI was turning it into a string. Some examples of things that didn't work: (DBI still quoted the param)
As other tests, I tried putting a hardcoded number in the call to $sth->execute(), and it worked. I tried assigning the $start_item in the second part of the limit (third bound param instead of second) and DBI quoted it. So far, the only way I've been able to get it working is the insane:
which should absolutely not be necessary. Any ideas?