postgres DBI question

C

Chris Newman

------_=_NextPart_001_01C5D95E.A5993884
Content-Type: text/plain

Hi,

I'm trying to connect to a Postgresql database using the DBI and postgres
packages. My OS is Solaris 2.8.

Here's my code snippet...

#!/usr/local/bin/ruby

require 'dbi'
require 'postgres'

dbh = DBI.connect('dbi:pg:dbname=somedbasename;host=/var/tmp', 'someuser',
'somepasswd')

dbh.disconnect

However, when I run it I get...

/usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:490:in `load_driver': is not a
class/module (TypeError)
from /usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:392:in
`_get_full_driver'
from /usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:372:in `connect'
from ./ptexec_query.rb:9


I want to use DBI in case I want to change databases in the future. Any
suggestions would be appreciated.

Thanks,

cn

------_=_NextPart_001_01C5D95E.A5993884--
 
E

Ernest Ellingson

Chris said:
Hi,

I'm trying to connect to a Postgresql database using the DBI and postgres
packages. My OS is Solaris 2.8.

Here's my code snippet...

#!/usr/local/bin/ruby

require 'dbi'
require 'postgres'

dbh = DBI.connect('dbi:pg:dbname=somedbasename;host=/var/tmp', 'someuser',
'somepasswd')

dbh.disconnect

However, when I run it I get...

/usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:490:in `load_driver': is not a
class/module (TypeError)
from /usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:392:in
`_get_full_driver'
from /usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:372:in `connect'
from ./ptexec_query.rb:9


I want to use DBI in case I want to change databases in the future. Any
suggestions would be appreciated.

Thanks,

cn
Here's a link to some documentation on the dbi.
http://www.kitebird.com/articles/ruby-dbi.html
Hope it helps

Ernie
 
K

Kirk Haines

Hi,

I'm trying to connect to a Postgresql database using the DBI and postgres
packages. My OS is Solaris 2.8.

Here's my code snippet...

#!/usr/local/bin/ruby

require 'dbi'
require 'postgres'
^^^^^^^^^^^^^^^^^^-- Don't need this line. DBI will find the right driver and
load it itself.
/usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:490:in `load_driver': is not
a class/module (TypeError)
from /usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:392:in
`_get_full_driver'
from /usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:372:in `connect'
from ./ptexec_query.rb:9

DBI is complaining that it can't find the DBD driver that you told it to use
'Pg' here.

The problem, I bet, is that when you build DBI, you didn't build the DBD for
Pg.

When dbi is built, make sure to tell it what DBD's you want, like this:

ruby setup.rb config --with=dbi,dbd_pg,dbd_mysql

If you look in your sitelib for your ruby installation, in the DBD directory
(a path like /usr/local/lib/ruby/site_ruby/1.8/DBD) you should see a Pg
directory with a Pg.rb inside of it. If you don't, go back to the DBI
source, and do this:

ruby setup.rb config --with=dbd_pg
ruby setup.rb setup
ruby setup.rb install

And then try your snippet again.


Kirk Haines
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top