Global $DBH?

require ‘singleton’

Something like this should be re-workable into what you want:

http://segment7.net/projects/ruby/snippets/database.rb

···

Mike J. (candiazoo@comcast.net) wrote:

I recently decided that for the sake of portability it might be better
if I changed my app to not use the SQLite specific modules (ruby-sqlite
or sqlite-ruby, one of those) and instead made use of dbi.

Well, I quickly discovered that when using DBI.connect to my SQLite
database, it locks it and none of the other classes in my app can open
it to make extraneous queries.

SO… is there a “good” way (perhaps using BEGIN) to establish my
database handle for use by all classes/modules within my application?
I’ve fiddled with BEGIN but it seems to have scoping problems that I am
not familiar with (I am, btw, a relative newbie to Ruby, having been a
Python person up until the last month or so).


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Very cool. Is singleton a mixin? I still have a lot to learn. Thanks
for the tip!

Mike

···

On Thu, 18 Mar 2004 08:30:47 +0900, Eric Hodel wrote:

require ‘singleton’

Something like this should be re-workable into what you want:

http://segment7.net/projects/ruby/snippets/database.rb


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Yes.

···

Michael S. Jessop (candiazoo@comcast.net) wrote:

Very cool. Is singleton a mixin? I still have a lot to learn. Thanks
for the tip!


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04