Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Q: postgres access in Windows

Reply
Thread Tools

Q: postgres access in Windows

 
 
G. Ralph Kuntz, MD, MS
Guest
Posts: n/a
 
      07-28-2008
I spent a couple of hour this weekend trying to get Ruby to talk to
PostgreSQL on a Windows Vista machine without success. I am working
with both Cygwin Ruby and JRuby.

I installed the DBI gem, including dbd_pg. I get the following error
in both version of Ruby:

Could not load driver (no such file to load -- /usr/lib/ruby/
site_ruby/1.8/dbd/Pg)

I also tried jruby-postgres and pgconn but I could not figure out how
to call the first one and got errors with the second. I could not
find any documentation (even tried ri).

I tried Googling everything I could think of.

Has anyone gotten a DB connection to PostgreSQL working under Windows
with any version of Ruby?

Thanks.
 
Reply With Quote
 
 
 
 
J-H Johansen
Guest
Posts: n/a
 
      07-28-2008
On Mon, Jul 28, 2008 at 2:14 PM, G. Ralph Kuntz, MD, MS <(E-Mail Removed)> wrote:
> I spent a couple of hour this weekend trying to get Ruby to talk to
> PostgreSQL on a Windows Vista machine without success. I am working
> with both Cygwin Ruby and JRuby.
>
> I installed the DBI gem, including dbd_pg. I get the following error
> in both version of Ruby:
>
> Could not load driver (no such file to load -- /usr/lib/ruby/
> site_ruby/1.8/dbd/Pg)
>
> I also tried jruby-postgres and pgconn but I could not figure out how
> to call the first one and got errors with the second. I could not
> find any documentation (even tried ri).
>
> I tried Googling everything I could think of.
>
> Has anyone gotten a DB connection to PostgreSQL working under Windows
> with any version of Ruby?
>
> Thanks.
>
>



Hi,

My current use of postgres is done like this (but I think you can
require 'dbi' instead of 'rubygems'):

require 'rubygems'
require 'postgres'

$conn = PGconn.connect('hostname','port','','','db-name','username','password')

If you've installed rails you can also do the following in order to
use ActiveRecord which is nice:

require 'rubygems'
require 'active_record'

ActiveRecord::Base.pluralize_table_names = false
ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
:host => "hostname",
:database => "db-name",
:username => "username",
assword => "password"
)

And then create objects of tables or views.
Assuming you have a table or a view called gen_table:

class GenTable < ActiveRecord::Base; end
gt = GenTable.find(:all)

for a in gt
puts a.id
end



--
J-H Johansen
--
There are 10 kinds of people in the world: Those who understand binary and
those who don't...

 
Reply With Quote
 
 
 
 
G. Ralph Kuntz, MD, MS
Guest
Posts: n/a
 
      07-28-2008
That worked like a charm!

Is there any documentation on PGconn and the other classes in the
postgres-pr module?

Thanks.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting MS Access DB to Postgres or MySQL for ORM support withSQLalchemy Alec Taylor Python 2 11-30-2011 02:55 PM
Getting Ruby to work with Postgres on Windows XP Dillip Kumar Ruby 5 11-24-2007 01:14 AM
Postgres/Postgres-pr - some confusion Nick Black Ruby 1 11-16-2006 08:01 PM
Secure Postgres access Reid Priedhorsky Python 9 09-10-2006 12:49 PM
ruby-postgres for windows? Carl Youngblood Ruby 0 07-26-2003 07:41 PM



Advertisments