Method: Sequel::SqlAnywhere::DatabaseMethods#schema_parse_table

Defined in:
lib/sequel/adapters/shared/sqlanywhere.rb

#schema_parse_table(table, opts) ⇒ Object

[View source]

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 28

def schema_parse_table(table, opts)
  m = output_identifier_meth(opts[:dataset])
  im = input_identifier_meth(opts[:dataset])
  .
   from{sa_describe_query("select * from #{im.call(table)}").as(:a)}.
   join(Sequel[:syscolumn].as(:b), :table_id=>:base_table_id, :column_id=>:base_column_id).
   order{a[:column_number]}.
   map do |row|
    auto_increment = row.delete(:is_autoincrement)
    row[:auto_increment] = auto_increment == 1 || auto_increment == true
    row[:primary_key] = row.delete(:pkey) == 'Y'
    row[:allow_null] = row[:nulls_allowed].is_a?(Integer) ? row.delete(:nulls_allowed) == 1 : row.delete(:nulls_allowed)
    row[:db_type] = row.delete(:domain_name_with_size)
    row[:type] = if row[:db_type] =~ /numeric/i and (row[:scale].is_a?(Integer) ? row[:scale] == 0 : !row[:scale])
      :integer
    else
      schema_column_type(row[:db_type])
    end
    row[:max_length] = row[:width] if row[:type] == :string
    [m.call(row.delete(:name)), row]
  end
end