Skip to content

Commit

Permalink
The Informix adapter now uses sequences to generate ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivern committed Nov 10, 2008
1 parent 1496aa2 commit cd01972
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions lib/jdbc_adapter/jdbc_informix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def simplified_type(field_type)
end
end

# TODO: Look into using sequences instead for the PKs.
def modify_types(tp)
tp[:primary_key] = "SERIAL PRIMARY KEY"
tp[:string] = { :name => "VARCHAR", :limit => 255 }
Expand All @@ -78,6 +77,18 @@ def modify_types(tp)
tp
end

def prefetch_primary_key?(table_name = nil)
true
end

def supports_migrations?
true
end

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

def add_limit_offset!(sql, options)
if options[:limit]
limit = "FIRST #{options[:limit]}"
Expand All @@ -89,6 +100,10 @@ def add_limit_offset!(sql, options)
sql
end

def next_sequence_value(sequence_name)
select_one("SELECT #{sequence_name}.nextval id FROM systables WHERE tabid=1")['id']
end

# TODO: Add some smart quoting for newlines in string and text fields.
def quote_string(string)
string.gsub(/\'/, "''")
Expand All @@ -105,8 +120,19 @@ def quote(value, column = nil)
end
end

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

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

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

def remove_index(table_name, options = {})
Expand Down

0 comments on commit cd01972

Please sign in to comment.