2 key user questions on Ruby-SQL

N

nkb

Hi.
1. Is it possible to access SQL data for simple query like Select,
Update etc. via Ruby?
2. Most SQL databases require user authentication. I'm on SQL 2000. I am
able to access SQL via my vb script since microsoft is able to simply
use my windows NT login as the authentication to the SQL. Can this be
done for Ruby? I dont wish to explicitly enter my password since this
script needs to run background.

Thanks.
 
M

Michael Neumann

nkb said:
Hi.
1. Is it possible to access SQL data for simple query like Select,
Update etc. via Ruby?
2. Most SQL databases require user authentication. I'm on SQL 2000. I am
able to access SQL via my vb script since microsoft is able to simply
use my windows NT login as the authentication to the SQL. Can this be
done for Ruby? I dont wish to explicitly enter my password since this
script needs to run background.

yes and yes.

Try either Ruby/ODBC or the ODBC database driver of Ruby/DBI.

http://www.ch-werner.de/rubyodbc
http://ruby-dbi.rubyforge.org

In Ruby/DBI it could look like this:

require 'dbi'
DSN = 'fill in' # the ODBC datasource name
DBI.connect("DBI:ODBC:#{DSN}", "user", "passwd") do |dbh|
dbh.execute("SELECT * FROM table") do |sth|

# iterate over each row of the result set
sth.each do |row|
p row
end

end
end


Hope this helps.

Regards,

Michael
 
J

Joey Gibson

Michael said:
yes and yes.

Try either Ruby/ODBC or the ODBC database driver of Ruby/DBI.

If your script is going to run on Windows, you can install the ADO.rb
file that comes with the source distro of Ruby DBI and use ADO. I have
recently gotten this working, and I like it better than ODBC. It let's
you use those ugly SQL Server DSNs that you've gotten used to, so you
can easily select the initial catalog, etc.


--
She drove a Plymouth Satellite
Faster than the Speed of Light...

http://www.joeygibson.com/blog
http://www.joeygibson.com/blog/life/Wisdom.html
Atlanta Ruby User Group http://www.AtlRUG.org
 

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
474,159
Messages
2,570,881
Members
47,418
Latest member
NoellaXku

Latest Threads

Top