Class/Module Index [+]

Quicksearch

Sequel::DB2::DatabaseMethods

Public Instance Methods

database_type() click to toggle source

DB2 always uses :db2 as it's database type

# File lib/sequel/adapters/shared/db2.rb, line 20
def database_type
  :db2
end
db2_version() click to toggle source

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 26
def db2_version
  return @db2_version if @db2_version
  @db2_version = metadata_dataset.with_sql("select service_level from sysibmadm.env_inst_info").first[:service_level]
end
Also aliased as: server_version
indexes(table, opts = {}) click to toggle source

Use SYSCAT.INDEXES to get the indexes for the table

# File lib/sequel/adapters/shared/db2.rb, line 64
def indexes(table, opts = {})
  m = output_identifier_meth
  indexes = {}
  metadata_dataset.
   from(:syscat__indexes).
   select(:indname, :uniquerule, :colnames).
   where(:tabname=>input_identifier_meth.call(table), :system_required=>0).
   each do |r|
    indexes[m.call(r[:indname])] = {:unique=>(r[:uniquerule]=='U'), :columns=>r[:colnames][1..-1].split('+').map{|v| m.call(v)}}
  end
  indexes
end
schema_parse_table(table, opts = {}) click to toggle source

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

# File lib/sequel/adapters/shared/db2.rb, line 33
def schema_parse_table(table, opts = {})
  m = output_identifier_meth(opts[:dataset])
  im = input_identifier_meth(opts[:dataset])
  metadata_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]  == "DECIMAL"
        column[:db_type] << "(#{column[:longlength]},#{column[:scale]})"
      end
      column[:allow_null]  = column.delete(:nulls) == 'Y'
      column[:primary_key] = column.delete(:identity) == 'Y' || !column[:keyseq].nil?
      column[:type]        = schema_column_type(column[:db_type])
      [ m.call(column.delete(:name)), column]
    end
end
server_version() click to toggle source
Alias for: db2_version
supports_transaction_isolation_levels?() click to toggle source

DB2 supports transaction isolation levels.

# File lib/sequel/adapters/shared/db2.rb, line 78
def supports_transaction_isolation_levels?
  true
end
tables() click to toggle source

Use SYSCAT.TABLES to get the tables for the database

# File lib/sequel/adapters/shared/db2.rb, line 50
def tables
  metadata_dataset.
    with_sql("SELECT TABNAME FROM SYSCAT.TABLES WHERE TYPE='T' AND OWNER = #{literal(input_identifier_meth.call(opts[:user]))}").
    all.map{|h| output_identifier_meth.call(h[:tabname]) }
end
views() click to toggle source

Use SYSCAT.TABLES to get the views for the database

# File lib/sequel/adapters/shared/db2.rb, line 57
def views
  metadata_dataset.
    with_sql("SELECT TABNAME FROM SYSCAT.TABLES WHERE TYPE='V' AND OWNER = #{literal(input_identifier_meth.call(opts[:user]))}").
    all.map{|h| output_identifier_meth.call(h[:tabname]) }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.