diff options
author | kennyj <kennyj@gmail.com> | 2012-03-03 22:25:15 +0900 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-06-11 11:00:29 -0700 |
commit | 22994b2d638738abce7dc7672c27a5e7171018e8 (patch) | |
tree | 15032a734030d873f408032103949a156191d4cd | |
parent | 0391ae9a14af1a87ca435eb7777c73271e859ae0 (diff) | |
download | rails-22994b2d638738abce7dc7672c27a5e7171018e8.tar.gz rails-22994b2d638738abce7dc7672c27a5e7171018e8.tar.bz2 rails-22994b2d638738abce7dc7672c27a5e7171018e8.zip |
Fix GH #3163. Should quote database on mysql/mysql2.
Conflicts:
activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
3 files changed, 22 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 2658c444d1..88f82b5e35 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -375,7 +375,7 @@ module ActiveRecord def tables(name = nil, database = nil, like = nil) #:nodoc: sql = "SHOW TABLES " - sql << "IN #{database} " if database + sql << "IN #{quote_table_name(database)} " if database sql << "LIKE #{quote(like)}" if like execute_and_free(sql, 'SCHEMA') do |result| diff --git a/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb b/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb index 65328522c3..749d50fe12 100644 --- a/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb +++ b/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb @@ -82,6 +82,16 @@ module ActiveRecord assert_equal @conn.default_sequence_name('ex_with_custom_index_type_pk', 'id'), seq end + def test_tables_quoting + begin + @conn.tables(nil, "foo-bar", nil) + flunk + rescue => e + # assertion for *quoted* database properly + assert_match(/Access denied for user/, e.inspect) + end + end + private def insert(ctx, data) binds = data.map { |name, value| diff --git a/activerecord/test/cases/adapters/mysql2/schema_test.rb b/activerecord/test/cases/adapters/mysql2/schema_test.rb index d5676bc522..fd9996c937 100644 --- a/activerecord/test/cases/adapters/mysql2/schema_test.rb +++ b/activerecord/test/cases/adapters/mysql2/schema_test.rb @@ -35,6 +35,17 @@ module ActiveRecord def test_table_exists_wrong_schema assert(!@connection.table_exists?("#{@db_name}.zomg"), "table should not exist") end + + def test_tables_quoting + begin + @connection.tables(nil, "foo-bar", nil) + flunk + rescue => e + # assertion for *quoted* database properly + assert_match(/Access denied for user/, e.inspect) + end + end + end end end |