Module: ArJdbc::Informix

Defined in:
lib/arjdbc/informix/adapter.rb

Defined Under Namespace

Modules: Column

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.column_selectorObject



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

def self.column_selector
  [ /informix/i,
    lambda { |cfg, column| column.extend(::ArJdbc::Informix::Column) } ]
end

.extended(base) ⇒ Object



30
31
32
# File 'lib/arjdbc/informix/adapter.rb', line 30

def self.extended(base)
  @@db_major_version = base.select_one("SELECT dbinfo('version', 'major') version FROM systables WHERE tabid = 1")['version'].to_i
end

.jdbc_connection_classObject



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

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

Instance Method Details

#add_limit_offset!(sql, options) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/arjdbc/informix/adapter.rb', line 82

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!(/^select /i, "SELECT #{offset} #{limit} ")
  end
  sql
end

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



113
114
115
116
# File 'lib/arjdbc/informix/adapter.rb', line 113

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

#default_sequence_name(table, column) ⇒ Object



78
79
80
# File 'lib/arjdbc/informix/adapter.rb', line 78

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

#drop_table(name) ⇒ Object



123
124
125
126
# File 'lib/arjdbc/informix/adapter.rb', line 123

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

#modify_types(tp) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/arjdbc/informix/adapter.rb', line 55

def modify_types(tp)
  tp[:primary_key] = "SERIAL PRIMARY KEY"
  tp[:string]      = { :name => "VARCHAR", :limit => 255 }
  tp[:integer]     = { :name => "INTEGER" }
  tp[:float]       = { :name => "FLOAT" }
  tp[:decimal]     = { :name => "DECIMAL" }
  tp[:datetime]    = { :name => "DATETIME YEAR TO FRACTION(5)" }
  tp[:timestamp]   = { :name => "DATETIME YEAR TO FRACTION(5)" }
  tp[:time]        = { :name => "DATETIME HOUR TO FRACTION(5)" }
  tp[:date]        = { :name => "DATE" }
  tp[:binary]      = { :name => "BYTE" }
  tp[:boolean]     = { :name => "BOOLEAN" }
  tp
end

#next_sequence_value(sequence_name) ⇒ Object



93
94
95
# File 'lib/arjdbc/informix/adapter.rb', line 93

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)


70
71
72
# File 'lib/arjdbc/informix/adapter.rb', line 70

def prefetch_primary_key?(table_name = nil)
  true
end

#quote(value, column = nil) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/arjdbc/informix/adapter.rb', line 102

def quote(value, column = nil)
  if column && [:binary, :text].include?(column.type)
    # LOBs are updated separately by an after_save trigger.
    "NULL"
  elsif column && 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.



98
99
100
# File 'lib/arjdbc/informix/adapter.rb', line 98

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

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



128
129
130
# File 'lib/arjdbc/informix/adapter.rb', line 128

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

#rename_table(name, new_name) ⇒ Object



118
119
120
121
# File 'lib/arjdbc/informix/adapter.rb', line 118

def rename_table(name, new_name)
  execute("RENAME TABLE #{name} TO #{new_name}")
  execute("RENAME SEQUENCE #{name}_seq TO #{new_name}_seq")
end

#supports_migrations?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/arjdbc/informix/adapter.rb', line 74

def supports_migrations?
  true
end