[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

2 key user questions on Ruby-SQL

nkb

10/11/2004 2:10:00 PM

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.


2 Answers

Michael Neumann

10/12/2004 5:05:00 AM

0

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.d...
http://ruby-dbi.rub...

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


Joey Gibson

10/12/2004 11:58:00 AM

0

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.joeygibso...
http://www.joeygibso.../life/Wisdom.html
Atlanta Ruby User Group http://www....