Class: ActiveRecord::ConnectionAdapters::FirebirdColumn
- Defined in:
- lib/active_record/connection_adapters/firebird_adapter.rb
Overview
:nodoc:
Constant Summary collapse
- VARCHAR_MAX_LENGTH =
32_765
- BLOB_MAX_LENGTH =
32_767
Instance Attribute Summary
Attributes inherited from Column
#limit, #name, #null, #primary, #sql_type
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) ⇒ FirebirdColumn
constructor
A new instance of FirebirdColumn.
- #type ⇒ Object
- #type_cast(value) ⇒ Object
Methods inherited from Column
binary_to_string, #human_name, #klass, #number?, string_to_binary, string_to_date, string_to_dummy_time, string_to_time, #text?, #type_cast_code, value_to_boolean
Constructor Details
#initialize(name, domain, type, sub_type, length, precision, scale, default_source, null_flag) ⇒ FirebirdColumn
Returns a new instance of FirebirdColumn.
46 47 48 49 50 51 52 |
# File 'lib/active_record/connection_adapters/firebird_adapter.rb', line 46 def initialize(name, domain, type, sub_type, length, precision, scale, default_source, null_flag) @firebird_type = FireRuby::SQLType.to_base_type(type, sub_type).to_s super(name.downcase, nil, @firebird_type, !null_flag) @default = parse_default(default_source) if default_source @limit = type == 'BLOB' ? BLOB_MAX_LENGTH : length @domain, @sub_type, @precision, @scale = domain, sub_type, precision, scale 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).
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/active_record/connection_adapters/firebird_adapter.rb', line 67 def default if @default sql = "SELECT CAST(#{@default} AS #{column_def}) FROM RDB$DATABASE" connection = ActiveRecord::Base.active_connections.values.detect { |conn| conn && conn.adapter_name == 'Firebird' } if connection type_cast connection.execute(sql).to_a.first['CAST'] else raise ConnectionNotEstablished, "No Firebird connections established." end end end |
#type ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/active_record/connection_adapters/firebird_adapter.rb', line 54 def type if @domain =~ /BOOLEAN/ :boolean elsif @type == :binary and @sub_type == 1 :text else @type end end |
#type_cast(value) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/active_record/connection_adapters/firebird_adapter.rb', line 79 def type_cast(value) if type == :boolean value == true or value == ActiveRecord::ConnectionAdapters::FirebirdAdapter.boolean_domain[:true] else super end end |