I''m having the strangest problem... I''m getting syntax errors on this find... @lob_messages = ProviderMessage.find(:all, :conditions => [ "to = ?", "GFA"], :order => ''created_at DESC'', :limit => 5) The Exception Rails is returning is:Mysql::Error: #42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''to = ''GFA'') ORDER BY created_at DESC LIMIT 5'' at line 1: SELECT * FROM provider_messages WHERE (to = ''GFA'') ORDER BY created_at DESC LIMIT 5I really would appreciate another set of eyeballs. Anybody see anything wrong with the find?And I can''t get a find with :conditions => [ "something IN (?)", some_array] to work either.Any assistance would really be appreciated!TIA,Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8/4/07, Bill Walton <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> > I''m having the strangest problem... > > I''m getting syntax errors on this find... > > @lob_messages = ProviderMessage.find(:all, > :conditions => [ "to = ?", > "GFA"], > :order => ''created_at DESC'', > :limit => 5) > > The Exception Rails is returning is: > > Mysql::Error: #42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''to = ''GFA'') ORDER BY created_at DESC LIMIT 5'' at line 1: SELECT * FROM provider_messages WHERE (to = ''GFA'') ORDER BY created_at DESC LIMIT 5 > > I really would appreciate another set of eyeballs. Anybody see anything wrong with the find? > >It seems "to" is a reserved word in mysql, check the manual yourself. And I can''t get a find with :conditions => [ "something IN (?)", some_array] to work either.> >use some_array.joins(",") instead. Any assistance would really be appreciated!> > TIA, > > Bill > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ye Dingding wrote:> It seems "to" is a reserved word in mysql,Thanks. It never occurred to me that it might be a reserved word problem.> use some_array.joins(",") instead.And thanks again! Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 3, 2007, at 2:18 PM, Ye Dingding wrote:> On 8/4/07, Bill Walton <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: > I''m having the strangest problem... > > I''m getting syntax errors on this find... > > @lob_messages = ProviderMessage.find(:all, > :conditions => [ "to = ?", > "GFA"], > :order => ''created_at DESC'', > :limit => 5) > The Exception Rails is returning is: > Mysql::Error: #42000You have an error in your SQL syntax; check the > manual that corresponds to your MySQL server version for the right > syntax to use near ''to = ''GFA'') ORDER BY created_at DESC LIMIT 5'' > at line 1: SELECT * FROM provider_messages WHERE (to = ''GFA'') > ORDER BY created_at DESC LIMIT 5 > I really would appreciate another set of eyeballs. Anybody see > anything wrong with the find? > > It seems "to" is a reserved word in mysql, check the manual yourself. > > And I can''t get a find with :conditions => [ "something IN (?)", > some_array] to work either. > > use some_array.joins(",") instead. > > Any assistance would really be appreciated! > TIA, > BillWhile I''d strongly suggest that you change the name of that column, if you actually managed to create a column with that name, you should be able to add ID quotes (that is, backticks or grave accents) to the column name: :conditions => [ "`to` = ?", "GFA"], -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Rob, Rob Biedenharn wrote:> While I''d strongly suggest that you change the name > of that column,Did that.> if you actually managed to create a column with that name,Did. Via a migration.> you should be able to add ID quotes (that is, backticks or > grave accents) to the column name:Thanks for that information. When I get some time, I''ll go back and see if that works. Thanks again! Bill :conditions => [ "`to` = ?", "GFA"], -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-04 12:00 UTC
Re: Problem with :conditions in find
Rob, Would you mind taking this one step further and show how I''d write the condition to find an integer instead of a string. I get the same error message described above when I try to make the :condition for an integer like this; :conditions => [ ''intfieldvalue = ?, intvalue''] surprisingly, it passes with this, but the condition is disregared for some reason? :conditions => [ ''intfieldvalue = intvalue''] I am grateful for a reply. Kathy KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org On Aug 3, 5:18 pm, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> Hi Rob, > > Rob Biedenharn wrote: > > While I''d strongly suggest that you change the name > > of that column, > > Did that. > > > if you actually managed to create a column with that name, > > Did. Via a migration. > > > you should be able to add ID quotes (that is, backticks or > > grave accents) to the column name: > > Thanks for that information. When I get some time, I''ll go back and see if > that works. > > Thanks again! > Bill > :conditions => [ "`to` = ?", "GFA"], > > -Rob > > Rob Biedenharnhttp://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-04 12:05 UTC
Re: Problem with :conditions in find
Hi -- On Sat, 4 Aug 2007, KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > Rob, > Would you mind taking this one step further and show how I''d write the > condition to find an integer instead of a string. > I get the same error message described above when I try to make > the :condition for an integer like this; > :conditions => [ ''intfieldvalue = ?, intvalue'']That has to be: :conditions => [''intfieldvalue = ?'', intvalue] The values to be interpolated have to be outside the string, as separate array elements.> surprisingly, it passes with this, but the condition is disregared for > some reason? > :conditions => [ ''intfieldvalue = intvalue'']If you want it all in one string (usually not advisable, for security reasons), you''d have to do Ruby-style string interpolation: :conditions => "intfieldvalue = #{intvalue}" David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---