Skip to content

Commit 0a333d4

Browse files
fgoepelkares
authored andcommitted
Fix InformixAdapter for Rails 4.0/4.1
Fixes #622. This doesn’t add Rails 4.2 support. Conflicts: lib/arjdbc/informix/adapter.rb
1 parent 5e14ef3 commit 0a333d4

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

lib/arjdbc/informix/adapter.rb

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
require 'arjdbc/jdbc/serialized_attributes_helper'
1+
require 'arjdbc/util/serialized_attributes'
22

33
module ArJdbc
44
module Informix
5-
5+
66
@@_lob_callback_added = nil
7-
7+
88
def self.extended(base)
99
unless @@_lob_callback_added
1010
ActiveRecord::Base.class_eval do
@@ -13,10 +13,10 @@ def after_save_with_informix_lob
1313
lob_columns.each do |column|
1414
value = ::ArJdbc::SerializedAttributesHelper.dump_column_value(self, column)
1515
next if value.nil? || (value == '')
16-
16+
1717
connection.write_large_object(
18-
column.type == :binary, column.name,
19-
self.class.table_name, self.class.primary_key,
18+
column.type == :binary, column.name,
19+
self.class.table_name, self.class.primary_key,
2020
quote_value(id), value
2121
)
2222
end
@@ -28,16 +28,25 @@ def after_save_with_informix_lob
2828
end
2929
end
3030

31+
# @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
3132
def self.column_selector
32-
[ /informix/i, lambda { |cfg, column| column.extend(::ArJdbc::Informix::Column) } ]
33+
[ /informix/i, lambda { |cfg, column| column.extend(ColumnMethods) } ]
3334
end
3435

36+
JdbcConnection = ::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
37+
38+
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
3539
def self.jdbc_connection_class
3640
::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
3741
end
3842

39-
module Column
40-
43+
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
44+
def jdbc_column_class
45+
::ActiveRecord::ConnectionAdapters::InformixColumn
46+
end
47+
48+
module ColumnMethods
49+
4150
private
4251
# TODO: Test all Informix column types.
4352
def simplified_type(field_type)
@@ -47,7 +56,7 @@ def simplified_type(field_type)
4756
super
4857
end
4958
end
50-
59+
5160
end
5261

5362
def modify_types(types)
@@ -126,18 +135,28 @@ def drop_table(name)
126135
def remove_index(table_name, options = {})
127136
@connection.execute_update("DROP INDEX #{index_name(table_name, options)}")
128137
end
129-
138+
130139
def select(sql, *rest)
131140
# Informix does not like "= NULL", "!= NULL", or "<> NULL".
132-
execute(sql.gsub(/(!=|<>)\s*null/i, "IS NOT NULL").gsub(/=\s*null/i, "IS NULL"), *rest)
141+
super(sql.gsub(/(!=|<>)\s*null/i, "IS NOT NULL").gsub(/=\s*null/i, "IS NULL"), *rest)
133142
end
134-
143+
135144
private
136-
145+
137146
def db_major_version
138-
@@db_major_version ||=
147+
@@db_major_version ||=
139148
select_one("SELECT dbinfo('version', 'major') version FROM systables WHERE tabid = 1")['version'].to_i
140149
end
141-
150+
142151
end # module Informix
143152
end # module ::ArJdbc
153+
154+
module ActiveRecord::ConnectionAdapters
155+
class InformixColumn < JdbcColumn
156+
include ::ArJdbc::Informix::ColumnMethods
157+
end
158+
159+
class InformixAdapter < JdbcAdapter
160+
include ::ArJdbc::Informix
161+
end
162+
end

0 commit comments

Comments
 (0)