How to output the name of the db

Hi all,

does anyone maybe know whether one can output the name of the current
used database during runtime (for example something like puts
currentDatabase’}) ?

Regards,
Y

You can grab a raw connection from an ActiveRecord based model object
and
ask it nicely:

aro.connection.adapter_name
=> “MySQL”

On 11/4/06, Yu Co [email protected] wrote:


Posted via http://www.ruby-forum.com/.


Thanks,
-Steve
http://www.stevelongdo.com

I’ve been able to grab the current values for migrations using the
following:

ActiveRecord::Base.connection.instance_values[‘config’][:database]
ActiveRecord::Base.connection.instance_values[‘config’][:host]
ActiveRecord::Base.connection.instance_values[‘config’][:username]
ActiveRecord::Base.connection.instance_values[‘config’][:password]

Using those I can do a system call to run the command line mysql binary
to import SQL data into newly created tables that are mostly used for
static lookup tables that rarely change. When we get a new dump file I
reload the sites manually and then check the new SQL dump file into SVN
so that anyone doing a migrate will load the latest copy.

# use current values from database.yml (already loaded into

ActiveRecord)
host =
ActiveRecord::Base.connection.instance_values[‘config’][:host]
username =
ActiveRecord::Base.connection.instance_values[‘config’][:username]
password =
ActiveRecord::Base.connection.instance_values[‘config’][:password]
database =
ActiveRecord::Base.connection.instance_values[‘config’][:database]

system "mysql -h#{host} -u#{username} -p#{password} #{database} " +
  "<db/zipcodes.import.sql"

David