Ruby on Rails: Convert Table into CSV

Ruby scripts example about how to read table data and convert it into CSV

require 'odbc' require 'dbi' filename = "./file.csv" writeFile = File.open(filename,"w") dbh = DBI.connect('DBI:ODBC:data_source_name', 'username', 'password') sth = dbh.prepare("SELECT * FROM table WITH UR") sth.execute writeFile.puts sth.column_names.join(" ; ") #puts names on the top of each row while row=sth.fetch do writeFile.puts row.join(" ; ") #puts lines from table end sth.finish dbh.disconnect writeFile.close

Love this source code? Please help us to spread it ^_^
 

Discuss

No discussion for this source code yet. Be the first to discuss about this code.

Submit Comment

Sorry, you have to login for joining the discussion

Click here to register or login using your facebook account