Search code examples
mysqlruby-on-railsquotes

Rails & MySQL: SELECT Statement Single vs. Double Quotes


I have a CRON job which executes a SELECT statement to grab records. When the SELECT runs on my dev machine, it produces the following statement:

SELECT `users`.* FROM `users` WHERE `users`.`id` = 87 LIMIT 1  

This is successful.

When the SELECT runs on my production (hosted) machine it produces the statement with double quotes:

SELECT "users".* FROM "users" WHERE "users”.”id” = 87 LIMIT 1

This is not successful and I get a MySQL 1064 error,

#1064 - 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 '.* FROM "users" WHERE "users

The code is the same on both machines, but my dev MySQL is version 5.5.33, whereas production is 5.1.67 (I don't have control over this to set/update it)

Is there a way to force single quotes or another preferred method to handle this situation?

Thanks for your time and assistance.

--EDIT--

Here are the main code snippets that are invoked via my CRON job:

/lib/tasks/reports.rake

namespace :report do
  desc "Send Daily Report"
  task :daily => :environment do
    User.where(:report_daily => 1).find_each do |user|
      ReportsMailer.send_report(user, 'daily').deliver
    end
  end

/app/mailers/reports_mailer.rb

def send_report(user, date_increment)
   @user = user
   @date_increment = date_increment
   get_times(user)
   mail :to => user.email, :subject=> "Report: #{@dates}"
 end

--EDIT2--

So it looks like I need to use slanted single quotes (`) in order for this to work successfully. How do I force my app or MySQL to use these instead of double (") quotes?


Solution

  • After further inspection, and working with my hosting company, its turns out that my query is timing out on their server. Thanks to all that responded.