Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 69c7f024882f8150a2bda8536e1480d19c982e04 1 parent 223549f
@kennyj authored
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
@@ -46,6 +46,16 @@ def test_exec_insert_string
assert_equal str, value
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.