diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2019-07-11 07:16:54 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2019-07-11 07:18:11 +0900 |
commit | ac41b73d97a80f2552196516e29d7e3335e2d556 (patch) | |
tree | 0b8870ae91f73c58131f954bb663d8ac6ba8a7c4 /activerecord/lib/active_record/connection_adapters | |
parent | 6e40b131d2c7208e116d267e4b40dcf621f8b442 (diff) | |
download | rails-ac41b73d97a80f2552196516e29d7e3335e2d556.tar.gz rails-ac41b73d97a80f2552196516e29d7e3335e2d556.tar.bz2 rails-ac41b73d97a80f2552196516e29d7e3335e2d556.zip |
MySQL: Check error number instead of a message
To be able to check regardless of locale.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index d9eab9582e..1df9ac32c9 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -8,6 +8,8 @@ require "mysql2" module ActiveRecord module ConnectionHandling # :nodoc: + ER_BAD_DB_ERROR = 1049 + # Establishes a connection to the database that's used by all Active Record objects. def mysql2_connection(config) config = config.symbolize_keys @@ -22,7 +24,7 @@ module ActiveRecord client = Mysql2::Client.new(config) ConnectionAdapters::Mysql2Adapter.new(client, logger, nil, config) rescue Mysql2::Error => error - if error.message.include?("Unknown database") + if error.error_number == ER_BAD_DB_ERROR raise ActiveRecord::NoDatabaseError else raise |