Class: SnowflakeOdbcAdapter::ColumnMetadata

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

Overview

:nodoc:

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 ],
  json: [ 2004 ]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter) ⇒ ColumnMetadata

Returns a new instance of ColumnMetadata.



26
27
28
# File 'lib/snowflake_odbc_adapter/column_metadata.rb', line 26

def initialize(adapter)
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



24
25
26
# File 'lib/snowflake_odbc_adapter/column_metadata.rb', line 24

def adapter
  @adapter
end

Instance Method Details

#native_database_typesObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/snowflake_odbc_adapter/column_metadata.rb', line 30

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