Class: ActiveRecord::ConnectionAdapters::ODBCAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::ODBCAdapter
- Includes:
- ODBCAdapter::DatabaseLimits, ODBCAdapter::DatabaseStatements, ODBCAdapter::Quoting, ODBCAdapter::SchemaStatements
- Defined in:
- lib/active_record/connection_adapters/odbc_adapter.rb
Direct Known Subclasses
ODBCAdapter::Adapters::MySQLODBCAdapter, ODBCAdapter::Adapters::NullODBCAdapter, ODBCAdapter::Adapters::PostgreSQLODBCAdapter
Constant Summary collapse
- ADAPTER_NAME =
'ODBC'.freeze
- BOOLEAN_TYPE =
'BOOLEAN'.freeze
- ERR_DUPLICATE_KEY_VALUE =
23_505
- ERR_QUERY_TIMED_OUT =
57_014
- ERR_QUERY_TIMED_OUT_MESSAGE =
/Query has timed out/
- ERR_CONNECTION_FAILED_REGEX =
'^08[0S]0[12347]'.freeze
- ERR_CONNECTION_FAILED_MESSAGE =
/Client connection failed/
Constants included from ODBCAdapter::DatabaseStatements
ODBCAdapter::DatabaseStatements::SQL_NO_NULLS, ODBCAdapter::DatabaseStatements::SQL_NULLABLE, ODBCAdapter::DatabaseStatements::SQL_NULLABLE_UNKNOWN
Instance Attribute Summary collapse
-
#database_metadata ⇒ Object
readonly
The object that stores the information that is fetched from the DBMS when a connection is first established.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Checks whether the connection to the database is still active.
-
#adapter_name ⇒ Object
Returns the human-readable name of the adapter.
-
#disconnect! ⇒ Object
Disconnects from the database if already connected.
-
#initialize(connection, logger, config, database_metadata) ⇒ ODBCAdapter
constructor
A new instance of ODBCAdapter.
-
#new_column(name, default, sql_type_metadata, null, table_name, default_function = nil, collation = nil, native_type = nil) ⇒ Object
Build a new column object from the given options.
-
#reconnect! ⇒ Object
(also: #reset!)
Disconnects from the database if already connected, and establishes a new connection with the database.
-
#supports_migrations? ⇒ Boolean
Does this adapter support migrations? Backend specific, as the abstract adapter always returns
false
.
Methods included from ODBCAdapter::SchemaStatements
#columns, #current_database, #foreign_keys, #index_name, #indexes, #native_database_types, #primary_key, #tables, #views
Methods included from ODBCAdapter::Quoting
#quote_column_name, #quote_string, #quoted_date
Methods included from ODBCAdapter::DatabaseStatements
#begin_db_transaction, #commit_db_transaction, #default_sequence_name, #exec_delete, #exec_query, #exec_rollback_db_transaction, #execute
Methods included from ODBCAdapter::DatabaseLimits
Constructor Details
#initialize(connection, logger, config, database_metadata) ⇒ ODBCAdapter
Returns a new instance of ODBCAdapter.
89 90 91 92 93 |
# File 'lib/active_record/connection_adapters/odbc_adapter.rb', line 89 def initialize(connection, logger, config, ) (connection) super(connection, logger, config) @database_metadata = end |
Instance Attribute Details
#database_metadata ⇒ Object (readonly)
The object that stores the information that is fetched from the DBMS when a connection is first established.
87 88 89 |
# File 'lib/active_record/connection_adapters/odbc_adapter.rb', line 87 def @database_metadata end |
Instance Method Details
#active? ⇒ Boolean
Checks whether the connection to the database is still active. This includes checking whether the database is actually capable of responding, i.e. whether the connection isn’t stale.
111 112 113 |
# File 'lib/active_record/connection_adapters/odbc_adapter.rb', line 111 def active? @connection.connected? end |
#adapter_name ⇒ Object
Returns the human-readable name of the adapter.
96 97 98 |
# File 'lib/active_record/connection_adapters/odbc_adapter.rb', line 96 def adapter_name ADAPTER_NAME end |
#disconnect! ⇒ Object
Disconnects from the database if already connected. Otherwise, this method does nothing.
133 134 135 |
# File 'lib/active_record/connection_adapters/odbc_adapter.rb', line 133 def disconnect! @connection.disconnect if @connection.connected? end |
#new_column(name, default, sql_type_metadata, null, table_name, default_function = nil, collation = nil, native_type = nil) ⇒ Object
Build a new column object from the given options. Effectively the same as super except that it also passes in the native type. rubocop:disable Metrics/ParameterLists
140 141 142 |
# File 'lib/active_record/connection_adapters/odbc_adapter.rb', line 140 def new_column(name, default, , null, table_name, default_function = nil, collation = nil, native_type = nil) ::ODBCAdapter::Column.new(name, default, , null, table_name, default_function, collation, native_type) end |
#reconnect! ⇒ Object Also known as: reset!
Disconnects from the database if already connected, and establishes a new connection with the database.
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/active_record/connection_adapters/odbc_adapter.rb', line 117 def reconnect! disconnect! odbc_module = @config[:encoding] == 'utf8' ? ODBC_UTF8 : ODBC @connection = if @config.key?(:dsn) odbc_module.connect(@config[:dsn], @config[:username], @config[:password]) else odbc_module::Database.new.drvconnect(@config[:driver]) end (@connection) super end |
#supports_migrations? ⇒ Boolean
Does this adapter support migrations? Backend specific, as the abstract adapter always returns false
.
102 103 104 |
# File 'lib/active_record/connection_adapters/odbc_adapter.rb', line 102 def supports_migrations? true end |