From: "M. Edward (Ed) Borasky" Date: 2007-06-04T21:57:06+09:00 Subject: Re: Using Ruby to get data from an Access Database Andy wrote: > Hi guys, I'm very new to this Ruby language. > > I only have basic experience of creating Intranet applications using ASP > and an MS Access Database. > > I'm trying to adapt some code from the www.Alexa.com 's example code but > don't know if what I'm trying to attempt is out of my depth. > > In its simplicisty this is what i'm trying to achieve, > > connecting to an access database to return the web addresses for 1,000 > firms, using the following Ruby code to query Alexa statistics and then > insert the result back into the access database. > > #/usr/bin/ruby > > require "cgi" > require "base64" > require "openssl" > require "digest/sha1" > require "uri" > require "net/https" > require "rexml/document" > require "time" > > ACCESS_KEY_ID = "--- Replace with your access key id ---" > SECRET_ACCESS_KEY = "--- Replace with your secret access key ---" > > action = "UrlInfo" > responseGroup = "Rank" > url = "yahoo.com" > > timestamp = ( Time::now ).utc.strftime("%Y-%m-%dT%H:%M:%S.000Z") > > signature = Base64.encode64( OpenSSL::HMAC.digest( > OpenSSL::Digest::Digest.new( "sha1" ), SECRET_ACCESS_KEY, action + > timestamp)).strip > > url = URI.parse( > > "http://awis.amazonaws.com/onca/xml?" + > { > "Action" => action, > "AWSAccessKeyId" => ACCESS_KEY_ID, > "Signature" => signature, > "Timestamp" => timestamp, > "ResponseGroup" => responseGroup, > "Url" => url > }.to_a.collect{|item| item.first + "=" + > CGI::escape(item.last) }.join("&") # Put key value pairs into http > GET format > ) > > > print "\n\nRequest:\n\n" > print url > > xml = REXML::Document.new( Net::HTTP.get(url) ) > > print "\n\nResponse:\n\n" > > xml.write > > > Any help would be greatly appreciated .... > > Cheers Andy > > There are lots of ways to get data to and from an Access database, depending on whether the Access database is on the same machine as the Ruby script and whether the Ruby script is running on a Windows box or not. The simplest case would be the database and Ruby script co-resident on a Windows box. Then it can be done either with the OLE interface or ODBC -- ODBC is preferable since it's more portable. If you need the data from the Access database for a Ruby script running on another box, the simplest thing is probably to write a small server using distributed Ruby on the Windows box and access it over the network. But there are other ways to skin the cat, ranging from an open source package called "mdbtools" that reads and writes Access files (http://mdbtools.sourceforge.net/) to more complicated things like "unixODBC".