2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/sqlserver_schema_reflector/reflector.rb', line 2
def self.run(out, options)
client = TinyTds::Client.new(options)
tables = client.execute(
"SELECT [TABLE_SCHEMA] as [schema],
[TABLE_NAME] as [name]
FROM information_schema.tables"
).map {|r| r.symbolize_keys }
tables.each do |t|
begin
cmd = "sp_help " + "'#{t[:schema]}.#{t[:name]}'"
table_hash = client.execute(cmd).map { |result| result }
table = SqlServerSchemaReflector::TableReflection.new(table_hash, t)
out.write table.create_sql + "\n"
rescue
e = "/*\n"
e << "Unable to generate create statement for table: #{t}\n"
e << $!.message
e << "*/\n"
out.write e
$stderr.print e
end
end
end
|