The DB2 adapter works with the C-based CLI driver (rubyforge.org/projects/ruby-dbi/)
Options:
- :username — Defaults to nothing
- :password — Defaults to nothing
- :database — The name of the database. No default, must be provided.
- :schema — Database schema to be set initially.
Methods
- active?
- adapter_name
- add_limit_offset!
- begin_db_transaction
- columns
- commit_db_transaction
- delete
- execute
- indexes
- insert
- native_database_types
- new
- quote_column_name
- quote_string
- quoted_false
- quoted_true
- reconnect!
- rollback_db_transaction
- select_all
- select_one
- table_alias_length
- tables
- update
Public Class methods
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 41 41: def initialize(connection, logger, connection_options) 42: super(connection, logger) 43: @connection_options = connection_options 44: if schema = @connection_options[:schema] 45: with_statement do |stmt| 46: stmt.exec_direct("SET SCHEMA=#{schema}") 47: end 48: end 49: end
Public Instance methods
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 182 182: def active? 183: @connection.select_one 'select 1 from ibm.sysdummy1' 184: true 185: rescue Exception 186: false 187: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 96 96: def adapter_name() 97: 'DB2' 98: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 104 104: def add_limit_offset!(sql, options) 105: if limit = options[:limit] 106: offset = options[:offset] || 0 107: # The following trick was added by andrea+rails@webcom.it. 108: sql.gsub!(/SELECT/i, 'SELECT B.* FROM (SELECT A.*, row_number() over () AS internal$rownum FROM (SELECT') 109: sql << ") A ) B WHERE B.internal$rownum > #{offset} AND B.internal$rownum <= #{limit + offset}" 110: end 111: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 78 78: def begin_db_transaction 79: @connection.set_auto_commit_off 80: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 142 142: def columns(table_name, name = nil) 143: result = [] 144: schema = @connection_options[:schema] || '%' 145: with_statement do |stmt| 146: stmt.columns(table_name, schema).each do |c| 147: c_name = c[3].downcase 148: c_default = c[12] == 'NULL' ? nil : c[12] 149: c_default.gsub!(/^'(.*)'$/, '\1') if !c_default.nil? 150: c_type = c[5].downcase 151: c_type += "(#{c[6]})" if !c[6].nil? && c[6] != '' 152: result << Column.new(c_name, c_default, c_type, c[17] == 'YES') 153: end 154: end 155: result 156: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 82 82: def commit_db_transaction 83: @connection.commit 84: @connection.set_auto_commit_on 85: end
Alias for execute
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 64 64: def execute(sql, name = nil) 65: rows_affected = 0 66: with_statement do |stmt| 67: log(sql, name) do 68: stmt.exec_direct(sql) 69: rows_affected = stmt.row_count 70: end 71: end 72: rows_affected 73: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 122 122: def indexes(table_name, name = nil) 123: tmp = {} 124: schema = @connection_options[:schema] || '' 125: with_statement do |stmt| 126: stmt.indexes(table_name, schema).each do |t| 127: next unless t[5] 128: next if t[4] == 'SYSIBM' # Skip system indexes. 129: idx_name = t[5].downcase 130: col_name = t[8].downcase 131: if tmp.has_key?(idx_name) 132: tmp[idx_name].columns << col_name 133: else 134: is_unique = t[3] == 0 135: tmp[idx_name] = IndexDefinition.new(table_name, idx_name, is_unique, [col_name]) 136: end 137: end 138: end 139: tmp.values 140: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 59 59: def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) 60: execute(sql, name = nil) 61: id_value || last_insert_id 62: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 158 158: def native_database_types 159: { 160: :primary_key => 'int generated by default as identity (start with 42) primary key', 161: :string => { :name => 'varchar', :limit => 255 }, 162: :text => { :name => 'clob', :limit => 32768 }, 163: :integer => { :name => 'int' }, 164: :float => { :name => 'float' }, 165: :datetime => { :name => 'timestamp' }, 166: :timestamp => { :name => 'timestamp' }, 167: :time => { :name => 'time' }, 168: :date => { :name => 'date' }, 169: :binary => { :name => 'blob', :limit => 32768 }, 170: :boolean => { :name => 'decimal', :limit => 1 } 171: } 172: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 92 92: def quote_column_name(column_name) 93: column_name 94: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 100 100: def quote_string(string) 101: string.gsub(/'/, "''") # ' (for ruby-mode) 102: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 178 178: def quoted_false 179: '0' 180: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 174 174: def quoted_true 175: '1' 176: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 189 189: def reconnect! 190: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 87 87: def rollback_db_transaction 88: @connection.rollback 89: @connection.set_auto_commit_on 90: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 51 51: def select_all(sql, name = nil) 52: select(sql, name) 53: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 55 55: def select_one(sql, name = nil) 56: select(sql, name).first 57: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 192 192: def table_alias_length 193: 128 194: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 113 113: def tables(name = nil) 114: result = [] 115: schema = @connection_options[:schema] || '%' 116: with_statement do |stmt| 117: stmt.tables(schema).each { |t| result << t[2].downcase } 118: end 119: result 120: end
Alias for execute