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.
Methods
- adapter_name
- add_limit_offset!
- begin_db_transaction
- columns
- commit_db_transaction
- delete
- execute
- insert
- native_database_types
- quote_column_name
- quote_string
- quoted_false
- quoted_true
- rollback_db_transaction
- select_all
- select_one
- tables
- update
Public Instance methods
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 86
86: def adapter_name()
87: 'DB2'
88: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 94
94: def add_limit_offset!(sql, options)
95: if options[:limit] and !options[:limit].nil?
96: # "FETCH FIRST 0 ROWS ONLY" is not allowed, so we have
97: # to use a cheap trick.
98: if options[:limit] == 0
99: if sql =~ /WHERE/i
100: sql.sub!(/WHERE/i, 'WHERE 1 = 2 AND ')
101: elsif
102: sql =~ /ORDER\s+BY/i
103: sql.sub!(/ORDER\s+BY/i, 'WHERE 1 = 2 ORDER BY')
104: else
105: sql << 'WHERE 1 = 2'
106: end
107: else
108: sql << " FETCH FIRST #{options[:limit]} ROWS ONLY"
109: end
110: end
111: if options[:offset] and !options[:offset].nil?
112: raise ArgumentError, ':offset option is not yet supported!'
113: end
114: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 68
68: def begin_db_transaction
69: @connection.set_auto_commit_off
70: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 124
124: def columns(table_name, name = nil)
125: stmt = DB2::Statement.new(@connection)
126: result = []
127:
128: stmt.columns(table_name.upcase).each do |c|
129: c_name = c[3].downcase
130: c_default = c[12] == 'NULL' ? nil : c[12]
131: c_type = c[5].downcase
132: c_type += "(#{c[6]})" if !c[6].nil? && c[6] != ''
133: result << Column.new(c_name, c_default, c_type)
134: end
135:
136: stmt.free
137: result
138: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 72
72: def commit_db_transaction
73: @connection.commit
74: @connection.set_auto_commit_on
75: end
Alias for execute
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 52
52: def execute(sql, name = nil)
53: rows_affected = 0
54:
55: log(sql, name) do
56: stmt = DB2::Statement.new(@connection)
57: stmt.exec_direct(sql)
58: rows_affected = stmt.row_count
59: stmt.free
60: end
61:
62: rows_affected
63: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 47
47: def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
48: execute(sql, name = nil)
49: id_value || last_insert_id
50: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 140
140: def native_database_types
141: {
142: :primary_key => "int generated by default as identity primary key",
143: :string => { :name => "varchar", :limit => 255 },
144: :text => { :name => "clob", :limit => 32768 },
145: :integer => { :name => "int" },
146: :float => { :name => "float" },
147: :datetime => { :name => "timestamp" },
148: :timestamp => { :name => "timestamp" },
149: :time => { :name => "time" },
150: :date => { :name => "date" },
151: :binary => { :name => "blob", :limit => 32768 },
152: :boolean => { :name => "decimal", :limit => 1 }
153: }
154: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 82
82: def quote_column_name(column_name)
83: column_name
84: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 90
90: def quote_string(string)
91: string.gsub(/'/, "''") # ' (for ruby-mode)
92: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 160
160: def quoted_false
161: '0'
162: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 156
156: def quoted_true
157: '1'
158: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 77
77: def rollback_db_transaction
78: @connection.rollback
79: @connection.set_auto_commit_on
80: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 39
39: def select_all(sql, name = nil)
40: select(sql, name)
41: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 43
43: def select_one(sql, name = nil)
44: select(sql, name).first
45: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/db2_adapter.rb, line 116
116: def tables(name = nil)
117: stmt = DB2::Statement.new(@connection)
118: result = []
119: stmt.tables.each { |t| result << t[2].downcase }
120: stmt.free
121: result
122: end
Alias for execute