| Module | Sequel::DB2::DatabaseMethods |
| In: |
lib/sequel/adapters/shared/db2.rb
|
| AUTOINCREMENT | = | 'GENERATED ALWAYS AS IDENTITY'.freeze |
| NOT_NULL | = | ' NOT NULL'.freeze |
| NULL | = | ''.freeze |
Return the database version as a string. Don‘t rely on this, it may return an integer in the future.
# File lib/sequel/adapters/shared/db2.rb, line 24
24: def db2_version
25: return @db2_version if @db2_version
26: @db2_version = metadata_dataset.with_sql("select service_level from sysibmadm.env_inst_info").first[:service_level]
27: end
Use SYSCAT.INDEXES to get the indexes for the table
# File lib/sequel/adapters/shared/db2.rb, line 62
62: def indexes(table, opts = {})
63: metadata_dataset.
64: with_sql("SELECT INDNAME,UNIQUERULE,MADE_UNIQUE,SYSTEM_REQUIRED FROM SYSCAT.INDEXES WHERE TABNAME = #{literal(input_identifier_meth.call(table))}").
65: all.map{|h| Hash[ h.map{|k,v| [k.to_sym, v]} ] }
66: end
Use SYSIBM.SYSCOLUMNS to get the information on the tables.
# File lib/sequel/adapters/shared/db2.rb, line 31
31: def schema_parse_table(table, opts = {})
32: m = output_identifier_meth(opts[:dataset])
33: im = input_identifier_meth(opts[:dataset])
34: metadata_dataset.with_sql("SELECT * FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = #{literal(im.call(table))} ORDER BY COLNO").
35: collect do |column|
36: column[:db_type] = column.delete(:typename)
37: if column[:db_type] == "DECIMAL"
38: column[:db_type] << "(#{column[:longlength]},#{column[:scale]})"
39: end
40: column[:allow_null] = column.delete(:nulls) == 'Y'
41: column[:primary_key] = column.delete(:identity) == 'Y' || !column[:keyseq].nil?
42: column[:type] = schema_column_type(column[:db_type])
43: [ m.call(column.delete(:name)), column]
44: end
45: end
Use SYSCAT.TABLES to get the tables for the database
# File lib/sequel/adapters/shared/db2.rb, line 48
48: def tables
49: metadata_dataset.
50: with_sql("SELECT TABNAME FROM SYSCAT.TABLES WHERE TYPE='T' AND OWNER = #{literal(input_identifier_meth.call(opts[:user]))}").
51: all.map{|h| output_identifier_meth.call(h[:tabname]) }
52: end
Use SYSCAT.TABLES to get the views for the database
# File lib/sequel/adapters/shared/db2.rb, line 55
55: def views
56: metadata_dataset.
57: with_sql("SELECT TABNAME FROM SYSCAT.TABLES WHERE TYPE='V' AND OWNER = #{literal(input_identifier_meth.call(opts[:user]))}").
58: all.map{|h| output_identifier_meth.call(h[:tabname]) }
59: end