Skip to content

Instantly share code, notes, and snippets.

@mikecmpbll
Created August 22, 2012 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikecmpbll/3426276 to your computer and use it in GitHub Desktop.
Save mikecmpbll/3426276 to your computer and use it in GitHub Desktop.
Mysql2 error
# MySQL db, Rails 3.2, Ruby 1.8.7
# Works for anything other than 1 in: `students`.`sen_status_id` IN ...
# sens_status_id is an int column.
# There are significantly more rows with 1 than anything else, some are NULL, others are 2 and 3
Student Load (38.5ms) SELECT DISTINCT students.* FROM `students` LEFT JOIN klasses_students ON ( klasses_students.student_id = students.id ) WHERE `students`.`sen_status_id` IN (1, 2) AND `klasses_students`.`klass_id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND (archived = 0) ORDER BY firstname ASC
Mysql2::Error: Lost connection to MySQL server during query: SELECT DISTINCT students.* FROM `students` LEFT JOIN klasses_students ON ( klasses_students.student_id = students.id ) WHERE `students`.`sen_status_id` IN (1, 2) AND `klasses_students`.`klass_id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND (archived = 0) ORDER BY firstname ASC
Completed 500 Internal Server Error in 85ms
ActiveRecord::StatementInvalid (Mysql2::Error: Lost connection to MySQL server during query: SELECT DISTINCT students.* FROM `students` LEFT JOIN klasses_students ON ( klasses_students.student_id = students.id ) WHERE `students`.`sen_status_id` IN (1, 2) AND `klasses_students`.`klass_id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND (archived = 0) ORDER BY firstname ASC):
app/controllers/reports_controller.rb:401:in `multiple'
# This on the other hand, goes through untroubled:
Student Load (7.7ms) SELECT DISTINCT students.* FROM `students` LEFT JOIN klasses_students ON ( klasses_students.student_id = students.id ) WHERE `students`.`sen_status_id` IN (2, 3) AND `klasses_students`.`klass_id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND (archived = 0) ORDER BY firstname ASC
# relevant bits from reports_controller.rb :
@students = Student.not_archived.where( conditions ).joins( joins ).select('DISTINCT students.*').order('firstname ASC')
line 401: @students.each do |s|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment