I want script save results into .csv or .txt file. My script must perform select into mssql database and send all strings from this request on email. My code:
require 'tiny_tds'
require 'csv'
@db_host = 'myserver.com'
@db_user = 'mylogin'
@db_pass = 'mypassword'
client = TinyTds::Client.new(:host => @db_host, :username => @db_user, :password => @db_pass)
results = client.execute(" SELECT * FROM mydatabase ")
results.each do |row|
p $rows = row.to_a
p h = $rows
CSV.open("data.csv", "wb") {|csv| h.to_a.each {|elem| csv << elem} }
end
My problem:
The generated csv file contains only the first line of my request. How can I write to a file all the strings of my request?