module ArJdbc::Informix

Constants

JdbcConnection

Public Class Methods

column_selector() click to toggle source

@see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types

# File lib/arjdbc/informix/adapter.rb, line 32
def self.column_selector
  [ /informix/i, lambda { |cfg, column| column.extend(ColumnMethods) } ]
end
extended(base) click to toggle source
# File lib/arjdbc/informix/adapter.rb, line 8
def self.extended(base)
  unless @@_lob_callback_added
    ActiveRecord::Base.class_eval do
      def after_save_with_informix_lob
        lob_columns = self.class.columns.select { |c| [:text, :binary].include?(c.type) }
        lob_columns.each do |column|
          value = ::ArJdbc::SerializedAttributesHelper.dump_column_value(self, column)
          next if value.nil? || (value == '')

          connection.write_large_object(
            column.type == :binary, column.name,
            self.class.table_name, self.class.primary_key,
            quote_value(id), value
          )
        end
      end
    end

    ActiveRecord::Base.after_save :after_save_with_informix_lob
    @@_lob_callback_added = true
  end
end
jdbc_connection_class() click to toggle source

@see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class

# File lib/arjdbc/informix/adapter.rb, line 39
def self.jdbc_connection_class
  ::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
end

Public Instance Methods

add_limit_offset!(sql, options) click to toggle source
# File lib/arjdbc/informix/adapter.rb, line 90
def add_limit_offset!(sql, options)
  if options[:limit]
    limit = "FIRST #{options[:limit]}" # SKIP available only in IDS >= 10 :
    offset = (db_major_version >= 10 && options[:offset] ? "SKIP #{options[:offset]}" : "")
    sql.sub!(/^\s*?select /i, "SELECT #{offset} #{limit} ")
  end
  sql
end
after_save_with_informix_lob() click to toggle source
# File lib/arjdbc/informix/adapter.rb, line 11
def after_save_with_informix_lob
  lob_columns = self.class.columns.select { |c| [:text, :binary].include?(c.type) }
  lob_columns.each do |column|
    value = ::ArJdbc::SerializedAttributesHelper.dump_column_value(self, column)
    next if value.nil? || (value == '')

    connection.write_large_object(
      column.type == :binary, column.name,
      self.class.table_name, self.class.primary_key,
      quote_value(id), value
    )
  end
end
create_table(name, options = {}) click to toggle source
Calls superclass method
# File lib/arjdbc/informix/adapter.rb, line 120
def create_table(name, options = {})
  super(name, options)
  execute("CREATE SEQUENCE #{name}_seq")
end
default_sequence_name(table, column) click to toggle source
# File lib/arjdbc/informix/adapter.rb, line 86
def default_sequence_name(table, column)
  "#{table}_seq"
end
drop_table(name) click to toggle source
Calls superclass method
# File lib/arjdbc/informix/adapter.rb, line 130
def drop_table(name)
  super(name)
  execute("DROP SEQUENCE #{name}_seq")
end
jdbc_column_class() click to toggle source

@see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class

# File lib/arjdbc/informix/adapter.rb, line 44
def jdbc_column_class
  ::ActiveRecord::ConnectionAdapters::InformixColumn
end
modify_types(types) click to toggle source
Calls superclass method
# File lib/arjdbc/informix/adapter.rb, line 62
def modify_types(types)
  super(types)
  types[:primary_key] = "SERIAL PRIMARY KEY"
  types[:string]      = { :name => "VARCHAR", :limit => 255 }
  types[:integer]     = { :name => "INTEGER" }
  types[:float]       = { :name => "FLOAT" }
  types[:decimal]     = { :name => "DECIMAL" }
  types[:datetime]    = { :name => "DATETIME YEAR TO FRACTION(5)" }
  types[:timestamp]   = { :name => "DATETIME YEAR TO FRACTION(5)" }
  types[:time]        = { :name => "DATETIME HOUR TO FRACTION(5)" }
  types[:date]        = { :name => "DATE" }
  types[:binary]      = { :name => "BYTE" }
  types[:boolean]     = { :name => "BOOLEAN" }
  types
end
next_sequence_value(sequence_name) click to toggle source
# File lib/arjdbc/informix/adapter.rb, line 99
def next_sequence_value(sequence_name)
  select_one("SELECT #{sequence_name}.nextval id FROM systables WHERE tabid=1")['id']
end
prefetch_primary_key?(table_name = nil) click to toggle source
# File lib/arjdbc/informix/adapter.rb, line 78
def prefetch_primary_key?(table_name = nil)
  true
end
quote(value, column = nil) click to toggle source
Calls superclass method
# File lib/arjdbc/informix/adapter.rb, line 108
def quote(value, column = nil)
  column_type = column && column.type
  if column_type == :binary || column_type == :text
    # LOBs are updated separately by an after_save trigger.
    "NULL"
  elsif column_type == :date
    "'#{value.mon}/#{value.day}/#{value.year}'"
  else
    super
  end
end
quote_string(string) click to toggle source

TODO: Add some smart quoting for newlines in string and text fields.

# File lib/arjdbc/informix/adapter.rb, line 104
def quote_string(string)
  string.gsub(/\/, "''")
end
remove_index(table_name, options = {}) click to toggle source
# File lib/arjdbc/informix/adapter.rb, line 135
def remove_index(table_name, options = {})
  @connection.execute_update("DROP INDEX #{index_name(table_name, options)}")
end
rename_table(name, new_name) click to toggle source
# File lib/arjdbc/informix/adapter.rb, line 125
def rename_table(name, new_name)
  execute("RENAME TABLE #{name} TO #{new_name}")
  execute("RENAME SEQUENCE #{name}_seq TO #{new_name}_seq")
end
select(sql, *rest) click to toggle source
Calls superclass method
# File lib/arjdbc/informix/adapter.rb, line 139
def select(sql, *rest)
  # Informix does not like "= NULL", "!= NULL", or "<> NULL".
  super(sql.gsub(/(!=|<>)\s*null/i, "IS NOT NULL").gsub(/=\s*null/i, "IS NULL"), *rest)
end
supports_migrations?() click to toggle source
# File lib/arjdbc/informix/adapter.rb, line 82
def supports_migrations?
  true
end

Private Instance Methods

db_major_version() click to toggle source
# File lib/arjdbc/informix/adapter.rb, line 146
def db_major_version
  @@db_major_version ||=
    select_one("SELECT dbinfo('version', 'major') version FROM systables WHERE tabid = 1")['version'].to_i
end