Class: ActiveRecord::ConnectionAdapters::DB2Adapter

Inherits:
JdbcAdapter
  • Object
show all
Includes:
ArJdbc::DB2, ArJdbc::DB2::Column
Defined in:
lib/arjdbc/db2/adapter.rb

Direct Known Subclasses

AS400Adapter

Constant Summary

Constants included from ArJdbc::DB2

ArJdbc::DB2::ADAPTER_NAME, ArJdbc::DB2::DRIVER_NAME, ArJdbc::DB2::HAVE_LIMIT, ArJdbc::DB2::HAVE_PRECISION, ArJdbc::DB2::HAVE_SCALE, ArJdbc::DB2::NATIVE_DATABASE_TYPES

Constants inherited from JdbcAdapter

JdbcAdapter::ADAPTER_NAME

Constants included from ArJdbc::Abstract::DatabaseStatements

ArJdbc::Abstract::DatabaseStatements::NO_BINDS

Instance Attribute Summary

Attributes inherited from JdbcAdapter

#prepared_statements

Attributes included from ArJdbc::Abstract::Core

#config

Instance Method Summary collapse

Methods included from ArJdbc::DB2::Column

cast_to_date_or_time, cast_to_time, #type_cast, #type_cast_code

Methods included from ArJdbc::DB2

#adapter_name, #add_column, #add_column_options!, #add_index, #add_limit_offset!, #change_column, #change_column_default, #change_column_null, column_selector, #columns, #configure_connection, #create_table, #drop_database, #empty_insert_statement_value, emulate_booleans, emulate_booleans=, emulate_booleans?, #execute_table_change, #indexes, #jdbc_column_class, jdbc_connection_class, #last_inserted_id, #modify_types, #native_database_types, #next_sequence_value, #pk_and_sequence_for, #prefetch_primary_key?, #primary_keys, #quote, #quote_column_name, #quote_time, #quoted_date, #recreate_database, #remove_column, #remove_index!, #rename_column, #rename_table, #reset_column_information, #runstats_for_table, #schema, #schema=, #select, #supports_views?, #table_definition, #tables, #truncate, #type_to_sql, #update_lob_value?, update_lob_values=, update_lob_values?

Methods inherited from JdbcAdapter

#adapter_name, #adapter_spec, arel2_visitors, #columns, configure_arel2_visitors, #data_source_exists?, #data_sources, #database_name, #exec_query_raw, #execute, #execute_quietly, #foreign_keys, #indexes, #is_a?, #jdbc_column_class, #last_inserted_id, #modify_types, #native_database_types, #pk_and_sequence_for, prepared_statements?, #prepared_statements?, #primary_keys, #structure_dump, #supports_foreign_keys?, #supports_migrations?, #supports_views?, #table_definition, #table_exists?, #tables, #update_lob_value, #valid_type?, #write_large_object

Methods included from ArJdbc::Abstract::TransactionSupport

#begin_db_transaction, #begin_isolated_db_transaction, #commit_db_transaction, #create_savepoint, #exec_rollback_db_transaction, #exec_rollback_to_savepoint, #release_savepoint, #supports_savepoints?, #supports_transaction_isolation?

Methods included from ArJdbc::Abstract::DatabaseStatements

#exec_insert, #exec_query, #exec_update, #execute, #select_all

Methods included from ArJdbc::Abstract::ConnectionManagement

#active?, #disconnect!, #really_valid?, #reconnect!

Methods included from ArJdbc::Abstract::Core

#extract_raw_bind_values, #jdbc_connection, #log, #translate_exception, #translate_exception_class

Methods included from Jdbc::ConnectionPoolCallbacks

#on_checkin, #on_checkout

Constructor Details

#initialize(connection, logger = nil, connection_parameters = nil, config = {}) ⇒ DB2Adapter

AR 5.2 Fix



44
45
46
# File 'lib/arjdbc/db2/adapter.rb', line 44

def initialize(connection, logger = nil, connection_parameters = nil, config = {})
  super(connection, logger, config) # configure_connection happens in super
end

Instance Method Details

#data_source_sql(name = nil, type: nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/arjdbc/db2/adapter.rb', line 52

def data_source_sql(name = nil, type: nil)
  scope = quoted_scope(name, type: type)

  sql = if scope[:type] == "'T'"
          "select table_name from sysibm.tables".dup
        else
          "select table_name from sysibm.views".dup
        end

  wheres = []

  wheres << " table_type = #{scope[:type]}" if scope[:type]
  wheres << " table_schema = #{scope[:schema]}" if scope[:schema]
  wheres << " UPPER(table_name) = UPPER(#{scope[:name]})" if scope[:name]

  if wheres.present?
    sql << ' WHERE '
    sql << wheres.join(' AND ')
  end
  sql
end

#jdbc_connection_class(spec) ⇒ Object



48
49
50
# File 'lib/arjdbc/db2/adapter.rb', line 48

def jdbc_connection_class(spec)
  ArJdbc::DB2.jdbc_connection_class
end

#quoted_scope(name = nil, type: nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/arjdbc/db2/adapter.rb', line 74

def quoted_scope(name = nil, type: nil)
  type = \
      case type
      when "BASE TABLE"
        "'T'"
      when "VIEW"
        "'V'"
      end
  scope = {}
  scope[:name] = quote(name) if name
  scope[:type] = type if type
  scope[:schema] = quote(scope[:schema] || schema)
  scope
end