method
columns

v1.2.6 -
Show latest stable
-
0 notes -
Class: ActiveRecord::ConnectionAdapters::SQLServerAdapter
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
columns(table_name, name = nil)
public
Hide source
# File activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb, line 256 def columns(table_name, name = nil) return [] if table_name.blank? table_name = table_name.to_s if table_name.is_a?(Symbol) table_name = table_name.split('.')[-1] unless table_name.nil? table_name = table_name.gsub(/[\[\]]/, '') sql = %Q{ SELECT cols.COLUMN_NAME as ColName, cols.COLUMN_DEFAULT as DefaultValue, cols.NUMERIC_SCALE as numeric_scale, cols.NUMERIC_PRECISION as numeric_precision, cols.DATA_TYPE as ColType, cols.IS_NULLABLE As IsNullable, COL_LENGTH(cols.TABLE_NAME, cols.COLUMN_NAME) as Length, COLUMNPROPERTY(OBJECT_ID(cols.TABLE_NAME), cols.COLUMN_NAME, 'IsIdentity') as IsIdentity, cols.NUMERIC_SCALE as Scale FROM INFORMATION_SCHEMA.COLUMNS cols WHERE cols.TABLE_NAME = '#{table_name}' } # Comment out if you want to have the Columns select statment logged. # Personally, I think it adds unnecessary bloat to the log. # If you do comment it out, make sure to un-comment the "result" line that follows result = log(sql, name) { @connection.select_all(sql) } #result = @connection.select_all(sql) columns = [] result.each do |field| default = field[:DefaultValue].to_s.gsub!(/[()\']/,"") =~ /null/ ? nil : field[:DefaultValue] if field[:ColType] =~ /numeric|decimal/i type = "#{field[:ColType]}(#{field[:numeric_precision]},#{field[:numeric_scale]})" else type = "#{field[:ColType]}(#{field[:Length]})" end is_identity = field[:IsIdentity] == 1 is_nullable = field[:IsNullable] == 'YES' columns << SQLServerColumn.new(field[:ColName], default, type, is_identity, is_nullable) end columns end