Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Trouble updating value of variable for a placeholder

by thor (Priest)
on Jun 16, 2002 at 04:02 UTC ( #174896=note: print w/replies, xml ) Need Help??


in reply to Trouble updating value of variable for a placeholder

well, if it comes down to it, you may have to prepare your SQL with the limit already in it.
my $sth = $dbh->prepare('SELECT * FROM applicant WHERE date_col=? ORDE +R BY job_position LIMIT $limit,10'); $sth->execute($date) or die $sth->errstr;
Of course, you will have to prepare it every time, so use this as a last resort. Also, notice how I typed the first placeholder. Some DBDs require this (I was frustrated as hell until I discovered this was the case for Sybase).

thor

Replies are listed 'Best First'.
Re: Re: Trouble updating value of variable for a placeholder
by peppiv (Curate) on Jun 18, 2002 at 12:48 UTC
    UPDATE

    Workaround Solution

    I found a bug report on the web and a workaround solution. Thought some people might want to know this.

    my $sth = $dbh->prepare('SELECT * FROM applicant WHERE date_col = ? OR +DER BY job_position LIMIT ?,10'); $sth->bind_param(2, $limit, DBI::SQL_INTEGER); $sth->execute($date,$limit) or die $sth->errstr;

    Sometimes when using placeholders, especially for LIMIT, the DBD gets a little confused on what type of value it's being given. Line 2 binds the string $limit to an integer value. The "2" in the parenthesis is telling it the second string in the 'execute'. If you needed it for the first string it would be sth->bind_param(1, $date, DBI::SQL_INTEGER);
    Hey it worked for me. Maybe it can help someone else out.

    peppiv

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://174896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2021-06-18 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (90 votes). Check out past polls.

    Notices?