hi, I''m trying to write a test application that queries a postgres database, which so far I''ve managed to do but in a limited way. I''m completely lost how to perform transactions and how to return the primary key id for newly inserted rows. hopefully by placing some code someone might be able to help, require ''postgres'' db = PGconn.connect(''localhost'', 5432,'''','''',''testdatabase'',''username'',''password'') results = db.exec(''select * from testtable'') I can then loop on results and display them using puts. However suppose i wanted to issue the following statement but within a transaction? I simply can''t find any documentation anywhere to help me db.exec(''delete from testtable'') in addition, suppose i was to insert a row into testtable and want the id returned back? i can''t figure that out either. can anyone help? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Are you trying to do this in Rails? You know you could use the config/database.yml to set up the database and install the connector. You''re complicating things that don''t need complicating. On Jan 18, 2008 7:51 AM, hiddenhippo <redaudi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > hi, > > I''m trying to write a test application that queries a postgres > database, which so far I''ve managed to do but in a limited way. I''m > completely lost how to perform transactions and how to return the > primary key id for newly inserted rows. hopefully by placing some > code someone might be able to help, > > require ''postgres'' > > db = PGconn.connect(''localhost'', > 5432,'''','''',''testdatabase'',''username'',''password'') > results = db.exec(''select * from testtable'') > > I can then loop on results and display them using puts. > > However suppose i wanted to issue the following statement but within a > transaction? I simply can''t find any documentation anywhere to help > me > > db.exec(''delete from testtable'') > > in addition, suppose i was to insert a row into testtable and want the > id returned back? i can''t figure that out either. > > can anyone help? > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''m trying to do it outside of rails, so purely in ruby, but there''s a distinct lack of documentation covering postgres within ruby. On Jan 17, 11:13 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Are you trying to do this in Rails? > > You know you could use the config/database.yml to set up the database and > install the connector. You''re complicating things that don''t need > complicating. > > On Jan 18, 2008 7:51 AM, hiddenhippo <reda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > hi, > > > I''m trying to write a test application that queries a postgres > > database, which so far I''ve managed to do but in a limited way. I''m > > completely lost how to perform transactions and how to return the > > primary key id for newly inserted rows. hopefully by placing some > > code someone might be able to help, > > > require ''postgres'' > > > db = PGconn.connect(''localhost'', > > 5432,'''','''',''testdatabase'',''username'',''password'') > > results = db.exec(''select * from testtable'') > > > I can then loop on results and display them using puts. > > > However suppose i wanted to issue the following statement but within a > > transaction? I simply can''t find any documentation anywhere to help > > me > > > db.exec(''delete from testtable'') > > > in addition, suppose i was to insert a row into testtable and want the > > id returned back? i can''t figure that out either. > > > can anyone help? > > -- > Ryan Bigghttp://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---