Hi, I am trying to implement Base.connection.execute using a passed parameter from the calling view:- In my controller I have the following code:- def addnewsoa2 ActiveRecord::Base.connection.execute "INSERT INTO `soas` (`program_id`,`control_id`,`scope`,`detail`) VALUES (?,1,''Y'',''t.b.a.'')", @params[''proggy''] end This fails with a sql syntax error but I cant see where I am going wrong. The equivalent code in raw sql is okay. (i.e. "INSERT INTO `soas` (`program_id`,`control_id`,`scope`,`detail`) VALUES (13,1,''Y'',''t.b.a.'')" I think it''s the way I am using the passed parameter but would greatly appreciate any offered assistance. Thanks Martyn Elmy-Liddiard -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
On 7 Jan 2008, at 16:33, Martyn Elmy-liddiard wrote:> > Hi, > > I am trying to implement Base.connection.execute using a passed > parameter from the calling view:- > > In my controller I have the following code:- > > def addnewsoa2 > ActiveRecord::Base.connection.execute "INSERT INTO `soas` > (`program_id`,`control_id`,`scope`,`detail`) VALUES (?, > 1,''Y'',''t.b.a.'')", > @params[''proggy''] > end >Why are you using execute? Execute is much lower level than you need, and doesn''t understand parameters etc... It just chucks a string at the database adapter so you have to construct the entire bit of sql yourself. Why use this and not Soa.create(params) ? Fred> This fails with a sql syntax error but I cant see where I am going > wrong. The equivalent code in raw sql is okay. (i.e. "INSERT INTO > `soas` > (`program_id`,`control_id`,`scope`,`detail`) VALUES > (13,1,''Y'',''t.b.a.'')" > > I think it''s the way I am using the passed parameter but would greatly > appreciate any offered assistance. > > Thanks > > Martyn Elmy-Liddiard > -- > Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 7 Jan 2008, at 16:33, Martyn Elmy-liddiard wrote: > >> (`program_id`,`control_id`,`scope`,`detail`) VALUES (?, >> 1,''Y'',''t.b.a.'')", >> @params[''proggy''] >> end >> > Why are you using execute? Execute is much lower level than you need, > and doesn''t understand parameters etc... It just chucks a string at > the database adapter so you have to construct the entire bit of sql > yourself. Why use this and not Soa.create(params) ? > > FredThanks for response. Using execute just because I thought it was what I needed...I''m still getting to grips with ROR. Will look into Soa.create as you suggest and see if I can work it out. Thanks for the suggestion. Regards Martyn -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---