Class: ActiveRecord::ConnectionAdapters::InformixAdapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/active_record/connection_adapters/informix_adapter.rb

Overview

This adapter requires Ruby/Informix ruby-informix.rubyforge.org

Options:

  • :database – Defaults to nothing.

  • :username – Defaults to nothing.

  • :password – Defaults to nothing.

Instance Method Summary collapse

Constructor Details

#initialize(db, logger) ⇒ InformixAdapter

Returns a new instance of InformixAdapter.



110
111
112
113
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 110

def initialize(db, logger)
  super
  @ifx_version = db.version.major.to_i
end

Instance Method Details

#adapter_nameObject



132
133
134
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 132

def adapter_name
  'Informix'
end

#add_limit_offset!(sql, options) ⇒ Object



187
188
189
190
191
192
193
194
195
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 187

def add_limit_offset!(sql, options)
  if options[:limit]
    limit = "FIRST #{options[:limit]}"
    # SKIP available only in IDS >= 10
    offset = @ifx_version >= 10 && options[:offset]? "SKIP #{options[:offset]}": ""
    sql.sub!(/^select /i,"SELECT #{offset} #{limit} ")
  end
  sql
end

#begin_db_transactionObject



175
176
177
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 175

def begin_db_transaction
  execute("begin work")
end

#change_column(table_name, column_name, type, options = {}) ⇒ Object

:nodoc:



267
268
269
270
271
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 267

def change_column(table_name, column_name, type, options = {}) #:nodoc:
  sql = "ALTER TABLE #{table_name} MODIFY #{column_name} #{type_to_sql(type, options[:limit])}"
  add_column_options!(sql, options)
  execute(sql)
end

#columns(table_name, name = nil) ⇒ Object



225
226
227
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 225

def columns(table_name, name = nil)
  @connection.columns(table_name).map {|col| InformixColumn.new(col) }
end

#commit_db_transactionObject



179
180
181
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 179

def commit_db_transaction
  @connection.commit
end

#create_database(name) ⇒ Object



239
240
241
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 239

def create_database(name)
  execute("create database #{name}")
end

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



248
249
250
251
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 248

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

#default_sequence_name(table, column) ⇒ Object

:nodoc:



144
145
146
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 144

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

#drop_database(name) ⇒ Object



235
236
237
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 235

def drop_database(name)
  execute("drop database #{name}")
end

#drop_table(name) ⇒ Object



258
259
260
261
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 258

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

#execute(sql, name = nil) ⇒ Object Also known as: update, delete



159
160
161
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 159

def execute(sql, name = nil)
  log(sql, name) { @connection.immediate(sql) }
end

#indexes(table_name, name = nil) ⇒ Object

XXX



244
245
246
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 244

def indexes(table_name, name = nil)
  indexes = []
end

#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object



167
168
169
170
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 167

def insert(sql, name= nil, pk= nil, id_value= nil, sequence_name = nil)
  execute(sql)
  id_value
end

#native_database_typesObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 115

def native_database_types
  {
    :primary_key => "serial primary key",
    :string      => { :name => "varchar", :limit => 255  },
    :text        => { :name => "text" },
    :integer     => { :name => "integer" },
    :float       => { :name => "float" },
    :decimal     => { :name => "decimal" },
    :datetime    => { :name => "datetime year to second" },
    :timestamp   => { :name => "datetime year to second" },
    :time        => { :name => "datetime hour to second" },
    :date        => { :name => "date" },
    :binary      => { :name => "byte"},
    :boolean     => { :name => "boolean"}
  }
end

#next_sequence_value(sequence_name) ⇒ Object



197
198
199
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 197

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)


136
137
138
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 136

def prefetch_primary_key?(table_name = nil)
  true
end

#prepare(sql, name = nil) ⇒ Object



163
164
165
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 163

def prepare(sql, name = nil)
  log(sql, name) { @connection.prepare(sql) }
end

#quote(value, column = nil) ⇒ Object



206
207
208
209
210
211
212
213
214
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 206

def quote(value, column = nil)
  if column && [:binary, :text].include?(column.type)
    return "NULL"
  end
  if column && column.type == :date
    return "'#{value.mon}/#{value.day}/#{value.year}'"
  end
  super
end

#quote_string(string) ⇒ Object

QUOTING ===========================================



202
203
204
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 202

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

#recreate_database(name) ⇒ Object

MIGRATION =========================================



230
231
232
233
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 230

def recreate_database(name)
  drop_database(name)
  create_database(name)
end

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



273
274
275
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 273

def remove_index(table_name, options = {})
  execute("DROP INDEX #{index_name(table_name, options)}")
end

#rename_column(table, column, new_column_name) ⇒ Object



263
264
265
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 263

def rename_column(table, column, new_column_name)
  execute("RENAME COLUMN #{table}.#{column} TO #{new_column_name}")
end

#rename_table(name, new_name) ⇒ Object



253
254
255
256
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 253

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

#rollback_db_transactionObject



183
184
185
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 183

def rollback_db_transaction
  @connection.rollback
end

#select_all(sql, name = nil) ⇒ Object

DATABASE STATEMENTS =====================================



149
150
151
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 149

def select_all(sql, name = nil)
  select(sql, name)
end

#select_one(sql, name = nil) ⇒ Object



153
154
155
156
157
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 153

def select_one(sql, name = nil)
  add_limit!(sql, :limit => 1)
  result = select(sql, name)
  result.first if result
end

#structure_dropObject



282
283
284
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 282

def structure_drop
  super
end

#structure_dumpObject

XXX



278
279
280
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 278

def structure_dump
  super
end

#supports_migrations?Boolean

:nodoc:

Returns:

  • (Boolean)


140
141
142
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 140

def supports_migrations? #:nodoc:
  true
end

#tables(name = nil) ⇒ Object

SCHEMA STATEMENTS =====================================



217
218
219
220
221
222
223
# File 'lib/active_record/connection_adapters/informix_adapter.rb', line 217

def tables(name = nil)
  @connection.cursor(<<-end_sql) do |cur|
      SELECT tabname FROM systables WHERE tabid > 99 AND tabtype != 'Q'
    end_sql
    cur.open.fetch_all.flatten
  end
end