MS Access

S

Steve

I'm considering learning Ruby. I have no programming experience yet. I was
wondering if it's possibly to write applications in Ruby that can use and
change the data in my MS Access files.

Thanks for your help.

Steve
 
P

Phlip

Steve said:
I'm considering learning Ruby. I have no programming experience yet. I
was wondering if it's possibly to write applications in Ruby that can use
and change the data in my MS Access files.

Absolutely. Database are designed to access a wide warehouse of data through
a narrow interface. Narrow interfaces are easy to port to new languages.
Ruby will see tables of data, just like Visual Basic or C++ will.

Google Ruby DBI DAO or Ruby DBI ADO.
 
B

Brock Weaver

------=_Part_17908_22967416.1126809139074
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Steve,

Welcome, fellow rubyist!

It is great that you are choosing ruby as your language to learn=20
programming. It is a very powerful, robust language. But like the Uncle in=
=20
Spiderman says, "With great power comes great responsibility". This means=
=20
you may have to take a little longer to learn some things in ruby than you=
=20
would in other languages. But in the long run, it will be *well* worth it.

Just be patient, motivated, and stay optimistic. Post questions to this=20
list, no matter how "easy" you may think they are -- everybody here is very=
=20
supportive and prompt.

Good luck, and stick with it man!

=20
Steve wrote:
=20 =20
=20
Absolutely. Database are designed to access a wide warehouse of data=20
through
a narrow interface. Narrow interfaces are easy to port to new languages.
Ruby will see tables of data, just like Visual Basic or C++ will.
=20
Google Ruby DBI DAO or Ruby DBI ADO.
=20
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
=20
=20
=20
=20


--=20
Brock Weaver
(e-mail address removed)

/* you are not expected to understand this */

------=_Part_17908_22967416.1126809139074--
 
S

Sean Armstrong

------=_Part_11571_32159117.1126818866583
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

=20
Steve wrote:
=20 =20
=20
Absolutely. Database are designed to access a wide warehouse of data=20
through
a narrow interface. Narrow interfaces are easy to port to new languages.
Ruby will see tables of data, just like Visual Basic or C++ will.
=20
=20
Does anyone have any good code examples? The hardest thing for people like=
=20
Steve, and myself, is that the documentation for these items are very=20
limited and not very revealing to newbies. For instance, I could not find a=
=20
single code example for connecting to a SQL database, let alone Access, in=
=20
the Pickaxe book. So if anyone has any good code examples for manipulating=
=20
data in Access or MySQL, I would like to see it here.

Thanks.
SA

--=20
"I can do everything on my Mac that I could do on a PC."
-- Me

------=_Part_11571_32159117.1126818866583--
 
S

Sascha Ebach

Sean said:
Does anyone have any good code examples? The hardest thing for people like
Steve, and myself, is that the documentation for these items are very
limited and not very revealing to newbies. For instance, I could not find a
single code example for connecting to a SQL database, let alone Access, in
the Pickaxe book. So if anyone has any good code examples for manipulating
data in Access or MySQL, I would like to see it here.

Usually you can ask the great oracle:

http://www.google.com/search?q=ruby+mysql

This revealed:

Using the Ruby MySQL Module
Article describes how to install the Tomita Masahiro's MySQL module and
use it to write MySQL-based Ruby scripts. By Paul DuBois.
www.kitebird.com/articles/ruby-mysql.html - 32k - Cached - Similar pages

I didn't try "ruby access". I will leave that to you. But you might want
to search for "ruby odbc" or "ruby ado" or the like. I am sure you are
going to find something.
 
S

Simon Kröger

Sean said:
Does anyone have any good code examples? The hardest thing for people like
Steve, and myself, is that the documentation for these items are very
limited and not very revealing to newbies. For instance, I could not find a
single code example for connecting to a SQL database, let alone Access, in
the Pickaxe book. So if anyone has any good code examples for manipulating
data in Access or MySQL, I would like to see it here.

Thanks.
SA

Ok, this isn't 'good' but short and shows that it is realy easy to
connect to ms access.

-------------------------------------------------------------------
require 'dbi'

DBI.connect("DBI:ODBC:driver=Microsoft Access Driver (*.mdb);"+
"dbq=C:/path/to/my/db.mdb") do |dbh|

dbh.select_all('select * from myTable') {|row| p row}
end
-------------------------------------------------------------------

I guess it's so damm easy, nobody who figured it out writes HOWTO's.

cheers

Simon
 
D

Dave Burt

Steve said:
I'm considering learning Ruby. I have no programming experience yet. I
was wondering if it's possibly to write applications in Ruby that can
use
and change the data in my MS Access files.
Absolutely. Database are designed to access a wide warehouse of data
through
a narrow interface. Narrow interfaces are easy to port to new languages.
Ruby will see tables of data, just like Visual Basic or C++ will.

Sean said:
Does anyone have any good code examples? The hardest thing for people like
Steve, and myself, is that the documentation for these items are very
limited and not very revealing to newbies. For instance, I could not find
a
single code example for connecting to a SQL database, let alone Access, in
the Pickaxe book. So if anyone has any good code examples for manipulating
data in Access or MySQL, I would like to see it here.

If you're not only concerned about the database, or even if you'd like to
use ADO (or DAO) through Access to manage it, I think a better option,
that's about as easy as writing VBA code (but with all the advantages of
Ruby) is using WIN32OLE and Access' COM automation. See
http://www.rubygarden.org/ruby?ScriptingExcel (I thought there was a
ScriptingAccess, but I can't see it...) It's mostly pretty obvious how to
write Ruby code from the VB docs included with Access.

Cheers,
Dave
 
S

Sean Armstrong

------=_Part_11847_26258995.1126821623211
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Thank You.
:)
SA

Does anyone have any good code examples? The hardest thing for people=
=20
like
Steve, and myself, is that the documentation for these items are very
limited and not very revealing to newbies. For instance, I could not=20 find a
single code example for connecting to a SQL database, let alone Access,=
=20
in
the Pickaxe book. So if anyone has any good code examples for=20 manipulating
data in Access or MySQL, I would like to see it here.
=20
Usually you can ask the great oracle:
=20
http://www.google.com/search?q=3Druby+mysql
=20
This revealed:
=20
Using the Ruby MySQL Module
Article describes how to install the Tomita Masahiro's MySQL module and
use it to write MySQL-based Ruby scripts. By Paul DuBois.
www.kitebird.com/articles/ruby-mysql.html<http://www.kitebird.com/article=[/QUOTE]
s/ruby-mysql.html>- 32k - Cached - Similar pages
=20
I didn't try "ruby access". I will leave that to you. But you might want
to search for "ruby odbc" or "ruby ado" or the like. I am sure you are
going to find something.
=20
=20


--=20
"I can do everything on my Mac that I could do on a PC."
-- Me

------=_Part_11847_26258995.1126821623211--
 
S

Sean Armstrong

------=_Part_11967_17574448.1126822685127
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Does anyone know how to install the Ruby MySQL module on a Windows platform=
=20
I installed MySQL for Windows and, although I have cygwin installed, the=20
library files required for the module are not present.
Thanks:)
SA

Does anyone have any good code examples? The hardest thing for people=
=20
like
Steve, and myself, is that the documentation for these items are very
limited and not very revealing to newbies. For instance, I could not=20 find a
single code example for connecting to a SQL database, let alone Access,=
=20
in
the Pickaxe book. So if anyone has any good code examples for=20 manipulating
data in Access or MySQL, I would like to see it here.
=20
Usually you can ask the great oracle:
=20
http://www.google.com/search?q=3Druby+mysql
=20
This revealed:
=20
Using the Ruby MySQL Module
Article describes how to install the Tomita Masahiro's MySQL module and
use it to write MySQL-based Ruby scripts. By Paul DuBois.
www.kitebird.com/articles/ruby-mysql.html<http://www.kitebird.com/article=[/QUOTE]
s/ruby-mysql.html>- 32k - Cached - Similar pages
=20
I didn't try "ruby access". I will leave that to you. But you might want
to search for "ruby odbc" or "ruby ado" or the like. I am sure you are
going to find something.
=20
=20


--=20
"I can do everything on my Mac that I could do on a PC."
-- Me

------=_Part_11967_17574448.1126822685127--
 
P

Phlip

Dave said:
If you're not only concerned about the database, or even if you'd like to
use ADO (or DAO) through Access to manage it, I think a better option,
that's about as easy as writing VBA code (but with all the advantages of
Ruby) is using WIN32OLE and Access' COM automation.

Driving Access through COM, essentially operating its user interface to read
and write your data, is remarkably similar to laying your tongue on a
baseball bat, pounding a nail through it, and then hitting a home run with
it.

A good way to use COM the way it was intended is Ruby->WIN32OLE->ADO->any
data. That will come with Jet ("Access") drivers out-of-the-box.
 
S

Sean Armstrong

------=_Part_12135_4083502.1126825638560
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Let me make sure I got this right:

1. Download MySQL source
2. Compile it under Cygwin with the flags you mentioned
3. Remove the bin files?
4. Use the lib file generated from the compilation
5. This will work with the MySQL binarie install for Windows?

Thanks:)

Sean A.

=20
Sean,
I needed to compile/install mysql (running ./configure
--without-server) from source to get the required development
libraries under Cygwin. (then I moved the newly-created client
binaries out of the way so I could use the Win32-native mysql
binaries.) After that, it worked like a charm. *Do not compile the
Cygwin-ized mysql client with "--with-openssl"* I don't know why, but
the gem refused to install if I did. Good luck, and let me know if you
run into any issues. Overall, developing on Cygwin for Ruby/Rails is
quite nice.
=20
=20
=20
--=20
"I can do everything on my Mac that I could do on a PC."
-- Me

------=_Part_12135_4083502.1126825638560--
 
G

Gavin Kistner

Does anyone have any good code examples? The hardest thing for
people like
Steve, and myself, is that the documentation for these items are very
limited and not very revealing to newbies. For instance, I could
not find a
single code example for connecting to a SQL database, let alone
Access, in
the Pickaxe book. So if anyone has any good code examples for
manipulating
data in Access or MySQL, I would like to see it here.

Following is a sanitized example of code I use at work to connect
both to an intranet-local SQL server, and also to a remote SQL server
on our web host over the 'net.

For both, I created a system ODBC DSN,which is what 'VerneCSR' and
'LiveServer' are.

DB_LOGIN = $test_db_flag ? [ 'dbi:ODBC:VerneCSR' ] :
[ 'dbi:ODBC:LiveServer', 'username_removed', 'password_removed' ]

puts "Working on the #{ $test_db_flag ? 'TEST' : 'LIVE' } database"

begin
require 'dbi'
dbh = DBI.connect( *DB_LOGIN )


# Ensure that the category exists, and get the ID
CATEGORY_NAME = 'Latest Behaviors'
row = dbh.select_one( 'SELECT acID FROM tblAssCategory WHERE
acName=?', CATEGORY_NAME )
if row
SCRIPT_REFERENCE_CATEGORY_ID = row[ 0 ]
else
dbh.do( 'INSERT INTO tblAssCategory (acName) VALUES (?)',
CATEGORY_NAME )
SCRIPT_REFERENCE_CATEGORY_ID = dbh.select_one( 'SELECT CAST
(@@IDENTITY AS int)' )[ 0 ]
end


#Prepare some SQL statements for speedier re-use
get_article = dbh.prepare( <<-ENDSQL
SELECT aID, aSummary, aBody, date_updated
FROM tblAssItems
WHERE acID=#{SCRIPT_REFERENCE_CATEGORY_ID} AND download_files=?
AND aTitle=?
ENDSQL
)
add_article = dbh.prepare( <<-ENDSQL
INSERT INTO tblAssItems

(author,aTitle,aSummary,aBody,download_files,acID,time_to_complete,diffi
culty,thumbnail,status)
VALUES (?,?,?,?,?,#{SCRIPT_REFERENCE_CATEGORY_ID},'5
Minutes','(Reference)','#{THUMBNAIL_URL}','public')
ENDSQL
)
update_article = dbh.prepare( <<-ENDSQL
UPDATE tblAssItems
SET
author=?,
aSummary=?,
aBody=?,
date_updated=#{Time.new.to_sql}
WHERE aID=?
ENDSQL
)


require 'erb'
Behavior.all.each_with_index{ |bvs,i|
#Check to see if the item should be added or updated in the DB
#(Don't just shove the current content, because that would
invalidate 'date_updated')
existing_article = get_article.execute( download_path, title )
rows = get_article.fetch_all

changed_db_flag = false

if rows.empty?
#Couldn't find an existing article for the behavior, time to
add a new one
puts "Adding article entry '#{title}'" if $verbose_flag
body.sub!( '%%CURRENT_TIME%%', Time.new.to_pretty )
add_article.execute( author, title, summary, body,
download_path )
changed_db_flag = true
$add_count += 1
else
existing_info = rows[ 0 ]
old_body = body.sub( '%%CURRENT_TIME%%', existing_info
[ 'date_updated' ].to_time.to_pretty )
if ( existing_info[ 'aSummary' ] != summary ) ||
( existing_info[ 'aBody' ] != old_body )
#Time to update the entry
body.sub!( '%%CURRENT_TIME%%', Time.new.to_pretty )
puts "Updating article entry '#{title}'" if $verbose_flag
update_article.execute( author, summary, body, existing_info
[ "aID" ] )
changed_db_flag = true
$update_count += 1
end
end
}

rescue DBI::DatabaseError => e
puts "An error occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"

ensure
#close out statements
get_article.finish if get_article
add_article.finish if add_article
update_article.finish if update_article

#unplug from the database
dbh.disconnect if dbh
end #db safety
 
D

Dave Burt

Phlip spat:
Driving Access through COM, essentially operating its user interface to
read and write your data, is remarkably similar to laying your tongue on a
baseball bat, pounding a nail through it, and then hitting a home run with
it.

A good way to use COM the way it was intended is Ruby->WIN32OLE->ADO->any
data. That will come with Jet ("Access") drivers out-of-the-box.

You're right if all you care about is a nicely designed database. I haven't
seen too many of those; far more common in my experience is a mess of
junk-ridden tables with some forms that try to make them make some kind of
sense. It's like using Watir to drive IE because your web app is chock-full
of javascript and you're not just playing with a nice bit of XHTML.

Although I guess it's still not all that dissimilar to your baseball
analogy.

Cheers,
Dave
 
S

Sean Armstrong

------=_Part_15724_17408133.1126886100123
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

It still refuses to find the lib and include directories even if I use the=
=20
--with flags. Any other ideas


Thanks:)
SA

=20
Let me make sure I got this right:
=20
1. Download MySQL source
2. Compile it under Cygwin with the flags you mentioned
3. Remove the bin files?
4. Use the lib file generated from the compilation
5. This will work with the MySQL binarie install for Windows?
=20
Thanks:)
=20
Sean A.
=20

--
"I can do everything on my Mac that I could do on a PC."
-- Me
=20
=20


--=20
"I can do everything on my Mac that I could do on a PC."
-- Me

------=_Part_15724_17408133.1126886100123--
 
S

Sean Armstrong

------=_Part_19472_25956696.1126963512563
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Well you have got me the closest so far. I had to go back and manually=20
compile mysql-ruby with the --with-mysql-config flag because the gme did no=
t=20
fully install. I can now use require 'mysql' and get a true result. My new=
=20
problem deals with the way MySQL is installed on my windows box. I did not=
=20
install it as a server. I just installed it locally. I use the -h . flag to=
=20
connect to my MySQL installation. It is not an option to install it as a=20
server. So I am now currently unable to connect to mysql with the mysql=20
module because it will not accept "localhost" as teh server string and it=
=20
will not accept "." as the server string like everything else does. Any new=
=20
ideas?

Thanks:)

SA

=20
Sean,
I'm going to try to explain *exactly* what I did, and hopefully you'll
see something you forgot to do.
1. Download mysql-essential-4.1.14-win32.msi from mysql.org<http://mysql.= org>and install it.
2. Download mysql-4.1.13.tar.gz from mysql.org <http://mysql.org>
3. Extract the above, and run "./configure -C --without-server" (the
-C enables config caching, I use it because the ./configure script
runs very slowly under Cygwin. Optional, of course)
4. Run "make && make install"
5. Run "gem install mysql"
6. Go make cool rails apps!
=20
Jacob
=20
=20

--=20
"I can do everything on my Mac that I could do on a PC."
-- Me

------=_Part_19472_25956696.1126963512563--
 
L

Linus Sellberg

------=_Part_6163_25462405.1126964337914
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

=20
server. So I am now currently unable to connect to mysql with the mysql
module because it will not accept "localhost" as teh server string and it
will not accept "." as the server string like everything else does. Any= =20
new
ideas?
=20

127.0.0.1 <http://127.0.0.1> ?

------=_Part_6163_25462405.1126964337914--
 
S

Sean Armstrong

------=_Part_19529_32167546.1126965751135
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

This does not work since my version of mysql is not iinstalled as a server.

Thanks:)
SA

=20
=20
=20
127.0.0.1 <http://127.0.0.1> <http://127.0.0.1> ?
=20
=20


--=20
"I can do everything on my Mac that I could do on a PC."
-- Me

------=_Part_19529_32167546.1126965751135--
 
D

Dave Burt

Sean Armstrong:
Well you have got me the closest so far. I had to go back and manually
compile mysql-ruby with the --with-mysql-config flag because the gme did
not
...

Have you tried using MyODBC with Ruby-DBI via the ODBC DBD? It was mentioned
in another thread. I think you'd have to add an ODBC data source as an extra
step (rather than just specifying the host/user/database), but it should
work on Windows without having to compile anything against particular
versions, which seems to be where these things tend to fall over.

Cheers,
Dave
 

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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top