ActiveRecord supports multiple database systems. AbstractAdapter and related classes form the abstraction layer which makes this possible. An AbstractAdapter represents a connection to a database, and provides an abstract interface for database-specific functionality such as establishing a connection, escaping values, building the right SQL fragments for ’:offset’ and ’:limit’ options, etc.

All the concrete database adapters follow the interface laid down in this class. ActiveRecord::Base.connection returns an AbstractAdapter object, which you can use.

Most of the methods in the adapter are useful during migrations. Most notably, the instance methods provided by SchemaStatement are very useful.

Methods
Included Modules
Public Instance methods
active?()

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.

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 108
108:       def active?
109:         @active != false
110:       end
adapter_name()

Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 47
47:       def adapter_name
48:         'Abstract'
49:       end
create_savepoint()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 173
173:       def create_savepoint
174:       end
current_savepoint_name()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 182
182:       def current_savepoint_name
183:         "active_record_#{open_transactions}"
184:       end
decrement_open_transactions()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 165
165:       def decrement_open_transactions
166:         @open_transactions -= 1
167:       end
disable_referential_integrity() {|| ...}

Override to turn off referential integrity while executing &block.

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 99
 99:       def disable_referential_integrity(&block)
100:         yield
101:       end
disconnect!()

Disconnects from the database if already connected. Otherwise, this method does nothing.

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 120
120:       def disconnect!
121:         @active = false
122:       end
increment_open_transactions()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 160
160:       def increment_open_transactions
161:         @open_transactions ||= 0
162:         @open_transactions += 1
163:       end
log_info(sql, name, ms)
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 186
186:       def log_info(sql, name, ms)
187:         if @logger && @logger.debug?
188:           name = '%s (%.1fms)' % [name || 'SQL', ms]
189:           @logger.debug(format_log_entry(name, sql.squeeze(' ')))
190:         end
191:       end
open_transactions()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 156
156:       def open_transactions
157:         @open_transactions ||= 0
158:       end
prefetch_primary_key?(table_name = nil)

Should primary key values be selected from their corresponding sequence before the insert statement? If true, next_sequence_value is called before each insert to set the record‘s primary key. This is false for all adapters but Firebird.

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 80
80:       def prefetch_primary_key?(table_name = nil)
81:         false
82:       end
quote_table_name(name)

Override to return the quoted table name. Defaults to column quoting.

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 92
92:       def quote_table_name(name)
93:         quote_column_name(name)
94:       end
raw_connection()

Provides access to the underlying database driver for this adapter. For example, this method returns a Mysql object in case of MysqlAdapter, and a PGconn object in case of PostgreSQLAdapter.

This is useful for when you need to call a proprietary method such as PostgreSQL‘s lo_* methods.

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 152
152:       def raw_connection
153:         @connection
154:       end
reconnect!()

Disconnects from the database if already connected, and establishes a new connection with the database.

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 114
114:       def reconnect!
115:         @active = true
116:       end
release_savepoint()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 179
179:       def release_savepoint
180:       end
requires_reloading?()

Returns true if its safe to reload the connection between requests for development mode.

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 135
135:       def requires_reloading?
136:         true
137:       end
reset!()

Reset the state of this connection, directing the DBMS to clear transactions and other connection-related server-side state. Usually a database-dependent operation.

The default implementation does nothing; the implementation should be overridden by concrete adapters.

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 130
130:       def reset!
131:         # this should be overridden by concrete adapters
132:       end
rollback_to_savepoint()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 176
176:       def rollback_to_savepoint
177:       end
supports_count_distinct?()

Does this adapter support using DISTINCT within COUNT? This is true for all adapters except sqlite.

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 59
59:       def supports_count_distinct?
60:         true
61:       end
supports_ddl_transactions?()

Does this adapter support DDL rollbacks in transactions? That is, would CREATE TABLE or ALTER TABLE get rolled back by a transaction? PostgreSQL, SQL Server, and others support this. MySQL and others do not.

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 66
66:       def supports_ddl_transactions?
67:         false
68:       end
supports_migrations?()

Does this adapter support migrations? Backend specific, as the abstract adapter always returns false.

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 53
53:       def supports_migrations?
54:         false
55:       end
supports_savepoints?()

Does this adapter support savepoints? PostgreSQL and MySQL do, SQLite does not.

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 72
72:       def supports_savepoints?
73:         false
74:       end
transaction_joinable=(joinable)
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 169
169:       def transaction_joinable=(joinable)
170:         @transaction_joinable = joinable
171:       end
verify!(*ignored)

Checks whether the connection to the database is still active (i.e. not stale). This is done under the hood by calling active?. If the connection is no longer active, then this method will reconnect to the database.

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 142
142:       def verify!(*ignored)
143:         reconnect! unless active?
144:       end
Protected Instance methods
format_log_entry(message, dump = nil)
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 215
215:         def format_log_entry(message, dump = nil)
216:           if ActiveRecord::Base.colorize_logging
217:             if @@row_even
218:               @@row_even = false
219:               message_color, dump_color = "4;36;1", "0;1"
220:             else
221:               @@row_even = true
222:               message_color, dump_color = "4;35;1", "0"
223:             end
224: 
225:             log_entry = "  \e[#{message_color}m#{message}\e[0m   "
226:             log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
227:             log_entry
228:           else
229:             "%s  %s" % [message, dump]
230:           end
231:         end
log(sql, name) {|| ...}
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 194
194:         def log(sql, name)
195:           if block_given?
196:             result = nil
197:             ms = Benchmark.ms { result = yield }
198:             @runtime += ms
199:             log_info(sql, name, ms)
200:             result
201:           else
202:             log_info(sql, name, 0)
203:             nil
204:           end
205:         rescue Exception => e
206:           # Log message and raise exception.
207:           # Set last_verification to 0, so that connection gets verified
208:           # upon reentering the request loop
209:           @last_verification = 0
210:           message = "#{e.class.name}: #{e.message}: #{sql}"
211:           log_info(message, name, 0)
212:           raise ActiveRecord::StatementInvalid, message
213:         end