Friday, April 1, 2011

Ruby on Rails Error: Mysql::Error: You have an error in your SQL syntax

Problem:
Mysql::Error: 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 '' at line 2:
        SELECT profiles.id FROM profiles
        WHERE profiles.person_id = #<Mysql::Result:0x7f53e9ca31b0>;

The rb code for this:
SELECT profiles.id FROM profiles       
WHERE profiles.person_id = #{person_id};").to_a.flatten

Solution:
SELECT 'profiles.id' FROM profiles       
  WHERE 'profiles.person_id' = '#{person_id}'").to_a.flatten

The reason for this is :
Any values which are not numeric will need to be quoted.

No comments:

Post a Comment