Changed :dbfile to :database for SQLite adapter for consistency (old key still works as an alias) (closes #2644) [Dan Peterson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2825 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-10-30 08:10:04 +00:00
parent ea44527afd
commit c21fdf31a5
9 changed files with 25 additions and 21 deletions

View File

@ -1,5 +1,7 @@
*SVN* *SVN*
* Changed :dbfile to :database for SQLite adapter for consistency (old key still works as an alias) #2644 [Dan Peterson]
* Added migration support for Oracle #2647 [Michael Schoen] * Added migration support for Oracle #2647 [Michael Schoen]
* Worked around that connection can't be reset if allow_concurrency is off. #2648 [Michael Schoen <schoenm@earthlink.net>] * Worked around that connection can't be reset if allow_concurrency is off. #2648 [Michael Schoen <schoenm@earthlink.net>]

View File

@ -165,7 +165,7 @@ A short rundown of the major features:
* Database abstraction through simple adapters (~100 lines) with a shared connector * Database abstraction through simple adapters (~100 lines) with a shared connector
ActiveRecord::Base.establish_connection(:adapter => "sqlite", :dbfile => "dbfile") ActiveRecord::Base.establish_connection(:adapter => "sqlite", :database => "dbfile")
ActiveRecord::Base.establish_connection( ActiveRecord::Base.establish_connection(
:adapter => "mysql", :adapter => "mysql",

View File

@ -27,13 +27,13 @@ module ActiveRecord
# #
# ActiveRecord::Base.establish_connection( # ActiveRecord::Base.establish_connection(
# :adapter => "sqlite", # :adapter => "sqlite",
# :dbfile => "path/to/dbfile" # :database => "path/to/dbfile"
# ) # )
# #
# Also accepts keys as strings (for parsing from yaml for example): # Also accepts keys as strings (for parsing from yaml for example):
# ActiveRecord::Base.establish_connection( # ActiveRecord::Base.establish_connection(
# "adapter" => "sqlite", # "adapter" => "sqlite",
# "dbfile" => "path/to/dbfile" # "database" => "path/to/dbfile"
# ) # )
# #
# The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError # The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError

View File

@ -15,7 +15,7 @@ module ActiveRecord
end end
db = SQLite3::Database.new( db = SQLite3::Database.new(
config[:dbfile], config[:database],
:results_as_hash => true, :results_as_hash => true,
:type_translation => false :type_translation => false
) )
@ -29,7 +29,7 @@ module ActiveRecord
unless self.class.const_defined?(:SQLite) unless self.class.const_defined?(:SQLite)
require_library_or_gem(config[:adapter]) require_library_or_gem(config[:adapter])
db = SQLite::Database.new(config[:dbfile], 0) db = SQLite::Database.new(config[:database], 0)
db.show_datatypes = "ON" if !defined? SQLite::Version db.show_datatypes = "ON" if !defined? SQLite::Version
db.results_as_hash = true if defined? SQLite::Version db.results_as_hash = true if defined? SQLite::Version
db.type_translation = false db.type_translation = false
@ -45,16 +45,17 @@ module ActiveRecord
private private
def parse_config!(config) def parse_config!(config)
# Require dbfile. config[:database] ||= config[:dbfile]
unless config.has_key?(:dbfile) # Require database.
raise ArgumentError, "No database file specified. Missing argument: dbfile" unless config.has_key?(:database)
raise ArgumentError, "No database file specified. Missing argument: database"
end end
# Allow database path relative to RAILS_ROOT, but only if # Allow database path relative to RAILS_ROOT, but only if
# the database path is not the special path that tells # the database path is not the special path that tells
# Sqlite build a database only in memory. # Sqlite build a database only in memory.
if Object.const_defined?(:RAILS_ROOT) && ':memory:' != config[:dbfile] if Object.const_defined?(:RAILS_ROOT) && ':memory:' != config[:database]
config[:dbfile] = File.expand_path(config[:dbfile], RAILS_ROOT) config[:database] = File.expand_path(config[:database], RAILS_ROOT)
end end
end end
end end
@ -88,7 +89,7 @@ module ActiveRecord
# #
# Options: # Options:
# #
# * <tt>:dbfile</tt> -- Path to the database file. # * <tt>:database</tt> -- Path to the database file.
class SQLiteAdapter < AbstractAdapter class SQLiteAdapter < AbstractAdapter
def adapter_name #:nodoc: def adapter_name #:nodoc:
'SQLite' 'SQLite'

View File

@ -18,7 +18,7 @@ def make_connection(clazz, db_file, db_definitions_file)
raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command) raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
clazz.establish_connection( clazz.establish_connection(
:adapter => "sqlite", :adapter => "sqlite",
:dbfile => db_file) :database => db_file)
script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}") script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
# SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time # SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
script.split(';').each do script.split(';').each do
@ -28,7 +28,7 @@ def make_connection(clazz, db_file, db_definitions_file)
else else
clazz.establish_connection( clazz.establish_connection(
:adapter => "sqlite", :adapter => "sqlite",
:dbfile => db_file) :database => db_file)
end end
end end

View File

@ -18,7 +18,7 @@ def make_connection(clazz, db_file, db_definitions_file)
raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command) raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command)
clazz.establish_connection( clazz.establish_connection(
:adapter => "sqlite3", :adapter => "sqlite3",
:dbfile => db_file) :database => db_file)
script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}") script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
# SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time # SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
script.split(';').each do script.split(';').each do
@ -28,7 +28,7 @@ def make_connection(clazz, db_file, db_definitions_file)
else else
clazz.establish_connection( clazz.establish_connection(
:adapter => "sqlite3", :adapter => "sqlite3",
:dbfile => db_file) :database => db_file)
end end
end end

View File

@ -7,7 +7,7 @@ class SqliteError < StandardError
end end
def make_connection(clazz, db_definitions_file) def make_connection(clazz, db_definitions_file)
clazz.establish_connection(:adapter => 'sqlite3', :dbfile => ':memory:') clazz.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
File.read("#{File.dirname(__FILE__)}/../../fixtures/db_definitions/#{db_definitions_file}").split(';').each do |command| File.read("#{File.dirname(__FILE__)}/../../fixtures/db_definitions/#{db_definitions_file}").split(';').each do |command|
clazz.connection.execute(command) unless command.strip.empty? clazz.connection.execute(command) unless command.strip.empty?
end end

View File

@ -6,6 +6,7 @@
# #
# Get the fast C bindings: # Get the fast C bindings:
# gem install mysql # gem install mysql
# (on OS X: gem install mysql -- --include=/usr/local/lib)
# And be sure to use new-style password hashing: # And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development: development:
@ -81,10 +82,10 @@ sqlite_example:
# gem install sqlite3-ruby # gem install sqlite3-ruby
sqlite3_example: sqlite3_example:
adapter: sqlite3 adapter: sqlite3
dbfile: db/development.sqlite3 database: db/development.sqlite3
# In-memory SQLite 3 database. Useful for tests. # In-memory SQLite 3 database. Useful for tests.
sqlite3_in_memory_example: sqlite3_in_memory_example:
adapter: sqlite3 adapter: sqlite3
dbfile: ":memory:" database: ":memory:"

View File

@ -55,7 +55,7 @@ task :db_structure_dump => :environment do
else else
raise "Task not supported by '#{abcs["test"]["adapter"]}'" raise "Task not supported by '#{abcs["test"]["adapter"]}'"
end end
if ActiveRecord::Base.connection.supports_migrations? if ActiveRecord::Base.connection.supports_migrations?
File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information } File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
end end
@ -65,7 +65,7 @@ desc "Recreate the test databases from the development structure"
task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do
abcs = ActiveRecord::Base.configurations abcs = ActiveRecord::Base.configurations
case abcs["test"]["adapter"] case abcs["test"]["adapter"]
when "mysql" when "mysql"
ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
@ -80,7 +80,7 @@ task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do
`#{abcs["test"]["adapter"]} #{abcs["test"]["dbfile"]} < db/#{RAILS_ENV}_structure.sql` `#{abcs["test"]["adapter"]} #{abcs["test"]["dbfile"]} < db/#{RAILS_ENV}_structure.sql`
when "sqlserver" when "sqlserver"
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql` `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
when "oci", when "oci"
ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.establish_connection(:test)
IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl| IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
ActiveRecord::Base.connection.execute(ddl) ActiveRecord::Base.connection.execute(ddl)