Forum: Ruby on Rails Malformed SQL

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
hgs (Guest)
on 2005-11-12 13:49
(Received via mailing list)
I have

 orig_student = Student.find_first(:conditions => ["pnumber = ?",
     tudent.pnumber])

And I get
`
update_database(): pnumber is "00149246       "
update_database(): exception is 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 '?"00149246       "  LIMIT 1' at line 1

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
'?"00149246       "  LIMIT 1' at line 1
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/mysql_adapter.rb:119:in
`query'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/mysql_adapter.rb:119:in
`execute'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/mysql_adapter.rb:230:in
`select'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/mysql_adapter.rb:97:in
`select_all'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:376:in
`find_by_sql'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:343:in
`find'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:341:in
`find'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/deprecated_finders.rb:22:in
`find_first'
populate_tables2.rb:433:in `update_database'


Is there an obvious cause of this?  I can't see it.  Is the following
patch
against rails 0.13.1 a sensible suggestion?

        Hugh

--- ./mysql_adapter.rb.orig     2005-11-09 19:15:20.575395000 -0800
+++ ./mysql_adapter.rb  2005-11-09 19:26:23.411710000 -0800
@@ -132,7 +132,7 @@
         elsif exception.message.split(":").first =~ /Packets out of
order/
           raise ActiveRecord::StatementInvalid, "'Packets out of order'
error was received from the database. Please update your mysql bindings
(gem update mysql) and read
http://dev.mysql.com/doc/mysql/en/password-hashing.html for more
information."
         else
-          raise
+          raise exception.class.new(exception.message + ": SQL was: " +
sql)
         end
       end
This topic is locked and can not be replied to.