module ArJdbc::AS400

Constants

ADAPTER_NAME
DRIVER_NAME

Public Class Methods

arel_visitor_type(config = nil) click to toggle source

@see ActiveRecord::ConnectionAdapters::Jdbc::ArelSupport

# File lib/arjdbc/db2/as400.rb, line 17
def self.arel_visitor_type(config = nil); DB2.arel_visitor_type(config); end
column_selector() click to toggle source
# File lib/arjdbc/db2/as400.rb, line 19
def self.column_selector
  [ /as400/i, lambda { |config, column| column.extend(Column) } ]
end
emulate_booleans() click to toggle source

Boolean emulation can be disabled using :

ArJdbc::AS400.emulate_booleans = false
# File lib/arjdbc/db2/as400.rb, line 27
def self.emulate_booleans; DB2.emulate_booleans; end
emulate_booleans=(emulate) click to toggle source
# File lib/arjdbc/db2/as400.rb, line 28
def self.emulate_booleans=(emulate); DB2.emulate_booleans = emulate; end
extended(adapter) click to toggle source

@private

# File lib/arjdbc/db2/as400.rb, line 8
def self.extended(adapter); DB2.extended(adapter); end
initialize!() click to toggle source

@private

# File lib/arjdbc/db2/as400.rb, line 11
def self.initialize!; DB2.initialize!; end
jdbc_connection_class() click to toggle source

@see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class

# File lib/arjdbc/db2/as400.rb, line 14
def self.jdbc_connection_class; DB2.jdbc_connection_class; end

Public Instance Methods

adapter_name() click to toggle source
# File lib/arjdbc/db2/as400.rb, line 32
def adapter_name
  ADAPTER_NAME
end
as400?() click to toggle source

@private @deprecated no longer used

# File lib/arjdbc/db2/as400.rb, line 99
def as400?
  true
end
execute_table_change(sql, table_name, name = nil) click to toggle source

@override

# File lib/arjdbc/db2/as400.rb, line 52
def execute_table_change(sql, table_name, name = nil)
  execute_and_auto_confirm(sql, name)
end
prefetch_primary_key?(table_name = nil) click to toggle source

@override

# File lib/arjdbc/db2/as400.rb, line 37
def prefetch_primary_key?(table_name = nil)
  # TRUE if the table has no identity column
  names = table_name.upcase.split(".")
  sql = "SELECT 1 FROM SYSIBM.SQLPRIMARYKEYS WHERE "
  sql << "TABLE_SCHEM = '#{names.first}' AND " if names.size == 2
  sql << "TABLE_NAME = '#{names.last}'"
  select_one(sql).nil?
end
rename_column(table_name, column_name, new_column_name) click to toggle source

@override

# File lib/arjdbc/db2/as400.rb, line 47
def rename_column(table_name, column_name, new_column_name)
  raise NotImplementedError, "rename_column is not supported on IBM iSeries"
end
table_exists?(name) click to toggle source

disable all schemas browsing when default schema is specified

# File lib/arjdbc/db2/as400.rb, line 90
def table_exists?(name)
  return false unless name
  schema ? @connection.table_exists?(name, schema) : @connection.table_exists?(name)
end

Private Instance Methods

db2_schema() click to toggle source

@override

# File lib/arjdbc/db2/as400.rb, line 106
def db2_schema
  @db2_schema = false unless defined? @db2_schema
  return @db2_schema if @db2_schema != false
  @db2_schema =
    if config[:schema].present?
      config[:schema]
    elsif config[:jndi].present?
      # Only found method to set db2_schema from jndi
      result = select_one("SELECT CURRENT_SCHEMA FROM SYSIBM.SYSDUMMY1")
      schema = result['00001']
      # If the connection uses the library list schema name will be nil
      if schema == '*LIBL'
        schema = nil
      end
      schema
    else
      # AS400 implementation takes schema from library name (last part of URL)
      # jdbc:as400://localhost/schema;naming=system;libraries=lib1,lib2
      schema = nil
      split = config[:url].split('/')
      # Return nil if schema isn't defined
      schema = split.last.split(';').first.strip if split.size == 4
      schema
    end
end
execute_and_auto_confirm(sql, name = nil) click to toggle source

holy moly batman! all this to tell AS400 “yes i am sure”

# File lib/arjdbc/db2/as400.rb, line 57
def execute_and_auto_confirm(sql, name = nil)

  begin
    @connection.execute_update "call qsys.qcmdexc('QSYS/CHGJOB INQMSGRPY(*SYSRPYL)',0000000031.00000)"
    @connection.execute_update "call qsys.qcmdexc('ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY(''I'')',0000000045.00000)"
  rescue Exception => e
    raise "Could not call CHGJOB INQMSGRPY(*SYSRPYL) and ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I').\n" +
          "Do you have authority to do this?\n\n#{e.inspect}"
  end

  begin
    result = execute(sql, name)
  rescue Exception
    raise
  else
    # Return if all work fine
    result
  ensure

    # Ensure default configuration restoration
    begin
      @connection.execute_update "call qsys.qcmdexc('QSYS/CHGJOB INQMSGRPY(*DFT)',0000000027.00000)"
      @connection.execute_update "call qsys.qcmdexc('RMVRPYLE SEQNBR(9876)',0000000021.00000)"
    rescue Exception => e
      raise "Could not call CHGJOB INQMSGRPY(*DFT) and RMVRPYLE SEQNBR(9876).\n" +
                "Do you have authority to do this?\n\n#{e.inspect}"
    end

  end
end