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 QueryCache

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 84
84:       def active?
85:         @active != false
86:       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 38
38:       def adapter_name
39:         'Abstract'
40:       end

Override to turn off referential integrity while executing &block.

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 77
77:       def disable_referential_integrity(&block)
78:         yield
79:       end

Close this connection

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 94
94:       def disconnect!
95:         @active = false
96:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 121
121:       def log_info(sql, name, runtime)
122:         if @logger && @logger.debug?
123:           name = "#{name.nil? ? "SQL" : name} (#{sprintf("%f", runtime)})"
124:           @logger.debug format_log_entry(name, sql.squeeze(' '))
125:         end
126:       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 58
58:       def prefetch_primary_key?(table_name = nil)
59:         false
60:       end

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

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 70
70:       def quote_table_name(name)
71:         quote_column_name(name)
72:       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 117
117:       def raw_connection
118:         @connection
119:       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 89
89:       def reconnect!
90:         @active = true
91:       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]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 100
100:       def requires_reloading?
101:         false
102:       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 50
50:       def supports_count_distinct?
51:         true
52:       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 44
44:       def supports_migrations?
45:         false
46:       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 106
106:       def verify!(timeout)
107:         now = Time.now.to_i
108:         if (now - @last_verification) > timeout
109:           reconnect! unless active?
110:           @last_verification = now
111:         end
112:       end

Protected Instance methods

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 150
150:         def format_log_entry(message, dump = nil)
151:           if ActiveRecord::Base.colorize_logging
152:             if @@row_even
153:               @@row_even = false
154:               message_color, dump_color = "4;36;1", "0;1"
155:             else
156:               @@row_even = true
157:               message_color, dump_color = "4;35;1", "0"
158:             end
159: 
160:             log_entry = "  \e[#{message_color}m#{message}\e[0m   "
161:             log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
162:             log_entry
163:           else
164:             "%s  %s" % [message, dump]
165:           end
166:         end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 129
129:         def log(sql, name)
130:           if block_given?
131:             result = nil
132:             seconds = Benchmark.realtime { result = yield }
133:             @runtime += seconds
134:             log_info(sql, name, seconds)
135:             result
136:           else
137:             log_info(sql, name, 0)
138:             nil
139:           end
140:         rescue Exception => e
141:           # Log message and raise exception.
142:           # Set last_verification to 0, so that connection gets verified
143:           # upon reentering the request loop
144:           @last_verification = 0
145:           message = "#{e.class.name}: #{e.message}: #{sql}"
146:           log_info(message, name, 0)
147:           raise ActiveRecord::StatementInvalid, message
148:         end

[Validate]