7 if connection.is_a?(ArJdbc::Informix)
8 self.class.columns.each do |c|
9 if [:text, :binary].include? c.type
11 value = value.to_yaml if unserializable_attribute?(c.name, c)
13 unless value.nil? || (value == '')
14 connection.write_large_object(c.type == :binary,
16 self.class.table_name,
17 self.class.primary_key,
30 def self.extended(base)
31 @@db_major_version = base.select_one("SELECT dbinfo('version', 'major') version FROM systables WHERE tabid = 1")['version'].to_i
34 def self.column_selector
36 lambda { |cfg, column| column.extend(::ArJdbc::Informix::Column) } ]
39 def self.jdbc_connection_class
40 ::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
45 # TODO: Test all Informix column types.
46 def simplified_type(field_type)
47 if field_type =~ /serial/i
56 tp[:primary_key] = "SERIAL PRIMARY KEY"
57 tp[:string] = { :name => "VARCHAR", :limit => 255 }
58 tp[:integer] = { :name => "INTEGER" }
59 tp[:float] = { :name => "FLOAT" }
60 tp[:decimal] = { :name => "DECIMAL" }
61 tp[:datetime] = { :name => "DATETIME YEAR TO FRACTION(5)" }
62 tp[:timestamp] = { :name => "DATETIME YEAR TO FRACTION(5)" }
63 tp[:time] = { :name => "DATETIME HOUR TO FRACTION(5)" }
64 tp[:date] = { :name => "DATE" }
65 tp[:binary] = { :name => "BYTE" }
66 tp[:boolean] = { :name => "BOOLEAN" }
70 def prefetch_primary_key?(table_name = nil)
74 def supports_migrations?
78 def default_sequence_name(table, column)
82 def add_limit_offset!(sql, options)
84 limit = "FIRST #{options[:limit]}"
85 # SKIP available only in IDS >= 10
86 offset = (@@db_major_version >= 10 && options[:offset]?
87 "SKIP #{options[:offset]}" : "")
88 sql.sub!(/^select /i, "SELECT #{offset} #{limit} ")
93 def next_sequence_value(sequence_name)
94 select_one("SELECT #{sequence_name}.nextval id FROM systables WHERE tabid=1")['id']
97 # TODO: Add some smart quoting for newlines in string and text fields.
98 def quote_string(string)
99 string.gsub(/\'/, "''")
102 def quote(value, column = nil)
103 if column && [:binary, :text].include?(column.type)
104 # LOBs are updated separately by an after_save trigger.
106 elsif column && column.type == :date
107 "'#{value.mon}/#{value.day}/#{value.year}'"
113 def create_table(name, options = {})
115 execute("CREATE SEQUENCE #{name}_seq")
118 def rename_table(name, new_name)
119 execute("RENAME TABLE #{name} TO #{new_name}")
120 execute("RENAME SEQUENCE #{name}_seq TO #{new_name}_seq")
125 execute("DROP SEQUENCE #{name}_seq")
128 def remove_index(table_name, options = {})
129 @connection.execute_update("DROP INDEX #{index_name(table_name, options)}")
133 def select(sql, name = nil)
134 # Informix does not like "= NULL", "!= NULL", or "<> NULL".
135 execute(sql.gsub(/(!=|<>)\s*null/i, "IS NOT NULL").gsub(/=\s*null/i, "IS NULL"), name)
137 end # module Informix
138 end # module ::ArJdbc