Connecting to a database

I did a lot of googling and looking around the related Ruby websites, but I
still cannot find a concreate example of how to connect to a database using
a DSN and/or a DSN-less connection.

If I do this with win32ole – it seems to me that sort of means my code is
not really crossplatform. So, I think I would like to do it with a general
odbc library…but maybe this is more trouble than it’s worth?

I do have a near-term need to grab 100,000+ contacts from a MS SQL Server
and place them into Outlook contacts. So my needs are win-specific.

Basically, if someone can tell me how to connect to the server, prepare and
execute a sql statement and then iterate over a result-set, I could probably
get this done. :slight_smile:

Can anyone help with this?

-Dwayne

“Dwayne Smurdon @ DNA Media Pro” smurdon@dnamediapro.com writes:

I did a lot of googling and looking around the related Ruby websites, but I
still cannot find a concreate example of how to connect to a database using
a DSN and/or a DSN-less connection.

The big two are ODBC and DBI. I prefer DBI. The ruby-dbi package is at
http://ruby-dbi.sourceforge.net/. DBI, like ODBC, is just a front-end
to various dbase specific drivers (DBD). There is ADO DBD which allows
you to use win32’ ADO infrastructure.

Basically, if someone can tell me how to connect to the server, prepare and
execute a sql statement and then iterate over a result-set, I could probably
get this done. :slight_smile:

The ruby-dbi site glosses over the action you want to perform. A more
detailed explanation is found at perl-dbi site:
http://dbi.perl.org/doc/index.html.

You can also come to ruby’s irc channel and ask some people.

YS.
gnome.

Here’s an ADO example

require ‘win32ole’

db = WIN32OLE.new(“ADODB.Connection”)
db.open ""Provider=SQLOLEDB;Data Source=MyServer;Database=MyDb;User
ID=sa;Password=password;"
rs = db.execute (“select * from MyTable”)
rs.MoveFirst
rows = []
while !rs.eof
rowhash = {}
rs.fields.each do |field|
rowhash[field.name] = field.value
end
rows << rowhash
rs.MoveNext
end

this produces an array of hashes - each hash representing each record

Chris
http://clabs.org

“Dwayne Smurdon @ DNA Media Pro” smurdon@dnamediapro.com writes:

I did a lot of googling and looking around the related Ruby websites, but I
still cannot find a concreate example of how to connect to a database using
a DSN and/or a DSN-less connection.

The big two are ODBC and DBI. I prefer DBI. The ruby-dbi package is at
http://ruby-dbi.sourceforge.net/. DBI, like ODBC, is just a front-end
to various dbase specific drivers (DBD). There is ADO DBD which allows
you to use win32’ ADO infrastructure.

Basically, if someone can tell me how to connect to the server, prepare and
execute a sql statement and then iterate over a result-set, I could probably
get this done. :slight_smile:

The ruby-dbi site glosses over the action you want to perform. A more
detailed explanation is found at perl-dbi site:
http://dbi.perl.org/doc/index.html.

You can also come to ruby’s irc channel and ask some people.

It won’t show you specially how to connect with ADO, but you can find
instructions for the other stuff in the Ruby DBI article at:

http://www.kitebird.com/articles/

···

At 6:15 +0900 1/29/03, Yohanes Santoso wrote:

YS.
gnome.

Peter Hickman wrote:

There is a text to MIDI compiler (mine), what sort of midi
tools do people want?

Voice-to-MIDI as in Digital Ear (http://www.digital-ear.com/).

  • Jim -

James Davis wrote:

Voice-to-MIDI as in Digital Ear (http://www.digital-ear.com/).

Looks nice but its way out of my league.