Class: ODBCAdapter::DatabaseMetadata

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

Overview

Caches SQLGetInfo output

Constant Summary collapse

FIELDS =
%i[
  SQL_DBMS_NAME
  SQL_DBMS_VER
  SQL_IDENTIFIER_CASE
  SQL_QUOTED_IDENTIFIER_CASE
  SQL_IDENTIFIER_QUOTE_CHAR
  SQL_MAX_IDENTIFIER_LEN
  SQL_MAX_TABLE_NAME_LEN
  SQL_USER_NAME
  SQL_DATABASE_NAME
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, has_encoding_bug = false) ⇒ DatabaseMetadata

has_encoding_bug refers to github.com/larskanis/ruby-odbc/issues/2 where ruby-odbc in UTF8 mode returns incorrectly encoded responses to getInfo



20
21
22
23
24
25
26
27
# File 'lib/odbc_adapter/database_metadata.rb', line 20

def initialize(connection, has_encoding_bug = false)
  @values = Hash[FIELDS.map do |field|
    info = connection.get_info(ODBC.const_get(field))
    info = info.encode(Encoding.default_external, 'UTF-16LE') if info.is_a?(String) && has_encoding_bug

    [field, info]
  end]
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



16
17
18
# File 'lib/odbc_adapter/database_metadata.rb', line 16

def values
  @values
end

Instance Method Details

#adapter_classObject



29
30
31
# File 'lib/odbc_adapter/database_metadata.rb', line 29

def adapter_class
  ODBCAdapter.adapter_for(dbms_name)
end

#upcase_identifiers?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/odbc_adapter/database_metadata.rb', line 33

def upcase_identifiers?
  @upcase_identifiers ||= (identifier_case == ODBC::SQL_IC_UPPER)
end