public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Remove DB2 adapter since IBM chooses to maintain their own adapter 
instead.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7690 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
jeremy (author)
Sat Sep 29 16:20:36 -0700 2007
commit  c9bfd7d543813150d0f87f246f8f39e675a9c3d4
tree    2072a436b3b2f731825a9378790ca6381e1caba7
parent  4158e54d75328dee3353da8486b43090d5b94ca2
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.0.0 [Preview Release]* (September 29th, 2007) [Includes duplicates of changes from 1.14.2 - 1.15.3]
0
 
0
+* Remove DB2 adapter since IBM chooses to maintain their own adapter instead. [Jeremy Kemper]
0
+
0
 * Extract Oracle, SQLServer, and Sybase adapters into gems. [Jeremy Kemper]
0
 
0
 * Added fixture caching that'll speed up a normal fixture-powered test suite between 50% and 100% #9682 [frederick.cheung@gmail.com]
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,243 +1 @@
0
-# Author/Maintainer: Maik Schmidt <contact@maik-schmidt.de>
0
-
0
-require 'active_record/connection_adapters/abstract_adapter'
0
-
0
-begin
0
- require 'db2/db2cli' unless self.class.const_defined?(:DB2CLI)
0
- require 'active_record/vendor/db2'
0
-
0
- module ActiveRecord
0
- class Base
0
- # Establishes a connection to the database that's used by
0
- # all Active Record objects
0
- def self.db2_connection(config) # :nodoc:
0
- config = config.symbolize_keys
0
- usr = config[:username]
0
- pwd = config[:password]
0
- schema = config[:schema]
0
-
0
- if config.has_key?(:database)
0
- database = config[:database]
0
- else
0
- raise ArgumentError, 'No database specified. Missing argument: database.'
0
- end
0
-
0
- connection = DB2::Connection.new(DB2::Environment.new)
0
- connection.connect(database, usr, pwd)
0
- ConnectionAdapters::DB2Adapter.new(connection, logger, :schema => schema)
0
- end
0
- end
0
-
0
- module ConnectionAdapters
0
- # The DB2 adapter works with the C-based CLI driver (http://rubyforge.org/projects/ruby-dbi/)
0
- #
0
- # Options:
0
- #
0
- # * <tt>:username</tt> -- Defaults to nothing
0
- # * <tt>:password</tt> -- Defaults to nothing
0
- # * <tt>:database</tt> -- The name of the database. No default, must be provided.
0
- # * <tt>:schema</tt> -- Database schema to be set initially.
0
- class DB2Adapter < AbstractAdapter
0
- def initialize(connection, logger, connection_options)
0
- super(connection, logger)
0
- @connection_options = connection_options
0
- if schema = @connection_options[:schema]
0
- with_statement do |stmt|
0
- stmt.exec_direct("SET SCHEMA=#{schema}")
0
- end
0
- end
0
- end
0
-
0
- def select_rows(sql, name = nil)
0
- stmt = nil
0
- log(sql, name) do
0
- stmt = DB2::Statement.new(@connection)
0
- stmt.exec_direct("#{sql.gsub(/=\s*null/i, 'IS NULL')} with ur")
0
- end
0
-
0
- rows = []
0
- while row = stmt.fetch
0
- rows << row
0
- end
0
- stmt.free
0
- rows
0
- end
0
-
0
- def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
0
- super || last_insert_id
0
- end
0
-
0
- def execute(sql, name = nil)
0
- rows_affected = 0
0
- with_statement do |stmt|
0
- log(sql, name) do
0
- stmt.exec_direct(sql)
0
- rows_affected = stmt.row_count
0
- end
0
- end
0
- rows_affected
0
- end
0
-
0
- def begin_db_transaction
0
- @connection.set_auto_commit_off
0
- end
0
-
0
- def commit_db_transaction
0
- @connection.commit
0
- @connection.set_auto_commit_on
0
- end
0
-
0
- def rollback_db_transaction
0
- @connection.rollback
0
- @connection.set_auto_commit_on
0
- end
0
-
0
- def quote_column_name(column_name)
0
- column_name
0
- end
0
-
0
- def adapter_name()
0
- 'DB2'
0
- end
0
-
0
- def quote_string(string)
0
- string.gsub(/'/, "''") # ' (for ruby-mode)
0
- end
0
-
0
- def add_limit_offset!(sql, options)
0
- if limit = options[:limit]
0
- offset = options[:offset] || 0
0
- # The following trick was added by andrea+rails@webcom.it.
0
- sql.gsub!(/SELECT/i, 'SELECT B.* FROM (SELECT A.*, row_number() over () AS internal$rownum FROM (SELECT')
0
- sql << ") A ) B WHERE B.internal$rownum > #{offset} AND B.internal$rownum <= #{limit + offset}"
0
- end
0
- end
0
-
0
- def tables(name = nil)
0
- result = []
0
- schema = @connection_options[:schema] || '%'
0
- with_statement do |stmt|
0
- stmt.tables(schema).each { |t| result << t[2].downcase }
0
- end
0
- result
0
- end
0
-
0
- def indexes(table_name, name = nil)
0
- tmp = {}
0
- schema = @connection_options[:schema] || ''
0
- with_statement do |stmt|
0
- stmt.indexes(table_name, schema).each do |t|
0
- next unless t[5]
0
- next if t[4] == 'SYSIBM' # Skip system indexes.
0
- idx_name = t[5].downcase
0
- col_name = t[8].downcase
0
- if tmp.has_key?(idx_name)
0
- tmp[idx_name].columns << col_name
0
- else
0
- is_unique = t[3] == 0
0
- tmp[idx_name] = IndexDefinition.new(table_name, idx_name, is_unique, [col_name])
0
- end
0
- end
0
- end
0
- tmp.values
0
- end
0
-
0
- def columns(table_name, name = nil)
0
- result = []
0
- schema = @connection_options[:schema] || '%'
0
- with_statement do |stmt|
0
- stmt.columns(table_name, schema).each do |c|
0
- c_name = c[3].downcase
0
- c_default = c[12] == 'NULL' ? nil : c[12]
0
- c_default.gsub!(/^'(.*)'$/, '\1') if !c_default.nil?
0
- c_type = c[5].downcase
0
- c_type += "(#{c[6]})" if !c[6].nil? && c[6] != ''
0
- result << Column.new(c_name, c_default, c_type, c[17] == 'YES')
0
- end
0
- end
0
- result
0
- end
0
-
0
- def native_database_types
0
- {
0
- :primary_key => 'int generated by default as identity (start with 42) primary key',
0
- :string => { :name => 'varchar', :limit => 255 },
0
- :text => { :name => 'clob', :limit => 32768 },
0
- :integer => { :name => 'int' },
0
- :float => { :name => 'float' },
0
- :decimal => { :name => 'decimal' },
0
- :datetime => { :name => 'timestamp' },
0
- :timestamp => { :name => 'timestamp' },
0
- :time => { :name => 'time' },
0
- :date => { :name => 'date' },
0
- :binary => { :name => 'blob', :limit => 32768 },
0
- :boolean => { :name => 'decimal', :limit => 1 }
0
- }
0
- end
0
-
0
- def quoted_true
0
- '1'
0
- end
0
-
0
- def quoted_false
0
- '0'
0
- end
0
-
0
- def active?
0
- @connection.select_one 'select 1 from ibm.sysdummy1'
0
- true
0
- rescue Exception
0
- false
0
- end
0
-
0
- def reconnect!
0
- end
0
-
0
- def table_alias_length
0
- 128
0
- end
0
-
0
- private
0
-
0
- def with_statement
0
- stmt = DB2::Statement.new(@connection)
0
- yield stmt
0
- stmt.free
0
- end
0
-
0
- def last_insert_id
0
- row = select_one(<<-GETID.strip)
0
- with temp(id) as (values (identity_val_local())) select * from temp
0
- GETID
0
- row['id'].to_i
0
- end
0
-
0
- def select(sql, name = nil)
0
- rows = []
0
- with_statement do |stmt|
0
- log(sql, name) do
0
- stmt.exec_direct("#{sql.gsub(/=\s*null/i, 'IS NULL')} with ur")
0
- end
0
-
0
- while row = stmt.fetch_as_hash
0
- row.delete('internal$rownum')
0
- rows << row
0
- end
0
- end
0
- rows
0
- end
0
- end
0
- end
0
- end
0
-rescue LoadError
0
- # DB2 driver is unavailable.
0
- module ActiveRecord # :nodoc:
0
- class Base
0
- def self.db2_connection(config) # :nodoc:
0
- # Set up a reasonable error message
0
- raise LoadError, "DB2 Libraries could not be loaded."
0
- end
0
- end
0
- end
0
-end

Comments

    No one has commented yet.