diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-18 03:54:04 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-18 03:54:04 +0000 |
commit | 0555fc905c09d4339bfb641428a4ddfcb5f4c0c6 (patch) | |
tree | 5dcf5a5b409765fc32bbb5d082d3e1e962dd8934 /activerecord/lib/active_record/connection_adapters | |
parent | df97ed5e4c986be875248ec1b27d7acfc200ae9c (diff) | |
download | rails-0555fc905c09d4339bfb641428a4ddfcb5f4c0c6.tar.gz rails-0555fc905c09d4339bfb641428a4ddfcb5f4c0c6.tar.bz2 rails-0555fc905c09d4339bfb641428a4ddfcb5f4c0c6.zip |
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
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb | 4 |
2 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 842126a991..9e06c63181 100755 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -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 = [] diff --git a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb index be06887fa0..a046d470c9 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb @@ -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| |