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