Class: ActiveRecord::ConnectionAdapters::FbColumn
- Inherits:
-
Column
- Object
- Column
- ActiveRecord::ConnectionAdapters::FbColumn
- Defined in:
- lib/active_record/connection_adapters/fb_adapter.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
-
#default ⇒ Object
Submits a CAST query to the database, casting the default value to the specified SQL type.
-
#initialize(name, domain, type, sub_type, length, precision, scale, default_source, null_flag) ⇒ FbColumn
constructor
A new instance of FbColumn.
- #type ⇒ Object
Constructor Details
#initialize(name, domain, type, sub_type, length, precision, scale, default_source, null_flag) ⇒ FbColumn
Returns a new instance of FbColumn.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 86 def initialize(name, domain, type, sub_type, length, precision, scale, default_source, null_flag) @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 case @firebird_type when 'VARCHAR', 'CHAR' @limit = length when 'DECIMAL', 'NUMERIC' @precision, @scale = precision, scale.abs end @domain, @sub_type = domain, sub_type end |
Class Method Details
.value_to_boolean(value) ⇒ Object
129 130 131 |
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 129 def self.value_to_boolean(value) %W(#{FbAdapter.boolean_domain[:true]} true t 1).include? value.to_s.downcase end |
Instance Method Details
#default ⇒ Object
Submits a CAST query to the database, casting the default value to the specified SQL type. This enables Firebird to provide an actual value when context variables are used as column defaults (such as CURRENT_TIMESTAMP).
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 112 def default if @default sql = "SELECT CAST(#{@default} AS #{column_def}) FROM RDB$DATABASE" connection = ActiveRecord::Base.connection if connection value = connection.select_one(sql)['cast'] if value.acts_like?(:date) or value.acts_like?(:time) nil else type_cast(value) end else raise ConnectionNotEstablished, "No Firebird connections established." end end end |
#type ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/active_record/connection_adapters/fb_adapter.rb', line 99 def type if @domain =~ /BOOLEAN/ :boolean elsif @type == :binary and @sub_type == 1 :text else @type end end |