Module: ArJdbc::Informix

Included in:
ActiveRecord::ConnectionAdapters::InformixAdapter
Defined in:
lib/arjdbc/informix/adapter.rb

Constant Summary collapse

JdbcConnection =
::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
@@_lob_callback_added =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.jdbc_connection_classObject



34
35
36
# File 'lib/arjdbc/informix/adapter.rb', line 34

def self.jdbc_connection_class
  ::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
end

Instance Method Details

#add_limit_offset!(sql, options) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/arjdbc/informix/adapter.rb', line 71

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

#create_table(name, options = {}) ⇒ Object



101
102
103
104
# File 'lib/arjdbc/informix/adapter.rb', line 101

def create_table(name, options = {})
  super(name, options)
  execute("CREATE SEQUENCE #{name}_seq")
end

#default_sequence_name(table, column) ⇒ Object



67
68
69
# File 'lib/arjdbc/informix/adapter.rb', line 67

def default_sequence_name(table, column)
  "#{table}_seq"
end

#drop_table(name) ⇒ Object



111
112
113
114
# File 'lib/arjdbc/informix/adapter.rb', line 111

def drop_table(name)
  super(name)
  execute("DROP SEQUENCE #{name}_seq")
end

#jdbc_column_classObject



39
40
41
# File 'lib/arjdbc/informix/adapter.rb', line 39

def jdbc_column_class
  ::ActiveRecord::ConnectionAdapters::InformixColumn
end

#modify_types(types) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/arjdbc/informix/adapter.rb', line 43

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) ⇒ Object



80
81
82
# File 'lib/arjdbc/informix/adapter.rb', line 80

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) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/arjdbc/informix/adapter.rb', line 59

def prefetch_primary_key?(table_name = nil)
  true
end

#quote(value, column = nil) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/arjdbc/informix/adapter.rb', line 89

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) ⇒ Object

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



85
86
87
# File 'lib/arjdbc/informix/adapter.rb', line 85

def quote_string(string)
  string.gsub(/\'/, "''")
end

#remove_index(table_name, options = {}) ⇒ Object



116
117
118
# File 'lib/arjdbc/informix/adapter.rb', line 116

def remove_index(table_name, options = {})
  @connection.execute_update("DROP INDEX #{index_name(table_name, options)}")
end

#rename_table(name, new_name) ⇒ Object



106
107
108
109
# File 'lib/arjdbc/informix/adapter.rb', line 106

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) ⇒ Object



120
121
122
123
# File 'lib/arjdbc/informix/adapter.rb', line 120

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?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/arjdbc/informix/adapter.rb', line 63

def supports_migrations?
  true
end