Load database adapters on demand. Eliminates config.connection_adapters and RAILS_CONNECTION_ADAPTERS. Closes #8456.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6833 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
162a4c5309
commit
cb7a17a9d0
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Load database adapters on demand. Eliminates config.connection_adapters and RAILS_CONNECTION_ADAPTERS. Add your lib directory to the $LOAD_PATH and put your custom adapter in lib/active_record/connection_adapters/adaptername_adapter.rb. This way you can provide custom adapters as plugins or gems without modifying Rails. [Jeremy Kemper]
|
||||||
|
|
||||||
* Ensure that associations with :dependent => :delete_all respect :conditions option. Closes #8034 [danger, joshpeek, Rick]
|
* Ensure that associations with :dependent => :delete_all respect :conditions option. Closes #8034 [danger, joshpeek, Rick]
|
||||||
|
|
||||||
* belongs_to assignment creates a new proxy rather than modifying its target in-place. #8412 [mmangino@elevatedrails.com]
|
* belongs_to assignment creates a new proxy rather than modifying its target in-place. #8412 [mmangino@elevatedrails.com]
|
||||||
|
|
|
@ -73,13 +73,7 @@ ActiveRecord::Base.class_eval do
|
||||||
include ActiveRecord::AttributeMethods
|
include ActiveRecord::AttributeMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
unless defined?(RAILS_CONNECTION_ADAPTERS)
|
require 'active_record/connection_adapters/abstract_adapter'
|
||||||
RAILS_CONNECTION_ADAPTERS = %w( mysql postgresql sqlite firebird sqlserver db2 oracle sybase openbase frontbase )
|
|
||||||
end
|
|
||||||
|
|
||||||
RAILS_CONNECTION_ADAPTERS.each do |adapter|
|
|
||||||
require "active_record/connection_adapters/" + adapter + "_adapter"
|
|
||||||
end
|
|
||||||
|
|
||||||
require 'active_record/query_cache'
|
require 'active_record/query_cache'
|
||||||
require 'active_record/schema_dumper'
|
require 'active_record/schema_dumper'
|
||||||
|
|
|
@ -207,7 +207,12 @@ module ActiveRecord
|
||||||
spec = spec.symbolize_keys
|
spec = spec.symbolize_keys
|
||||||
unless spec.key?(:adapter) then raise AdapterNotSpecified, "database configuration does not specify adapter" end
|
unless spec.key?(:adapter) then raise AdapterNotSpecified, "database configuration does not specify adapter" end
|
||||||
adapter_method = "#{spec[:adapter]}_connection"
|
adapter_method = "#{spec[:adapter]}_connection"
|
||||||
unless respond_to?(adapter_method) then raise AdapterNotFound, "database configuration specifies nonexistent #{spec[:adapter]} adapter" end
|
|
||||||
|
require "active_record/connection_adapters/#{spec[:adapter]}_adapter"
|
||||||
|
unless respond_to?(adapter_method)
|
||||||
|
raise AdapterNotFound, "database configuration specifies nonexistent #{spec[:adapter]} adapter"
|
||||||
|
end
|
||||||
|
|
||||||
remove_connection
|
remove_connection
|
||||||
establish_connection(ConnectionSpecification.new(spec, adapter_method))
|
establish_connection(ConnectionSpecification.new(spec, adapter_method))
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
require 'active_record/connection_adapters/sqlite_adapter'
|
||||||
|
|
||||||
|
module ActiveRecord
|
||||||
|
class Base
|
||||||
|
# sqlite3 adapter reuses sqlite_connection.
|
||||||
|
def self.sqlite3_connection(config) # :nodoc:
|
||||||
|
parse_sqlite_config!(config)
|
||||||
|
|
||||||
|
unless self.class.const_defined?(:SQLite3)
|
||||||
|
require_library_or_gem(config[:adapter])
|
||||||
|
end
|
||||||
|
|
||||||
|
db = SQLite3::Database.new(
|
||||||
|
config[:database],
|
||||||
|
:results_as_hash => true,
|
||||||
|
:type_translation => false
|
||||||
|
)
|
||||||
|
|
||||||
|
db.busy_timeout(config[:timeout]) unless config[:timeout].nil?
|
||||||
|
|
||||||
|
ConnectionAdapters::SQLite3Adapter.new(db, logger)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module ConnectionAdapters #:nodoc:
|
||||||
|
class SQLite3Adapter < SQLiteAdapter # :nodoc:
|
||||||
|
def table_structure(table_name)
|
||||||
|
returning structure = @connection.table_info(table_name) do
|
||||||
|
raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,33 +1,11 @@
|
||||||
# Author: Luke Holden <lholden@cablelan.net>
|
|
||||||
# Updated for SQLite3: Jamis Buck <jamis@37signals.com>
|
|
||||||
|
|
||||||
require 'active_record/connection_adapters/abstract_adapter'
|
require 'active_record/connection_adapters/abstract_adapter'
|
||||||
|
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
class Base
|
class Base
|
||||||
class << self
|
class << self
|
||||||
# sqlite3 adapter reuses sqlite_connection.
|
|
||||||
def sqlite3_connection(config) # :nodoc:
|
|
||||||
parse_config!(config)
|
|
||||||
|
|
||||||
unless self.class.const_defined?(:SQLite3)
|
|
||||||
require_library_or_gem(config[:adapter])
|
|
||||||
end
|
|
||||||
|
|
||||||
db = SQLite3::Database.new(
|
|
||||||
config[:database],
|
|
||||||
:results_as_hash => true,
|
|
||||||
:type_translation => false
|
|
||||||
)
|
|
||||||
|
|
||||||
db.busy_timeout(config[:timeout]) unless config[:timeout].nil?
|
|
||||||
|
|
||||||
ConnectionAdapters::SQLite3Adapter.new(db, logger)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Establishes a connection to the database that's used by all Active Record objects
|
# Establishes a connection to the database that's used by all Active Record objects
|
||||||
def sqlite_connection(config) # :nodoc:
|
def sqlite_connection(config) # :nodoc:
|
||||||
parse_config!(config)
|
parse_sqlite_config!(config)
|
||||||
|
|
||||||
unless self.class.const_defined?(:SQLite)
|
unless self.class.const_defined?(:SQLite)
|
||||||
require_library_or_gem(config[:adapter])
|
require_library_or_gem(config[:adapter])
|
||||||
|
@ -47,7 +25,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def parse_config!(config)
|
def parse_sqlite_config!(config)
|
||||||
config[:database] ||= config[:dbfile]
|
config[:database] ||= config[:dbfile]
|
||||||
# Require database.
|
# Require database.
|
||||||
unless config[:database]
|
unless config[:database]
|
||||||
|
@ -381,14 +359,6 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class SQLite3Adapter < SQLiteAdapter # :nodoc:
|
|
||||||
def table_structure(table_name)
|
|
||||||
returning structure = @connection.table_info(table_name) do
|
|
||||||
raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class SQLite2Adapter < SQLiteAdapter # :nodoc:
|
class SQLite2Adapter < SQLiteAdapter # :nodoc:
|
||||||
def supports_count_distinct? #:nodoc:
|
def supports_count_distinct? #:nodoc:
|
||||||
false
|
false
|
||||||
|
|
Loading…
Reference in New Issue