Using Ruby to get data from an Access Database

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

-- 
Posted via http://www.ruby-forum.com/.

0
arobbo61 (5)
6/4/2007 12:20:01 PM
comp.lang.ruby 48906 articles. 0 followers. Post Follow

3 Replies
258 Views

Similar Articles

[PageSpeed] 50
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".

0
znmeb (1667)
6/4/2007 12:57:06 PM
> 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.
> 

The script would be running from the same machine as the database.  I've 
used ADO before with Access Databases so i'd probably stick with what I 
know, bit stuck as to how I'd get the right syntax for Ruby, can't find 
exactly what i'm looking for out there on the web.....

Dim adoCon
Dim rsHouse
Dim strSQL
Set adoCon = Server.CreateObject("ADODB.Connection")
Set rsHouse = Server.CreateObject("ADODB.Recordset")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & 
Server.MapPath("Rent_Management_System_V2.mdb")
strSQL = "Select * From House"
rsHouse.Open strSQl, adoCon

Any idea how this sort of thing would work with Ruby (or where I could 
go to find out)

Many thanks for your help

Andy

-- 
Posted via http://www.ruby-forum.com/.

0
arobbo61 (5)
6/4/2007 6:04:11 PM
On 6/4/07, Andy Robbo <arobbo61@hotmail.com> wrote:
>
> I've used ADO before with Access Databases so i'd probably stick with
> what I know, bit stuck as to how I'd get the right syntax for Ruby,

The win32ole library is your friend. This should work (almost direct
copy of VBS code):

require 'win32ole'
ado_con = WIN32OLE.new('adodb.connection')
rs_house = WIN32OLE.new('adodb.recordset')
ado_con.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" +
	base_dir   = File.dirname(__FILE__) + "Rent_Management_System_V2.mdb"
str_sql = "Select * From House"
rs_house.open( str_sql, ado_con )

0
6/4/2007 11:25:26 PM
Reply:
Similar artilces about - Using Ruby to get data from an Access Database:

Use of cluster
Hi I am not familar with the use of cluster,. See my attahed in verion 7.1 How am I going to manipulate the contols or indicators, I supposed only property node can work, isn't it? &nbsp; Clement cluster1.vi: http://forums.ni.com/attachments/ni/170/177767/1/cluster1.vi If you want to change the values of the cluster elements on the front panel, then you can either write to the Value property of the cluster (or the Value property of the individual cluster elements), write to a local variable of the cluster, or write to the indicator terminal (in the case of a cluster indicator).&...

Having Trouble with File I/O (win32 API) -- Using NASM and ALINK
I'm not sure what I am doing wrong. I run the exe, and a file is not created. I'm still trying to figure out how to debug this thing in windows. I assembled the below code with: nasm -f obj createfile.asm alink -oPE -subsys con createfile.obj Here's my source code: import CreateFileA kernel32.dll import ExitProcess kernel32.dll import CloseHandle kernel32.dll import WriteFile kernel32.dll extern CreateFileA extern ExitProcess extern CloseHandle extern WriteFile %include "win32n.inc" ; downloaded at rs1.szif.hu/~tomcat/win32 -- contains definitions for win32 par...

Question about using split
All I have a string which I want to split on the characters "SA", simple enough, I also want to (in the same expression) split on "sa" just to catch any lowercase characters, however I would like the characters SA/sa to remain in the array after the split, it's simple enough to append it back on, but it is a little clumsy and has caused some problems. Can anyone suggest a solution? PT In article <binuh4$bf0j0$1@ID-116287.news.uni-berlin.de>, Max Adams <rubberducky703@hotmail.com> wrote: : All I have a string which I want to split on the characters ...

how to get free discussion on my website ?
http://support.forumgogo.com More powerful than the phpbb This is a great site that is completely free, and can make some cool forums, here's an example of one, you can make your own topic, polls, and replies etc, and you can have an accout for every member. This next link is an example of a forum made from invisionfree. http://support.forumgogo.com ann wrote: > http://support.forumgogo.com More powerful than the phpbb > This is a great site that is completely free, and can make some cool > forums, here's an example of one, you can make your own topic, polls, > an...

updated "Using Python From IDL" ebook
All, I just added a chapter to the ebook on creating tones from IDL using a Pyth= on package called pyaudio. I also found a free plugin for Visual Studio th= at gives you a good IDE for python. (http://pytools.codeplex.com/) This not only gives a nice DE it also allows us to do interactive debugging= with Python from IDL. Of course, I explain it all in the book which can b= e purchased here (http://www.rlkling.com/using-python-from-idl.htm) for $5.= 00 US. If you have already purchased the book you are supposed to get free= updates. Thanks! Ronn Kling On Wednesday, Jul...

How to find free disk space using C
Hi, I am trying to incorporate a code snippet which would calculate the free disk space of any drive passed to it as argument but presently stuck with it. Can anyone help me out with sample code? I have already tried with the follwoing: typedef BOOL (WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER); void main (int argc, char **argv) { BOOL fResult; char *pszDrive = NULL, szDrive[4]; DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters; ...

When to use Tcl_DecrRefCount() and when not to?
I am using SWIG to interface a C library (libgpgme) that uses callbacks to Tcl and have written some C code to implement Tcl coded callbacks. The SWIG interface code looks like this: %{ /* C Structure containing the Tcl_Interp and the script prefix. */ typedef struct { Tcl_Interp *theinterp; Tcl_Obj *thecommand; } tcl_callback_hook; /* Actual C callback, that evals a Tcl script made from the stored script prefix, with the callback parameters uid_hint, passphrase_info, and prev_was_bad lappended. The result of this evaluation is written to the file descr...

using coherence function
Hi All, I'm having some trouble understanding how to use the "mscohere" command to get my coherence function. I have a bunch of force and corresponding acceleration signals which I have measured at one point in my test structure. I know I have to use the average of all of these in the coherence function. From the "mscohere" command in matlab, I see that the inputs are x and y, which in my case would be force and acc. however this just allows me to look at one measurement, not the average of all the measurements. If I were to just use 1 measurement, the coherence funct...

Data store block problem during minor time steps
I have some problems with the behaviour of Simulink during minor time steps for continuos solvers. The problem is related with Data Store blocks. General structure of the problematic model is as such: A is the data store name Data Store Read Block of A->Switch-Case->Various Switch Case Action Subsystems(There are other read and write operations of data store blocks unrelated with A)->All output signals merged-> Output is written to Data Store Write Block of A All data store diagnostics are on, so i can ensure the order of read and write procedure for Data Store Block A. What...

using setTimeout when using prototype
I have an object, and I define the following: var processForm=new Object(); processForm=function(inservleturl) { this.inservleturl = inservleturl; this.submitForm(); } processForm.prototype.submitForm2=function() { } processForm.prototype.submitForm=function() { setTimeout("submitStep2()", 20); } How can the submitForm function's setTimeout call submitStep2? Thank you. processForm=function(inservleturl) { this.inservleturl = inservleturl; this.submitForm(); } processForm.prototype.submitForm2=function() { ...

Getting next val in a sequence when the table is empty
Hi All, I want to get the next val in a sequence and then use it to do an insert. I can do this to get the next val: select NEXTVAL for EAIDATA.SUPPLIER_TP_SEQ_NO from EAIDATA.SUPPLIER_TP; But if EAIDATA.SUPPLIER_TP is empty, this fails - "0 records selected". How can I get the next value of a sequence without referring to a table? Kind regards, Rob :) Values NEXTVAL for EAIDATA.SUPPLIER_TP_SEQ_NO p175 wrote: > Values NEXTVAL for EAIDATA.SUPPLIER_TP_SEQ_NO SELECT NEXTVAL FOR EAIDATA.SUPPLIER_TP_SEQ_NO FROM sysibm.sysdummy1 This table always has ...

Need some help with pre-processign functions in C using Doxygen ...
Hi, I'm currently documenting source code in C and would like to skip some functions that don't need to be documented. The syntax that I'm using is defined below. #ifndef SKIP /* Code to be skipped */ #endif SKIP Where SKIP= Predifined Tag Name I'd like to know if anyone on this list has been using Doxygen to pre-process code fragments. In case you do pre-process the code, I'd appreciate your inputs with an alternative method to ignore code fragments. The problem is that Doxygen compiles it but the C compiler reads the /* Code to be skipped */ as comments !!! Plea...

OT: What filtering does Hotmail use?
This is completely off-topic, but I hope someone here knows the answer.=20 When talking to one of my sisters today I asked about an invitation I = sent her last week to her hotmail.com address. She said that she did not = receive it. One of my other sisters did not respond to the same email and it = turns out that she also uses hotmail.com. Another friend who uses hotmail did = not respond to a recent email as I expected them to. I created my own hotmail account tonight and sent an email to it from my domain more than two hours ago, that email has not yet arrived in my = hotmail account. My ...

How can i read data from more than one channel at the same time?
Hello I'm trying to get data&nbsp;from two channels simultaneously using the example Acq &amp; Cont Graph, to save it in a file excel.&nbsp;How&nbsp;can i read the two channels at once and displayed on the graphic? &nbsp; Thanks &nbsp; PS I am using Labview 6.0.1 Cont Acq&Graph (buffered)prueba.vi: http://forums.ni.com/attachments/ni/170/332868/1/Cont Acq&Graph (buffered)prueba.vi Just put mulitple channels in your 'channel(0)' control. If each channel will have the same input limits,&nbsp;you can specify, for example, 0:2 or 0,2,3. If you wan...

Re: Scope of macro variable using "call symput" #12
Perahps the way SAS calculates the scope of a macro variable created by CALL SYMPUT violates the principle of least astonishment. It might make more sense for CALL SYMPUT to create a new macro-level symbol table, rather than searching upwards to find one that already exists. Or maybe not. The SYMPUTX way, which lets you specify the scope, is slightly more work to use but can create results that don't require thought or knowledge of context. On Mon, 24 Mar 2008 09:48:11 -0400, "Chang Chung" <chang_y_chung@HOTMAIL.COM> said: > On Sun, 23 Mar 2008 02:05:16 -0700, Rola...

What Rbls are you using
Hello I would like to know which DNS RBLs everyone is using and what do you find most effective. I just started using dsn.rfc-ignorant.org and list.dsbl.org. So far no complaints. I have also been using bl.spamcop.net and sbl.spamhaus.org for awhile. They're ok however some get through. Thanks, J -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Fri, 13 Jan 2006 20:39:21 -0800, jpecki wrote: > Hello > I would like to know which DNS RBLs everyone is using and what do you > find most effective. I just started using dsn.rfc-ignorant.org and > list.dsbl.org. So far no compl...

US-Nationwide: Programmer, Mumps, VA Database VISTA; P/T (45322132429)
US-Nationwide: Programmer, Mumps, VA Database VISTA; P/T (45322132429) ====================================================================== Position: Programmer Reference: WMM00013 Location: Nationwide Duration: P/T Skills: Mumps VA Database VISTA Scope: Develop data extracts from VA database in MUMPS into flat ASCII files. Partime work, remotely done for nationwide coverage. Please send your current resume in confidence to "Wolf M. Metzner" <WMetzner@EuroSoft-Inc.Com> ...

input buffer overflow...data flow shuts off
I'm not sure if this is the proper forum for my problem, if it isn't would someone steer me in the correct direction? I have live stock market data coming in through an internet connection. Then into a charting software called Tradestation 2000i. This software has a module called Global Server that collects and saves the data. During market hours, sometimes 10-20 times per day, Global Server will stop collecting data even though the data is still coming in from the modem(via a software called Dynastore...which makes the data available to the Global Server). I can see the d...

voive recognition using matlab
good day, i would like to ask a program/code using MatLab for my project voice recognition for my subject... thank you very much....... ...

Is it possible to use an Object as value for a <html:select> (i'm using struts)
Hi, I'm having trouble with struts, well actually i don't know if the problem is struts or instead i'm assuming html to be capable of something it's not. I have a ValidatorForm, say VF and one of it's attibutes called organismo is an object of type Ob1, Ob1 being a bean definded in another file, Ob1 has just two attributes a and b and their respective setters and getters. I want that attribute to be filled with the value of a <html:select>, depending on what the user chooses from the options available. To get the options i'm using the next: <html:select pro...

ANN: Guis-1.3 a GTK2 widget server (scriptable in Python & Ruby)
Dear All, It is my pleasure to announce the release 1.3 of Guis, which is a programmable graphical user interface widget "server". Guis communicate with a (one) client application thru textual communication channels; input requests (from application to guis) are Python (or Ruby) instructions (using the PyGTK binding of GTK2 to Python or the ruby-gnome2 binding of GTK2 to Ruby) and output replies (or events) are arbitrary textual lines from Guis to application (sent by Python or Ruby script). There is a possibility to trace the exchanges between application & guis (in a graphic...

using ethereal
I have Fedora Core 3. When I did my install I did not install X windows or any GUI. I also did not install ethereal. Now I would like to use ethereal, so I installed Xwindows and KDE. I used yum install ethereal and it showed it installed it. But I cannot figure out how to run ethereal. I cannot find any binary to run. I found one post that said I should have an ethereal file under /usr/X11R6/bin but I don't. thank you jb Jason Benway wrote: > I have Fedora Core 3. When I did my install I did not install X windows or > any GUI. I also did not install ethereal. >...

How to get Service Ticket when we have TGT using java.
Hi, We are implementing WS Kerberos authentication using java. We went throught the sample providied @ http://services.iic.ac.in/kbase/docs/java2/guide/security/jgss/tutorials/AcnOnly.html We have setup Fedora Core 3 and krb5-server and configured. When we run the sample code it gets authenticated successfully, but my question is : How to get Kerberos Service Ticket after logging in succesfully and getting the TGT using java 1.4.2_04 and Fedora Core 3 [krb5-server] LoginContext lc ... ... lc.login(); after this step, we can say lc.getSubject() which contains the kerberos ticket, now usin...

Using a DLL from a Lotusscript agent
Hello, I have a LotusScript web agent that uses a external DLL. The agent works fine, but I have a performance problem. The DLL has 2 functions: initialize and translate. The first one performs some initialization tasks and the second one translates a word from a language to another. The problem is that the initialization task takes some time and it seems once the script ends, the DLL loses its iniatilization and I have to initialize it again, slowing down the whole process. Is there any way to keep the dll initialized once the "initialize" function is called and the ...

Using Oracle 8.1.7 OCI JDBC Driver WIth Oracle 9i Database
Has anyone had any problems using the 8.1.7 OCI JDBC driver with a 9i database? Oracle states they are compatible at the following URL: http://otn.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#_1_ "Matt" <mdavey4@csc.com> wrote in message news:f2892d3a.0307241304.6295d05c@posting.google.com... > Has anyone had any problems using the 8.1.7 OCI JDBC driver with a 9i database? > > Oracle states they are compatible at the following URL: > http://otn.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#_1_ Any reason not to trust that statement? If ...