Namespace

Class/Module Index [+]

Quicksearch

JdbcSpec::DB2

Public Class Methods

adapter_matcher(name, config) click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 3
def self.adapter_matcher(name, config)
  if name =~ /db2/
     return config[:url] =~ /^jdbc:derby:net:/ ? ::JdbcSpec::Derby : self
  end
  false
end
adapter_selector() click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 10
def self.adapter_selector
  [/db2/, lambda {|cfg,adapt|
     if cfg[:url] =~ /^jdbc:derby:net:/
       adapt.extend(::JdbcSpec::Derby)
     else
       adapt.extend(::JdbcSpec::DB2)
     end }]
end

Public Instance Methods

add_limit_offset!(sql, options) click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 60
def add_limit_offset!(sql, options)
  if limit = options[:limit]
    offset = options[:offset] || 0
    sql.gsub!(/SELECT/, 'SELECT B.* FROM (SELECT A.*, row_number() over () AS internal$rownum FROM (SELECT')
    sql << ") A ) B WHERE B.internal$rownum > #{offset} AND B.internal$rownum <= #{limit + offset}"
  end
end
add_quotes(name) click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 124
def add_quotes(name)
  return name unless name
  %{"#{name}"}
end
columns(table_name, name = nil) click to toggle source

This method makes tests pass without understanding why. Don't use this in production.

# File lib/jdbc_adapter/jdbc_db2.rb, line 117
def columns(table_name, name = nil)
  super.select do |col|
    # strip out "magic" columns from DB2 (?)
    !/rolename|roleid|create_time|auditpolicyname|auditpolicyid|remarks/.match(col.name)
  end
end
dump_schema_information() click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 179
def dump_schema_information
  begin
    if (current_schema = ActiveRecord::Migrator.current_version) > 0
      #TODO: Find a way to get the DB2 instace name to properly form the statement
      return "INSERT INTO DB2INST2.SCHEMA_INFO (version) VALUES (#{current_schema})"
    end
  rescue ActiveRecord::StatementInvalid
    # No Schema Info
  end
end
expand_double_quotes(name) click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 135
def expand_double_quotes(name)
  return name unless name && name['"']
  name.gsub(/"/,'""')
end
modify_types(tp) click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 52
def modify_types(tp)
  tp[:primary_key] = 'int not null generated by default as identity (start with 1) primary key'
  tp[:string][:limit] = 255
  tp[:integer][:limit] = nil
  tp[:boolean][:limit] = nil
  tp
end
quote_column_name(column_name) click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 68
def quote_column_name(column_name)
  column_name
end
quote_string(string) click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 90
def quote_string(string)
  string.gsub(/'/, "''") # ' (for ruby-mode)
end
quoted_false() click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 98
def quoted_false
  '0'
end
quoted_true() click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 94
def quoted_true
  '1'
end
recreate_database(name) click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 102
def recreate_database(name)
  do_not_drop = ["stmg_dbsize_info","hmon_atm_info","hmon_collection","policy"]
  tables.each do |table|
    unless do_not_drop.include?(table)
      drop_table(table)
    end
  end
end
remove_index(table_name, options = { }) click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 111
def remove_index(table_name, options = { })
  execute "DROP INDEX #{quote_column_name(index_name(table_name, options))}"
end
strip_quotes(str) click to toggle source
# File lib/jdbc_adapter/jdbc_db2.rb, line 129
def strip_quotes(str)
  return str unless str
  return str unless /^(["']).*\11$$/ =~ str
  str[1..-2]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.