Class ActiveRecord::ConnectionAdapters::AbstractAdapter
In: vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
Parent: Object

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 Base.connection.

Most of the methods in the adapter are useful during migrations. Most notably, SchemaStatements#create_table, SchemaStatements#drop_table, SchemaStatements#add_index, SchemaStatements#remove_index, SchemaStatements#add_column, SchemaStatements#change_column and SchemaStatements#remove_column are very useful.

Methods

Included Modules

Quoting DatabaseStatements SchemaStatements

Public Instance methods

Is this connection active and ready to perform queries?

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 68
68:       def active?
69:         @active != false
70:       end

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

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 35
35:       def adapter_name
36:         'Abstract'
37:       end

Close this connection

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 78
78:       def disconnect!
79:         @active = false
80:       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]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 55
55:       def prefetch_primary_key?(table_name = nil)
56:         false
57:       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]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 95
95:       def raw_connection
96:         @connection
97:       end

Close this connection and open a new one in its place.

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 73
73:       def reconnect!
74:         @active = true
75:       end

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

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 47
47:       def supports_count_distinct?
48:         true
49:       end

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

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 41
41:       def supports_migrations?
42:         false
43:       end

Lazily verify this connection, calling +active?+ only if it hasn’t been called for timeout seconds.

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 84
84:       def verify!(timeout)
85:         now = Time.now.to_i
86:         if (now - @last_verification) > timeout
87:           reconnect! unless active?
88:           @last_verification = now
89:         end
90:       end

Protected Instance methods

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 136
136:         def format_log_entry(message, dump = nil)
137:           if ActiveRecord::Base.colorize_logging
138:             if @@row_even
139:               @@row_even = false
140:               message_color, dump_color = "4;36;1", "0;1"
141:             else
142:               @@row_even = true
143:               message_color, dump_color = "4;35;1", "0"
144:             end
145: 
146:             log_entry = "  \e[#{message_color}m#{message}\e[0m   "
147:             log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
148:             log_entry
149:           else
150:             "%s  %s" % [message, dump]
151:           end
152:         end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 100
100:         def log(sql, name)
101:           if block_given?
102:             if @logger and @logger.level <= Logger::INFO
103:               result = nil
104:               seconds = Benchmark.realtime { result = yield }
105:               @runtime += seconds
106:               log_info(sql, name, seconds)
107:               result
108:             else
109:               yield
110:             end
111:           else
112:             log_info(sql, name, 0)
113:             nil
114:           end
115:         rescue Exception => e
116:           # Log message and raise exception.
117:           # Set last_verfication to 0, so that connection gets verified
118:           # upon reentering the request loop
119:           @last_verification = 0
120:           message = "#{e.class.name}: #{e.message}: #{sql}"
121:           log_info(message, name, 0)
122:           raise ActiveRecord::StatementInvalid, message
123:         end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 125
125:         def log_info(sql, name, runtime)
126:           return unless @logger
127: 
128:           @logger.debug(
129:             format_log_entry(
130:               "#{name.nil? ? "SQL" : name} (#{sprintf("%f", runtime)})",
131:               sql.gsub(/ +/, " ")
132:             )
133:           )
134:         end

[Validate]