From 49d14069a1a2b540d151a43a811ba69e1937203f Mon Sep 17 00:00:00 2001 From: Krekoten' Marjan Date: Tue, 31 Aug 2010 00:40:43 +0300 Subject: [PATCH] Fix unknown method Mysql::Error#errno and Mysql::Error#error [#5502 state:resolved] --- .../lib/active_record/railties/databases.rake | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index b1aad0d..bdd41ac 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -61,15 +61,17 @@ namespace :db do @charset = ENV['CHARSET'] || 'utf8' @collation = ENV['COLLATION'] || 'utf8_unicode_ci' creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)} - error_class = config['adapter'] =~ /mysql2/ ? Mysql2::Error : Mysql::Error + error_class = "#{config['adapter'].capitalize}::Error".constantize access_denied_error = 1045 begin ActiveRecord::Base.establish_connection(config.merge('database' => nil)) ActiveRecord::Base.connection.create_database(config['database'], creation_options) ActiveRecord::Base.establish_connection(config) rescue error_class => sqlerr - if sqlerr.errno == access_denied_error - print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>" + if (defined?(Mysql) && error_class == Mysql::Error && sqlerr.errno == access_denied_error)\ + || (defined?(Mysql2) && error_class == Mysql2::Error && sqlerr.error_number == access_denied_error) + + print "#{defined?(Mysql) && error_class == Mysql::Error ? sqlerr.error : sqlerr}. \nPlease provide the root password for your mysql installation\n>" root_password = $stdin.gets.strip grant_statement = "GRANT ALL PRIVILEGES ON #{config['database']}.* " \ "TO '#{config['username']}'@'localhost' " \ -- 1.7.2