Class: ActiveRecord::ConnectionAdapters::AbstractAdapter
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::AbstractAdapter
- Includes:
- Quoting, SchemaStatements, DatabaseStatements
- Defined in:
- lib/active_record/connection_adapters/abstract_adapter.rb
Overview
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.
Direct Known Subclasses
FirebirdAdapter, FrontBaseAdapter, OpenBaseAdapter, PostgreSQLAdapter, SQLServerAdapter
Constant Summary collapse
- @@row_even =
true
Instance Method Summary collapse
-
#active? ⇒ Boolean
Is this connection active and ready to perform queries?.
-
#adapter_name ⇒ Object
Returns the human-readable name of the adapter.
-
#disconnect! ⇒ Object
Close this connection.
-
#initialize(connection, logger = nil) ⇒ AbstractAdapter
constructor
:nodoc:.
-
#prefetch_primary_key?(table_name = nil) ⇒ Boolean
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.
-
#raw_connection ⇒ Object
Provides access to the underlying database connection.
-
#reconnect! ⇒ Object
Close this connection and open a new one in its place.
-
#requires_reloading? ⇒ Boolean
Returns true if its safe to reload the connection between requests for development mode.
-
#reset_runtime ⇒ Object
:nodoc:.
-
#supports_count_distinct? ⇒ Boolean
Does this adapter support using DISTINCT within COUNT? This is
true
for all adapters except sqlite. -
#supports_migrations? ⇒ Boolean
Does this adapter support migrations? Backend specific, as the abstract adapter always returns
false
. -
#verify!(timeout) ⇒ Object
Lazily verify this connection, calling
active?
only if it hasn’t been called fortimeout
seconds.
Methods included from Quoting
#quote, #quote_column_name, #quote_string, #quoted_date, #quoted_false, #quoted_true
Methods included from SchemaStatements
#add_column, #add_column_options!, #add_index, #add_order_by_for_association_limiting!, #change_column, #change_column_default, #columns, #create_table, #distinct, #drop_table, #dump_schema_information, #index_name, #initialize_schema_information, #native_database_types, #remove_column, #remove_index, #rename_column, #rename_table, #structure_dump, #table_alias_for, #table_alias_length, #type_to_sql
Constructor Details
#initialize(connection, logger = nil) ⇒ AbstractAdapter
:nodoc:
27 28 29 30 31 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 27 def initialize(connection, logger = nil) #:nodoc: @connection, @logger = connection, logger @runtime = 0 @last_verification = 0 end |
Instance Method Details
#active? ⇒ Boolean
Is this connection active and ready to perform queries?
68 69 70 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 68 def active? @active != false end |
#adapter_name ⇒ Object
Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.
35 36 37 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 35 def adapter_name 'Abstract' end |
#disconnect! ⇒ Object
Close this connection
78 79 80 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 78 def disconnect! @active = false end |
#prefetch_primary_key?(table_name = nil) ⇒ Boolean
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.
55 56 57 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 55 def prefetch_primary_key?(table_name = nil) false end |
#raw_connection ⇒ Object
Provides access to the underlying database connection. Useful for when you need to call a proprietary method such as postgresql’s lo_* methods
101 102 103 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 101 def raw_connection @connection end |
#reconnect! ⇒ Object
Close this connection and open a new one in its place.
73 74 75 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 73 def reconnect! @active = true end |
#requires_reloading? ⇒ Boolean
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.
84 85 86 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 84 def requires_reloading? false end |
#reset_runtime ⇒ Object
:nodoc:
59 60 61 62 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 59 def reset_runtime #:nodoc: rt, @runtime = @runtime, 0 rt end |
#supports_count_distinct? ⇒ Boolean
Does this adapter support using DISTINCT within COUNT? This is true
for all adapters except sqlite.
47 48 49 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 47 def supports_count_distinct? true end |
#supports_migrations? ⇒ Boolean
Does this adapter support migrations? Backend specific, as the abstract adapter always returns false
.
41 42 43 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 41 def supports_migrations? false end |
#verify!(timeout) ⇒ Object
Lazily verify this connection, calling active?
only if it hasn’t been called for timeout
seconds.
90 91 92 93 94 95 96 |
# File '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 |