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.
- A
- B
- C
- E
- I
- N
- Q
- R
- T
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 41 def initialize(connection, logger, connection_options) super(connection, logger) @connection_options = connection_options if schema = @connection_options[:schema] with_statement do |stmt| stmt.exec_direct("SET SCHEMA=#{schema}") end end end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 172 def active? @connection.select_one 'select 1 from ibm.sysdummy1' true rescue Exception false end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 85 def adapter_name() 'DB2' end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 93 def add_limit_offset!(sql, options) if limit = options[:limit] offset = options[:offset] || 0 # The following trick was added by andrea+rails@webcom.it. sql.gsub!(%rSELECT/, '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
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 67 def begin_db_transaction @connection.set_auto_commit_off end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 131 def columns(table_name, name = nil) result = [] schema = @connection_options[:schema] || '%' with_statement do |stmt| stmt.columns(table_name, schema).each do |c| c_name = c[3].downcase c_default = c[12] == 'NULL' ? nil : c[12] c_default.gsub!(%r^'(.*)'$/, '\1') if !c_default.nil? c_type = c[5].downcase c_type += "(#{c[6]})" if !c[6].nil? && c[6] != '' result << Column.new(c_name, c_default, c_type, c[17] == 'YES') end end result end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 71 def commit_db_transaction @connection.commit @connection.set_auto_commit_on end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 56 def execute(sql, name = nil) rows_affected = 0 with_statement do |stmt| log(sql, name) do stmt.exec_direct(sql) rows_affected = stmt.row_count end end rows_affected end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 111 def indexes(table_name, name = nil) tmp = {} schema = @connection_options[:schema] || '' with_statement do |stmt| stmt.indexes(table_name, schema).each do |t| next unless t[5] next if t[4] == 'SYSIBM' # Skip system indexes. idx_name = t[5].downcase col_name = t[8].downcase if tmp.has_key?(idx_name) tmp[idx_name].columns << col_name else is_unique = t[3] == 0 tmp[idx_name] = IndexDefinition.new(table_name, idx_name, is_unique, [col_name]) end end end tmp.values end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 51 def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) execute(sql, name = nil) id_value || last_insert_id end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 147 def native_database_types { :primary_key => 'int generated by default as identity (start with 42) primary key', :string => { :name => 'varchar', :limit => 255 }, :text => { :name => 'clob', :limit => 32768 }, :integer => { :name => 'int' }, :float => { :name => 'float' }, :decimal => { :name => 'decimal' }, :datetime => { :name => 'timestamp' }, :timestamp => { :name => 'timestamp' }, :time => { :name => 'time' }, :date => { :name => 'date' }, :binary => { :name => 'blob', :limit => 32768 }, :boolean => { :name => 'decimal', :limit => 1 } } end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 81 def quote_column_name(column_name) column_name end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 89 def quote_string(string) string.gsub(%r'/, "''") # ' (for ruby-mode) end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 168 def quoted_false '0' end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 164 def quoted_true '1' end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 179 def reconnect! end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 76 def rollback_db_transaction @connection.rollback @connection.set_auto_commit_on end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 182 def table_alias_length 128 end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 102 def tables(name = nil) result = [] schema = @connection_options[:schema] || '%' with_statement do |stmt| stmt.tables(schema).each { |t| result << t[2].downcase } end result end