2 key user questions on Ruby-SQL

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.

nkb wrote:

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

Michael Neumann wrote:

nkb wrote:

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.

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

Atlanta Ruby User Group http://www.AtlRUG.org