Johnathon22 Johnathon22 - 8 months ago 35
SQL Question

SQL Error with ruby

require 'mysql2'

SCHEDULER.every '2h', :first_in => 0 do |job|

# MySQL connection
db = => "host", :username => "username", :password => "password", :port => port, :database => "database" )

sql = "select count(*) from tickets where department_id = 6;"
tickets_sql = db.query(sql)
puts tickets_sql

#Send Events
send_event('tickets_sql', {current: tickets_sql})


I am using the
command so I can see the output in my log file. The output of this command is an error message which is:

What does this error mean?

I took the same exact query as in the code and ran it on the database and it outputs the number as expected.


It is not an error message, it is an object (Mysql2::Result). You can give count(*) and alias (put as smth after it) and access as tickets_sql.first['smth'] (you can use first as there is only one row, otherwise you get a collection, so you should iterate through it with .each, for example, to output retrieved rows with puts).