diff options
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
3 files changed, 42 insertions, 33 deletions
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 1a76050872..918c29114c 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb @@ -207,7 +207,12 @@ module ActiveRecord spec = spec.symbolize_keys unless spec.key?(:adapter) then raise AdapterNotSpecified, "database configuration does not specify adapter" end 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 establish_connection(ConnectionSpecification.new(spec, adapter_method)) end diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb new file mode 100644 index 0000000000..0827f61db4 --- /dev/null +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -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 diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 6409fe292a..5da97ceff6 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -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' module ActiveRecord class Base 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 def sqlite_connection(config) # :nodoc: - parse_config!(config) + parse_sqlite_config!(config) unless self.class.const_defined?(:SQLite) require_library_or_gem(config[:adapter]) @@ -47,7 +25,7 @@ module ActiveRecord end private - def parse_config!(config) + def parse_sqlite_config!(config) config[:database] ||= config[:dbfile] # Require database. unless config[:database] @@ -381,14 +359,6 @@ module ActiveRecord 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: def supports_count_distinct? #:nodoc: false |