Module: ArJdbc::Informix
- Defined in:
- lib/arjdbc/informix/adapter.rb
Defined Under Namespace
Modules: Column
Constant Summary collapse
- @@_lob_callback_added =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #add_limit_offset!(sql, options) ⇒ Object
- #create_table(name, options = {}) ⇒ Object
- #default_sequence_name(table, column) ⇒ Object
- #drop_table(name) ⇒ Object
- #modify_types(types) ⇒ Object
- #next_sequence_value(sequence_name) ⇒ Object
- #prefetch_primary_key?(table_name = nil) ⇒ Boolean
- #quote(value, column = nil) ⇒ Object
-
#quote_string(string) ⇒ Object
TODO: Add some smart quoting for newlines in string and text fields.
- #remove_index(table_name, options = {}) ⇒ Object
- #rename_table(name, new_name) ⇒ Object
- #select(sql, *rest) ⇒ Object
- #supports_migrations? ⇒ Boolean
Class Method Details
.column_selector ⇒ Object
31 32 33 |
# File 'lib/arjdbc/informix/adapter.rb', line 31 def self.column_selector [ /informix/i, lambda { |cfg, column| column.extend(::ArJdbc::Informix::Column) } ] end |
.extended(base) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 ⇒ Object
35 36 37 |
# File 'lib/arjdbc/informix/adapter.rb', line 35 def self.jdbc_connection_class ::ActiveRecord::ConnectionAdapters::InformixJdbcConnection end |
Instance Method Details
#add_limit_offset!(sql, options) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/arjdbc/informix/adapter.rb', line 81 def add_limit_offset!(sql, ) if [:limit] limit = "FIRST #{[:limit]}" # SKIP available only in IDS >= 10 : offset = (db_major_version >= 10 && [:offset] ? "SKIP #{[:offset]}" : "") sql.sub!(/^\s*?select /i, "SELECT #{offset} #{limit} ") end sql end |
#create_table(name, options = {}) ⇒ Object
111 112 113 114 |
# File 'lib/arjdbc/informix/adapter.rb', line 111 def create_table(name, = {}) super(name, ) execute("CREATE SEQUENCE #{name}_seq") end |
#default_sequence_name(table, column) ⇒ Object
77 78 79 |
# File 'lib/arjdbc/informix/adapter.rb', line 77 def default_sequence_name(table, column) "#{table}_seq" end |
#drop_table(name) ⇒ Object
121 122 123 124 |
# File 'lib/arjdbc/informix/adapter.rb', line 121 def drop_table(name) super(name) execute("DROP SEQUENCE #{name}_seq") end |
#modify_types(types) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/arjdbc/informix/adapter.rb', line 53 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
90 91 92 |
# File 'lib/arjdbc/informix/adapter.rb', line 90 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
69 70 71 |
# File 'lib/arjdbc/informix/adapter.rb', line 69 def prefetch_primary_key?(table_name = nil) true end |
#quote(value, column = nil) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/arjdbc/informix/adapter.rb', line 99 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.
95 96 97 |
# File 'lib/arjdbc/informix/adapter.rb', line 95 def quote_string(string) string.gsub(/\'/, "''") end |
#remove_index(table_name, options = {}) ⇒ Object
126 127 128 |
# File 'lib/arjdbc/informix/adapter.rb', line 126 def remove_index(table_name, = {}) @connection.execute_update("DROP INDEX #{index_name(table_name, )}") end |
#rename_table(name, new_name) ⇒ Object
116 117 118 119 |
# File 'lib/arjdbc/informix/adapter.rb', line 116 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
130 131 132 133 |
# File 'lib/arjdbc/informix/adapter.rb', line 130 def select(sql, *rest) # Informix does not like "= NULL", "!= NULL", or "<> NULL". execute(sql.gsub(/(!=|<>)\s*null/i, "IS NOT NULL").gsub(/=\s*null/i, "IS NULL"), *rest) end |
#supports_migrations? ⇒ Boolean
73 74 75 |
# File 'lib/arjdbc/informix/adapter.rb', line 73 def supports_migrations? true end |