Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix GH #3163. Should quote database on mysql/mysql2.

Conflicts:

	activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
  • Loading branch information...
commit 22994b2d638738abce7dc7672c27a5e7171018e8 1 parent 0391ae9
@kennyj kennyj authored tenderlove committed
View
2  activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -375,7 +375,7 @@ def collation
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|
View
10 activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
@@ -82,6 +82,16 @@ def test_pk_and_sequence_for_with_custom_index_type_pk
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|
View
11 activerecord/test/cases/adapters/mysql2/schema_test.rb
@@ -35,6 +35,17 @@ def test_table_exists?
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
Please sign in to comment.
Something went wrong with that request. Please try again.