Method: Sequel::DB2::DatabaseMethods#schema_parse_table

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

#schema_parse_table(table, opts = OPTS) ⇒ Object

Use SYSIBM.SYSCOLUMNS to get the information on the tables.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sequel/adapters/shared/db2.rb', line 33

def schema_parse_table(table, opts = OPTS)
  m = output_identifier_meth(opts[:dataset])
  im = input_identifier_meth(opts[:dataset])
  .with_sql("SELECT * FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = #{literal(im.call(table))} ORDER BY COLNO").
    collect do |column| 
      column[:db_type] = column.delete(:typename)
      if column[:db_type] =~ /\A(VAR)?CHAR\z/
        column[:db_type] << "(#{column[:length]})"
      end
      if column[:db_type] == "DECIMAL"
        column[:db_type] << "(#{column[:longlength]},#{column[:scale]})"
      end
      column[:allow_null] = column.delete(:nulls) == 'Y'
      identity = column.delete(:identity) == 'Y'
      if column[:primary_key] = identity || !column[:keyseq].nil?
        column[:auto_increment] = identity
      end
      column[:type]        = schema_column_type(column[:db_type])
      column[:max_length]  = column[:longlength] if column[:type] == :string
      [ m.call(column.delete(:name)), column]
    end
end