[Chicago-talk] Interpolation problem
Jason A. Crome
cromedome at gmail.com
Wed Sep 30 11:29:35 PDT 2015
Shawn’s answer is best. You can put a \ before @rn to prevent interpolation as well. His way is cleaner though.
Jason A. Crome / CromeDome
AIM: TheOneCromeDome
Twitter: http://www.twitter.com/cromedome
Blog: http://crome-plated.tumblr.com/
CPAN: http://search.cpan.org/~cromedome/
github: http://github.com/cromedome
Bitbucket: https://bitbucket.org/cromedome/
> On Sep 30, 2015, at 1:26 PM, Shawn Carroll <shawn.c.carroll at gmail.com> wrote:
>
> 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
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
More information about the Chicago-talk
mailing list