Permalink
Browse files

Merge pull request #14 from vizcay/master

improve FbColumn#initialize so that limit, precision & scale get set only for correct column types
  • Loading branch information...
rowland committed Dec 2, 2013
2 parents 17093e2 + d019fe8 commit 8141ea74f79854df331467229716f1c135215fd6
Showing with 13 additions and 2 deletions.
  1. +13 −2 lib/active_record/connection_adapters/fb_adapter.rb
@@ -77,8 +77,14 @@ def initialize(name, domain, type, sub_type, length, precision, scale, default_s
@firebird_type = Fb::SqlType.from_code(type, sub_type || 0)
super(name.downcase, nil, @firebird_type, !null_flag)
@default = parse_default(default_source) if default_source
@limit = (@firebird_type == 'BLOB') ? 10 * 1024 * 1024 : length
@domain, @sub_type, @precision, @scale = domain, sub_type, precision, scale
case @firebird_type
when 'VARCHAR'
@limit = length
when 'BLOB'
@limit = 10 * 1024 * 1024
end
@domain, @sub_type = domain, sub_type
@precision, @scale = precision, scale.abs if ['DECIMAL', 'NUMERIC'].include? @firebird_type
end

def type
@@ -824,6 +830,11 @@ def add_column(table_name, column_name, type, options = {})
add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
add_column_options!(add_column_sql, options)
execute(add_column_sql)
if options[:position]
# position is 1-based but add 1 to skip id column
alter_position_sql = "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} POSITION #{options[:position] + 1}"
execute(alter_position_sql)
end
end

# Changes the column's definition according to the new options.

0 comments on commit 8141ea7

Please sign in to comment.