Module: JdbcSpec::Informix
- Defined in:
- lib/jdbc_adapter/jdbc_informix.rb
Defined Under Namespace
Modules: Column
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(tp) ⇒ 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
- #supports_migrations? ⇒ Boolean
Class Method Details
.adapter_matcher(name) ⇒ Object
43 44 45 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 43 def self.adapter_matcher(name, *) name =~ /informix/i ? self : false end |
.column_selector ⇒ Object
47 48 49 50 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 47 def self.column_selector [ /informix/i, lambda { |cfg, column| column.extend(::JdbcSpec::Informix::Column) } ] end |
.extended(base) ⇒ Object
39 40 41 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 39 def self.extended(base) @@db_major_version = base.select_one("SELECT dbinfo('version', 'major') version FROM systables WHERE tabid = 1")['version'].to_i end |
Instance Method Details
#add_limit_offset!(sql, options) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 91 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!(/^select /i, "SELECT #{offset} #{limit} ") end sql end |
#create_table(name, options = {}) ⇒ Object
122 123 124 125 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 122 def create_table(name, = {}) super(name, ) execute("CREATE SEQUENCE #{name}_seq") end |
#default_sequence_name(table, column) ⇒ Object
87 88 89 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 87 def default_sequence_name(table, column) "#{table}_seq" end |
#drop_table(name) ⇒ Object
132 133 134 135 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 132 def drop_table(name) super(name) execute("DROP SEQUENCE #{name}_seq") end |
#modify_types(tp) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 64 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
102 103 104 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 102 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
79 80 81 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 79 def prefetch_primary_key?(table_name = nil) true end |
#quote(value, column = nil) ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 111 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.
107 108 109 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 107 def quote_string(string) string.gsub(/\'/, "''") end |
#remove_index(table_name, options = {}) ⇒ Object
137 138 139 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 137 def remove_index(table_name, = {}) @connection.execute_update("DROP INDEX #{index_name(table_name, )}") end |
#rename_table(name, new_name) ⇒ Object
127 128 129 130 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 127 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
83 84 85 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 83 def supports_migrations? true end |