mirror of
https://github.com/github/rails.git
synced 2026-02-11 06:35:10 -05:00
Added connection#current_database that'll return of the current database (only works in MySQL, SQL Server, and Oracle so far -- please help implement for the rest of the adapters) (closes #3663) [Tom ward]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3911 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Added connection#current_database that'll return of the current database (only works in MySQL, SQL Server, and Oracle so far -- please help implement for the rest of the adapters) #3663 [Tom ward]
|
||||
|
||||
* Fixed that Migration#execute would have the table name prefix appended to its query #4110 [mark.imbriaco@pobox.com]
|
||||
|
||||
* Make all tinyint(1) variants act like boolean in mysql (tinyint(1) unsigned, etc.) [Jamis Buck]
|
||||
|
||||
@@ -261,6 +261,9 @@ module ActiveRecord
|
||||
execute "DROP DATABASE IF EXISTS `#{name}`"
|
||||
end
|
||||
|
||||
def current_database
|
||||
select_one("SELECT DATABASE() as db")["db"]
|
||||
end
|
||||
|
||||
def tables(name = nil) #:nodoc:
|
||||
tables = []
|
||||
|
||||
@@ -399,6 +399,10 @@ module ActiveRecord
|
||||
def create_database(name)
|
||||
execute "CREATE DATABASE #{name}"
|
||||
end
|
||||
|
||||
def current_database
|
||||
@connection.select_one("select DB_NAME()")[0]
|
||||
end
|
||||
|
||||
def tables(name = nil)
|
||||
execute("SELECT table_name from information_schema.tables WHERE table_type = 'BASE TABLE'", name).inject([]) do |tables, field|
|
||||
|
||||
@@ -18,8 +18,9 @@ class AdapterTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_indexes
|
||||
idx_name = "accounts_idx"
|
||||
|
||||
if @connection.respond_to?(:indexes)
|
||||
idx_name = "accounts_idx"
|
||||
indexes = @connection.indexes("accounts")
|
||||
assert indexes.empty?
|
||||
|
||||
@@ -34,7 +35,15 @@ class AdapterTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
ensure
|
||||
@connection.remove_index :accounts, :firm_id rescue nil
|
||||
@connection.remove_index(:accounts, :name => idx_name) rescue nil
|
||||
end
|
||||
|
||||
def test_current_database
|
||||
if @connection.respond_to?(:current_database)
|
||||
assert_equal "activerecord_unittest", @connection.current_database
|
||||
else
|
||||
warn "#{@connection.class} does not respond to #current_database"
|
||||
end
|
||||
end
|
||||
|
||||
# test resetting sequences in odd tables in postgreSQL
|
||||
|
||||
Reference in New Issue
Block a user