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: m = output_identifier_meth 64: indexes = {} 65: metadata_dataset. 66: from(:syscat__indexes). 67: select(:indname, :uniquerule, :colnames). 68: where(:tabname=>input_identifier_meth.call(table), :system_required=>0). 69: each do |r| 70: indexes[m.call(r[:indname])] = {:unique=>(r[:uniquerule]=='U'), :columns=>r[:colnames][1..-1].split('+').map{|v| m.call(v)}} 71: end 72: indexes 73: 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