Class: ODBCAdapter::ColumnMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/odbc_adapter/column_metadata.rb

Constant Summary collapse

GENERICS =
{
  primary_key: [ODBC::SQL_INTEGER, ODBC::SQL_SMALLINT],
  string:      [ODBC::SQL_VARCHAR],
  text:        [ODBC::SQL_LONGVARCHAR, ODBC::SQL_VARCHAR],
  integer:     [ODBC::SQL_INTEGER, ODBC::SQL_SMALLINT],
  decimal:     [ODBC::SQL_NUMERIC, ODBC::SQL_DECIMAL],
  float:       [ODBC::SQL_DOUBLE, ODBC::SQL_REAL],
  datetime:    [ODBC::SQL_TYPE_TIMESTAMP, ODBC::SQL_TIMESTAMP],
  timestamp:   [ODBC::SQL_TYPE_TIMESTAMP, ODBC::SQL_TIMESTAMP],
  time:        [ODBC::SQL_TYPE_TIME, ODBC::SQL_TIME, ODBC::SQL_TYPE_TIMESTAMP, ODBC::SQL_TIMESTAMP],
  date:        [ODBC::SQL_TYPE_DATE, ODBC::SQL_DATE, ODBC::SQL_TYPE_TIMESTAMP, ODBC::SQL_TIMESTAMP],
  binary:      [ODBC::SQL_LONGVARBINARY, ODBC::SQL_VARBINARY],
  boolean:     [ODBC::SQL_BIT, ODBC::SQL_TINYINT, ODBC::SQL_SMALLINT, ODBC::SQL_INTEGER]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter) ⇒ ColumnMetadata

Returns a new instance of ColumnMetadata.



20
21
22
# File 'lib/odbc_adapter/column_metadata.rb', line 20

def initialize(adapter)
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



18
19
20
# File 'lib/odbc_adapter/column_metadata.rb', line 18

def adapter
  @adapter
end

Instance Method Details

#native_database_typesObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/odbc_adapter/column_metadata.rb', line 24

def native_database_types
  grouped = reported_types.group_by { |row| row[1] }

  GENERICS.each_with_object({}) do |(abstract, candidates), mapped|
    candidates.detect do |candidate|
      next unless grouped[candidate]
      mapped[abstract] = native_type_mapping(abstract, grouped[candidate])
    end
  end
end