ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: Executing SQL Query through ruby using winole32
by Jac Clapp other posts by this author
May 8 2008 1:44PM messages near this date
Re: Executing SQL Query through ruby using winole32 | initial stages of scripting
I did a little research on SQL-DMO and came up with this:

output = database.ExecuteWithResults('Select * from dbo.tLNPOrderStatus')

puts "There are #{output.Rows} records."

puts

# this iterates through the first column of each record returned
# if you want a different column, change the second 1 to a different number
output.Rows.times { |row| puts output.GetColumnString(row + 1, 1) }

Jac


On Thu, May 8, 2008 at 7:30 AM, Anukul Singhal <anukul.singhal@[...].com>  wrote:
>  Hi,
> 
>  I used the following code to connect to SQL Server:
> 
>  require 'win32ole'
>  server = WIN32OLE.new('SQLDMO.SQLServer')
>  server.connect('113.212.133.232,1423','username','password')
>  database = server.Databases('DIT_Photon_1007')
>  for table in database.Tables
>    puts table.Name
>  end
> 
>  When i execute this, it successfully gives me all the table names for
>  the DB ('DIT_Photon_1007')
> 
>  But I want to execute a query, and for that I am using this code:
> 
>  output = database.execute('Select * from dbo.tLNPOrderStatus')
>  puts output
> 
>  But I am getting the error like "method missing"
>  (Execute)(WIN32OLERuntimeError)
> 
>  Can anybody help me which method would be used to execute a query in
>  win32ole?
>  I even tried database.query('....'), server.query('....') and
>  server.execute('....') but no luck.
> 
>  Thanks,
>  Anukul
>  --
>  Posted via http://www.ruby-forum.com/.
> 
> 
Thread:
Anukul Singhal
Masaki Suketa
Michael Linfield
Anukul Singhal
Michael Linfield
Jac Clapp

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved