edieguez has asked for the wisdom of the Perl Monks concerning the following question:
And the error is:SET @num := 0; SET @id := -1; SELECT e.*, y.ChallengerID, CASE WHEN ep.isChampion IS TRUE THEN TRUE +ELSE FALSE END AS isCurrentChampion FROM ( . . .
The query executes without a problem in MySQL. I do not know why put placing the execution of the SET statement directly into the Perl code using \@ seems to result in something that works. In this case, I removed the SET statement from the code.sql file but left the remainder of the SQL code in place...DBD::mysql::st execute failed: You have an error in your SQL syntax; c +heck the manual that corresponds to your MySQL server version for the + right syntax to use near 'SET @id := -1; SELECT e.*, y.ChallengerID, CASE WHEN ep.isChampion IS TRUE THE' at li +ne 2
#!/usr/bin/env perl use strict; use warnings; use DBI; use Data::Dumper; # MYSQL CONFIG VARIABLES my $host = "XYZ"; my $db = "XYZ"; my $dbuser = "XYZ"; my $dbpw = "XYZ"; # CONNECT TO MYSQL my $dbh = DBI->connect("DBI:mysql:$db", $dbuser, $dbpw) || die "Could +not connect to database: $DBI::errstr"; my $myquery; $myquery = "SET \@num := 0, \@id := -1;"; my $sth = $dbh->prepare($myquery); $sth->execute(); # Retrieve all open tests my $file = "../sql/code.sql"; { local $/ = undef; open FILE, $file or die "Couldn't open file: $!"; $myquery = <FILE>; close FILE; } print "\nSQL scheduling query constructed... executing..."; + $sth = $dbh->prepare($myquery); $sth->execute();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBD and a MySQL query with a SET @num line
by kcott (Archbishop) on Jan 19, 2014 at 16:05 UTC | |
by edieguez (Initiate) on Jan 19, 2014 at 16:09 UTC | |
by karlgoethebier (Abbot) on Jan 19, 2014 at 16:52 UTC | |
|
Re: DBD and a MySQL query with a SET @num line
by kcott (Archbishop) on Jan 19, 2014 at 16:47 UTC | |
by edieguez (Initiate) on Jan 20, 2014 at 05:08 UTC | |
|
Re: DBD and a MySQL query with a SET @num line
by clueless newbie (Curate) on Jan 19, 2014 at 16:20 UTC | |
|
Re: DBD and a MySQL query with a SET @num line
by Neighbour (Friar) on Jan 20, 2014 at 10:19 UTC | |
by edieguez (Initiate) on Jan 22, 2014 at 04:10 UTC | |
|
Re: DBD and a MySQL query with a SET @num line
by karlgoethebier (Abbot) on Jan 19, 2014 at 18:03 UTC |