All the concrete database adapters follow the interface laid down in this class. You can use this interface directly by borrowing the database connection from the Base with ActiveRecord::Base.connection.
Most of the methods in the adapter are useful during migrations. Most notably, ActiveRecord::ConnectionAdapters::SchemaStatements#create_table, ActiveRecord::ConnectionAdapters::SchemaStatements#drop_table, ActiveRecord::ConnectionAdapters::SchemaStatements#add_index, ActiveRecord::ConnectionAdapters::SchemaStatements#remove_index, ActiveRecord::ConnectionAdapters::SchemaStatements#add_column, ActiveRecord::ConnectionAdapters::SchemaStatements#change_column and ActiveRecord::ConnectionAdapters::SchemaStatements#remove_column are very useful.
- A
- D
- F
- L
- P
- R
- S
- V
- ActiveRecord::ConnectionAdapters::Quoting
- ActiveRecord::ConnectionAdapters::DatabaseStatements
- ActiveRecord::ConnectionAdapters::SchemaStatements
Is this connection active and ready to perform queries?
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 68 def active? @active != false end
Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 35 def adapter_name 'Abstract' end
Close this connection
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 78 def disconnect! @active = false end
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.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 55 def prefetch_primary_key?(table_name = nil) false end
Provides access to the underlying database connection. Useful for when you need to call a proprietary method such as postgresql’s lo_* methods
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 101 def raw_connection @connection end
Close this connection and open a new one in its place.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 73 def reconnect! @active = true end
Returns true if its safe to reload the connection between requests for development mode. This is not the case for Ruby/MySQL and it’s not necessary for any adapters except SQLite.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 84 def requires_reloading? false end
Does this adapter support using DISTINCT within COUNT? This is
true
for all adapters except sqlite.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 47 def supports_count_distinct? true end
Does this adapter support migrations? Backend specific, as the abstract
adapter always returns false
.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 41 def supports_migrations? false end
Lazily verify this connection, calling active?
only if it
hasn’t been called for timeout
seconds.
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 90 def verify!(timeout) now = Time.now.to_i if (now - @last_verification) > timeout reconnect! unless active? @last_verification = now end end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 142 def format_log_entry(message, dump = nil) if ActiveRecord::Base.colorize_logging if @@row_even @@row_even = false message_color, dump_color = "4;36;1", "0;1" else @@row_even = true message_color, dump_color = "4;35;1", "0" end log_entry = " \e[#{message_color}m#{message}\e[0m " log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump log_entry else "%s %s" % [message, dump] end end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 106 def log(sql, name) if block_given? if @logger and @logger.level <= Logger::INFO result = nil seconds = Benchmark.realtime { result = yield } @runtime += seconds log_info(sql, name, seconds) result else yield end else log_info(sql, name, 0) nil end rescue Exception => e # Log message and raise exception. # Set last_verfication to 0, so that connection gets verified # upon reentering the request loop @last_verification = 0 message = "#{e.class.name}: #{e.message}: #{sql}" log_info(message, name, 0) raise ActiveRecord::StatementInvalid, message end
Source: show
# File rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 131 def log_info(sql, name, runtime) return unless @logger @logger.debug( format_log_entry( "#{name.nil? ? "SQL" : name} (#{sprintf("%f", runtime)})", sql.gsub(%r +/, " ") ) ) end