From: Ben Edwards Date: 2007-05-08T18:04:24+09:00 Subject: Re: Witch Oracle library should I use On 05/05/07, Ulf Hellstr�m wrote: > Hi Ben, > > You could always use fetch_hasch method instead of fetch. This will > fetch the data as a ruby Hash where each key is the column name > > Below is a simple example that select all columns from USER_TABLES > but only prints out the TABLE_NAME column. > > Note: The reference to the column name, in the sample TABLE_NAME has > to be in uppercase. > > The OCI8 API is documented quite good see > > http://ruby-oci8.rubyforge.org/en/api.html > > require 'oci8' > > class Testoci > > def get_data > > puts "***************************" > puts "Connecting..." > puts "***************************" > connection = OCI8.new('demo', 'demo', 'XE') > puts "***************************" > puts "Fetching data" > puts "***************************" > cursor = connection.parse("SELECT * FROM USER_TABLES") > cursor.exec() > # print out only the values of the TABLE_NAME column > while res = cursor.fetch_hash() > puts res["TABLE_NAME"] > end > cursor.close > connection.logoff > end > > end > > ora=Testoci.new > ora.get_data Thanks, just the ticket. Shame fetch_hash is not an iterator but think I am going to write a wrapper to make it easier to switch librarys/databases. Ben > Kindly Rgds > /Ulf > > On 4 maj 2007, at 21.37, Ben Edwards wrote: > > > On 04/05/07, Ulf Hellstr�m wrote: > >> Hi, > >> > >> I'm new on this mailing list. My name is Ulf , lives in Sweden and > >> been developing for Oracle for many, many years. Used to work for > >> Oracle for 10 years. > >> I've been studying and learning Ruby for aroune 2 months now and has > >> done some work with Ruby and Oracle. > >> As suggested i would defenly say go for Ruby/OCI8 > >> > >> There are some good introductions on how to use Ruby with Oracle on > >> OTN (Oracle Technology Network) > >> > >> See the following links: > >> > >> http://www.oracle.com/technology/pub/articles/marx-ruby.html > >> http://www.oracle.com/technology/pub/articles/tate-activeerecord.html > >> http://www.oracle.com/technology/pub/articles/haefel-oracle-ruby.html > >> http://www.oracle.com/technology/pub/articles/saternos-rails.html > > > > Thanks for this. Have been trying Ruby/OCI8 and it seems to work. > > Only thing is when it fetches row it is referenced as an array > > (row[0], row[1]...). Is there a way of referencing the column names > > (row["username"]...). > > > > Ben > > > >> Kindly Rgds > >> /Ulf > >> Ruby/OCI8 > >> > >> On 4 maj 2007, at 20.38, Brian Candler wrote: > >> > >> > On Sat, May 05, 2007 at 12:27:13AM +0900, Ben Edwards wrote: > >> >> Have had a look on rubyforge and done a little looking around > >> but not > >> >> totaly sure which ruby oracle library's I should use. > >> >> > >> >> I am connecting to a 10g database. > >> >> > >> >> Ruby9i and Ruby/OCI8 seem to be the contenders, or is there > >> >> something else. > >> >> > >> >> What would people recommend? > >> > > >> > ruby-oci8. It's been around for a long time, and it works well. > >> > It's the API > >> > used by ActiveRecord's Oracle adaptor, and it also comes with a DBD > >> > for use > >> > with ruby-dbi. I'm using it with Oracle 10g now. > >> > > >> > I've never seen or used Ruby9i though. > >> > > >> > >> > >> > > > > > > -- > > Ben Edwards - Bristol, UK > > If you have a problem emailing me use > > http://www.gurtlush.org.uk/profiles.php?uid=4 > > (email address this email is sent from may be defunct) > > > > > -- Ben Edwards - Bristol, UK If you have a problem emailing me use http://www.gurtlush.org.uk/profiles.php?uid=4 (email address this email is sent from may be defunct)