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.

Conflicts:

	activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb

Conflicts:

	activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
	activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
  • Loading branch information...
commit 023eaf8ab9a0cb54f11ab7db808aefd9b3c761c2 1 parent a1a71ab
@kennyj kennyj authored tenderlove committed
View
4 activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -423,7 +423,9 @@ def collation
end
def tables(name = nil, database = nil) #:nodoc:
- sql = ["SHOW TABLES", database].compact.join(' IN ')
+ sql = "SHOW TABLES "
+ sql << "IN #{quote_table_name(database)} " if database
+
execute(sql, 'SCHEMA').collect do |field|
field.first
end
View
5 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -630,7 +630,10 @@ def collation
end
def tables(name = nil, database = nil) #:nodoc:
- result = execute(["SHOW TABLES", database].compact.join(' IN '), 'SCHEMA')
+ sql = "SHOW TABLES "
+ sql << "IN #{quote_table_name(database)} " if database
+
+ result = execute(sql, 'SCHEMA')
tables = result.collect { |field| field[0] }
result.free
tables
View
10 activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
@@ -52,6 +52,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.