7 if connection.is_a?(JdbcSpec::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,
29 module ActiveRecordExtensions
30 def informix_connection(config)
31 config[:port] ||= 9088
32 config[:url] ||= "jdbc:informix-sqli://#{config[:host]}:#{config[:port]}/#{config[:database]}:INFORMIXSERVER=#{config[:servername]}"
33 config[:driver] = 'com.informix.jdbc.IfxDriver'
34 jdbc_connection(config)
39 def self.extended(base)
40 @@db_major_version = base.select_one("SELECT dbinfo('version', 'major') version FROM systables WHERE tabid = 1")['version'].to_i
43 def self.column_selector
45 lambda { |cfg, column| column.extend(::JdbcSpec::Informix::Column) } ]
48 def self.adapter_selector
50 lambda { |cfg, adapter| adapter.extend(::JdbcSpec::Informix) } ]
55 # TODO: Test all Informix column types.
56 def simplified_type(field_type)
57 if field_type =~ /serial/i
66 tp[:primary_key] = "SERIAL PRIMARY KEY"
67 tp[:string] = { :name => "VARCHAR", :limit => 255 }
68 tp[:integer] = { :name => "INTEGER" }
69 tp[:float] = { :name => "FLOAT" }
70 tp[:decimal] = { :name => "DECIMAL" }
71 tp[:datetime] = { :name => "DATETIME YEAR TO FRACTION(5)" }
72 tp[:timestamp] = { :name => "DATETIME YEAR TO FRACTION(5)" }
73 tp[:time] = { :name => "DATETIME HOUR TO FRACTION(5)" }
74 tp[:date] = { :name => "DATE" }
75 tp[:binary] = { :name => "BYTE" }
76 tp[:boolean] = { :name => "BOOLEAN" }
80 def prefetch_primary_key?(table_name = nil)
84 def supports_migrations?
88 def default_sequence_name(table, column)
92 def add_limit_offset!(sql, options)
94 limit = "FIRST #{options[:limit]}"
95 # SKIP available only in IDS >= 10
96 offset = (@@db_major_version >= 10 && options[:offset]?
97 "SKIP #{options[:offset]}" : "")
98 sql.sub!(/^select /i, "SELECT #{offset} #{limit} ")
103 def next_sequence_value(sequence_name)
104 select_one("SELECT #{sequence_name}.nextval id FROM systables WHERE tabid=1")['id']
107 # TODO: Add some smart quoting for newlines in string and text fields.
108 def quote_string(string)
109 string.gsub(/\'/, "''")
112 def quote(value, column = nil)
113 if column && [:binary, :text].include?(column.type)
114 # LOBs are updated separately by an after_save trigger.
116 elsif column && column.type == :date
117 "'#{value.mon}/#{value.day}/#{value.year}'"
123 def create_table(name, options = {})
125 execute("CREATE SEQUENCE #{name}_seq")
128 def rename_table(name, new_name)
129 execute("RENAME TABLE #{name} TO #{new_name}")
130 execute("RENAME SEQUENCE #{name}_seq TO #{new_name}_seq")
135 execute("DROP SEQUENCE #{name}_seq")
138 def remove_index(table_name, options = {})
139 @connection.execute_update("DROP INDEX #{index_name(table_name, options)}")
143 def select(sql, name = nil)
144 # Informix does not like "= NULL", "!= NULL", or "<> NULL".
145 execute(sql.gsub(/(!=|<>)\s*null/i, "IS NOT NULL").gsub(/=\s*null/i, "IS NULL"), name)
147 end # module Informix
148 end # module ::JdbcSpec