Module: ActiveRecord::ConnectionAdapters::SchemaStatements

Defined in:
lib/active_record/connection_adapters/jdbc_adapter.rb

Instance Method Summary collapse

Instance Method Details

#type_to_sql(type, limit = nil, precision = nil, scale = nil) ⇒ Object

Convert the speficied column type to a SQL string.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 15

def type_to_sql(type, limit = nil, precision = nil, scale = nil)
  if native = native_database_types[type]
    column_type_sql = (native.is_a?(Hash) ? native[:name] : native).dup

    if type == :decimal # ignore limit, use precision and scale
      scale ||= native[:scale]

      if precision ||= native[:precision]
        if scale
          column_type_sql << "(#{precision},#{scale})"
        else
          column_type_sql << "(#{precision})"
        end
      elsif scale
        raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified"
      end

    elsif limit ||= native.is_a?(Hash) && native[:limit]
      column_type_sql << "(#{limit})"
    end

    column_type_sql
  else
    type
  end
end