[Chicago-talk] Interpolation problem

Shawn Carroll shawn.c.carroll at gmail.com
Wed Sep 30 11:26:42 PDT 2015


In the line

$q = "SELECT @rn:=@rn+1 AS RN, l.ID FROM logros l WHERE l.ID>?"

Replace the double quotes (") with single quotes (') to prevent
interpolation.


shawn.c.carroll at gmail.com
Software Engineer
Soccer Referee

On Wed, Sep 30, 2015 at 1:23 PM, <richard at rushlogistics.com> wrote:

> Wondering if anyone can lend a hand here. The set of queries below work
> when I just plug them directly into the MySQL console.  However, when I
> wrap them in perl they fail with SQL errors.
>
>    my @rn;
>    my $q = "set @rn = 0"'; # set row number var for query below in order
> to be able to iterate as a hash in featadd.tt
>    $sth = $dbh->prepare($q);
>    $sth->execute();
>
>    # for now in this same subroutine, let's get the sponsorships that
> these feats match
>    $q = "SELECT @rn:=@rn+1 AS RN, l.ID FROM logros l WHERE l.ID>?";
>    $sth = $dbh->prepare($q);
>    $sth->execute($lid);
>    my $log_ref = $sth->fetchall_hashref('RN');
>
> I get:
>
> DBD::mysql::st execute failed: You have an error in your SQL syntax; check
> the manual that corresponds to your MySQL server version for the right
> syntax to use near '= 0' at line 1 at test_sql.pl line 12.
> DBD::mysql::st execute failed: You have an error in your SQL syntax; check
> the manual that corresponds to your MySQL server version for the right
> syntax to use near ':=+1 AS RN, l.ID FROM logros l WHERE l.ID>'7'' at line
> 1 at test_sql.pl line 17.
> DBD::mysql::st fetchall_hashref failed: statement contains no result [err
> was 4 now 2000000000]
>
> Thanks for any help.
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20150930/8b9bb1cb/attachment.html>


More information about the Chicago-talk mailing list