aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb24
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb3
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb4
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb36
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb2
7 files changed, 15 insertions, 58 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index 377f2a44c5..bf8c546d2e 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -56,7 +56,7 @@ module ActiveRecord
# * +wait_timeout+: number of seconds to block and wait for a connection
# before giving up and raising a timeout error (default 5 seconds).
class ConnectionPool
- attr_reader :spec
+ attr_reader :spec, :connections
# Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification
# object which describes database connection information (e.g. adapter,
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
index bbc290f721..2f36bec764 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
@@ -51,8 +51,8 @@ module ActiveRecord
def self.establish_connection(spec = nil)
case spec
when nil
- raise AdapterNotSpecified unless defined? RAILS_ENV
- establish_connection(RAILS_ENV)
+ raise AdapterNotSpecified unless defined?(Rails.env)
+ establish_connection(Rails.env)
when ConnectionSpecification
@@connection_handler.establish_connection(name, spec)
when Symbol, String
@@ -88,26 +88,6 @@ module ActiveRecord
end
class << self
- # Deprecated and no longer has any effect.
- def allow_concurrency
- ActiveSupport::Deprecation.warn("ActiveRecord::Base.allow_concurrency has been deprecated and no longer has any effect. Please remove all references to allow_concurrency.")
- end
-
- # Deprecated and no longer has any effect.
- def allow_concurrency=(flag)
- ActiveSupport::Deprecation.warn("ActiveRecord::Base.allow_concurrency= has been deprecated and no longer has any effect. Please remove all references to allow_concurrency=.")
- end
-
- # Deprecated and no longer has any effect.
- def verification_timeout
- ActiveSupport::Deprecation.warn("ActiveRecord::Base.verification_timeout has been deprecated and no longer has any effect. Please remove all references to verification_timeout.")
- end
-
- # Deprecated and no longer has any effect.
- def verification_timeout=(flag)
- ActiveSupport::Deprecation.warn("ActiveRecord::Base.verification_timeout= has been deprecated and no longer has any effect. Please remove all references to verification_timeout=.")
- end
-
# Returns the connection currently associated with the class. This can
# also be used to "borrow" the connection to do database work unrelated
# to any of the specific Active Records.
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
index 00c71090f3..020acbbe5a 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
@@ -75,7 +75,8 @@ module ActiveRecord
def cache_sql(sql)
result =
if @query_cache.has_key?(sql)
- log_info(sql, "CACHE", 0.0)
+ ActiveSupport::Notifications.instrument("active_record.sql",
+ :sql => sql, :name => "CACHE", :connection_id => self.object_id)
@query_cache[sql]
else
@query_cache[sql] = yield
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index e731bc84f0..86ba7d72c3 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -344,12 +344,12 @@ module ActiveRecord
end
end
- def assume_migrated_upto_version(version)
+ def assume_migrated_upto_version(version, migrations_path = ActiveRecord::Migrator.migrations_path)
version = version.to_i
sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i)
- versions = Dir['db/migrate/[0-9]*_*.rb'].map do |filename|
+ versions = Dir["#{migrations_path}/[0-9]*_*.rb"].map do |filename|
filename.split('/').last.split('_').first.to_i
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index d09aa3c4d2..7e80347f75 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -39,7 +39,6 @@ module ActiveRecord
def initialize(connection, logger = nil) #:nodoc:
@connection, @logger = connection, logger
@runtime = 0
- @last_verification = 0
@query_cache_enabled = false
end
@@ -191,27 +190,19 @@ module ActiveRecord
"active_record_#{open_transactions}"
end
- def log_info(sql, name, ms)
- if @logger && @logger.debug?
- name = '%s (%.1fms)' % [name || 'SQL', ms]
- @logger.debug(format_log_entry(name, sql.squeeze(' ')))
- end
- end
-
protected
+
def log(sql, name)
+ name ||= "SQL"
result = nil
- ActiveSupport::Notifications.instrument(:sql, :sql => sql, :name => name) do
+ ActiveSupport::Notifications.instrument("active_record.sql",
+ :sql => sql, :name => name, :connection_id => self.object_id) do
@runtime += Benchmark.ms { result = yield }
end
result
rescue Exception => e
- # Log message and raise exception.
- # Set last_verification 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)
+ @logger.debug message if @logger
raise translate_exception(e, message)
end
@@ -220,23 +211,6 @@ module ActiveRecord
ActiveRecord::StatementInvalid.new(message)
end
- 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
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index fa28bc64df..8c0bf6396a 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -579,6 +579,8 @@ module ActiveRecord
protected
def translate_exception(exception, message)
+ return super unless exception.respond_to?(:errno)
+
case exception.errno
when 1062
RecordNotUnique.new(message, exception)
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index 78b897add6..0a52f3a6a2 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -14,7 +14,7 @@ module ActiveRecord
# Allow database path relative to Rails.root, but only if
# the database path is not the special path that tells
# Sqlite to build a database only in memory.
- if Object.const_defined?(:Rails) && ':memory:' != config[:database]
+ if defined?(Rails.root) && ':memory:' != config[:database]
config[:database] = File.expand_path(config[:database], Rails.root)
end
end