1 Aug 2010 02:34
Re: multiple connections with DBI and Mysql
Dave Lilley <dglnz2 <at> gmail.com>
2010-08-01 00:34:54 GMT
2010-08-01 00:34:54 GMT
Hassan Schroeder wrote: > On Sat, Jul 31, 2010 at 2:04 AM, Dave Lilley <dglnz2 <at> gmail.com> wrote: > >> I am sure I need to use a pool of connections but am unsure as to how >> best to do this. > > You might take a look at Sequel: <http://sequel.rubyforge.org/rdoc/> > > HTH, Thanks for the reply, I have done a wee test (code below) but I am getting errors as shown below the code. sequel.rb - my DB connections handler require 'sequel' class Dopen def initialise <at> db = Sequel.connect(:adapter=>'mysql', :host=>'localhost', :database=>'test', :user=>'dave', :password=>'test') end def allcust row = <at> db["SELECT * FROM cust_data"] puts " in all_cust #{row}" end end c = Dopen.new c.allcust running ruby sequel.rb give output below sequel.rb:9:in `allcust': undefined method `[]' for nil:NilClass (NoMethodError) from sequel.rb:16 I beleive I am missing something critical in the line row = <at> db["SELECT * FROM cust_data"] for it to give me the error above. was expecting at best and error like #<Sequel::MySQL::Dataset:0xb762cdcc> the next script is to call this sequel and access it's database connection and methods. One.rb calls the above class. Have another one called two.rb which I want called from within one to replicate multiple connections via 1 database connection (but this is step 3 and 4 of by plans). one.rb script below. require 'sequel' class One def initialise 'in One initialise!' <at> dbh = Dopen.new end def link puts 'in link' <at> dbh.allcust end end a=One.new puts a.link errors I get for this is... in link one.rb:14:in `link': undefined method `allcust' for nil:NilClass (NoMethodError) from one.rb:21 NOTE the 2 very end lines of sequel.rb are commented out when I call via one.rb. you're help would be grateful. I will in the meantime continue to try and find a solution dave -- -- Posted via http://www.ruby-forum.com/.
RSS Feed