Exporting data from SQL Server Express to CSV (need quoting and escaping)

后端 未结 10 1959
执笔经年
执笔经年 2020-12-05 04:16

I\'ve spent 2 days trying to export a 75,000 row table containing a large text field of user input data from a SQL server installation. This data contains every plain ascii

10条回答
  •  忘掉有多难
    2020-12-05 04:59

    Here's the essence of a script I use to do just this:

    require 'rubygems'
    require 'active_record'
    require 'tiny_tds'
    require 'activerecord-sqlserver-adapter'
    require 'acts_as_reportable'
    require 'ruport'
    
    ActiveRecord::Base.logger = Logger.new("log/debug.log")
    ActiveRecord::Base.establish_connection(
      :adapter    => 'sqlserver',
      :mode       => 'dblib',
      :dataserver => 'servername',
      :username   => 'username',
      :password   => 'password',
      :timeout    => '60000'
    )
    
    class Table1 < ActiveRecord::Base
      set_table_name 'table_name'
      set_primary_key 'table_id'
      acts_as_reportable
    end
    
    Table1.report_table(:all).save_as("finished/table1.csv")
    

    Hope it helps!

提交回复
热议问题