Skip to content
This repository
Browse code

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
Toshinori Kajihara authored March 03, 2012 tenderlove committed June 11, 2012
4  activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -423,7 +423,9 @@ def collation
423 423
       end
424 424
 
425 425
       def tables(name = nil, database = nil) #:nodoc:
426  
-        sql = ["SHOW TABLES", database].compact.join(' IN ')
  426
+        sql = "SHOW TABLES "
  427
+        sql << "IN #{quote_table_name(database)} " if database
  428
+
427 429
         execute(sql, 'SCHEMA').collect do |field|
428 430
           field.first
429 431
         end
5  activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -630,7 +630,10 @@ def collation
630 630
       end
631 631
 
632 632
       def tables(name = nil, database = nil) #:nodoc:
633  
-        result = execute(["SHOW TABLES", database].compact.join(' IN '), 'SCHEMA')
  633
+        sql = "SHOW TABLES "
  634
+        sql << "IN #{quote_table_name(database)} " if database
  635
+
  636
+        result = execute(sql, 'SCHEMA')
634 637
         tables = result.collect { |field| field[0] }
635 638
         result.free
636 639
         tables
10  activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb
@@ -52,6 +52,16 @@ def test_exec_insert_string
52 52
         assert_equal str, value
53 53
       end
54 54
 
  55
+      def test_tables_quoting
  56
+        begin
  57
+          @conn.tables(nil, "foo-bar", nil)
  58
+          flunk
  59
+        rescue => e
  60
+          # assertion for *quoted* database properly
  61
+          assert_match(/Access denied for user/, e.inspect)
  62
+        end
  63
+      end
  64
+
55 65
       private
56 66
       def insert(ctx, data)
57 67
         binds   = data.map { |name, value|
11  activerecord/test/cases/adapters/mysql2/schema_test.rb
@@ -35,6 +35,17 @@ def test_table_exists?
35 35
       def test_table_exists_wrong_schema
36 36
         assert(!@connection.table_exists?("#{@db_name}.zomg"), "table should not exist")
37 37
       end
  38
+
  39
+      def test_tables_quoting
  40
+        begin
  41
+          @connection.tables(nil, "foo-bar", nil)
  42
+          flunk
  43
+        rescue => e
  44
+          # assertion for *quoted* database properly
  45
+          assert_match(/Access denied for user/, e.inspect)
  46
+        end
  47
+      end
  48
+
38 49
     end
39 50
   end
40 51
 end

0 notes on commit 023eaf8

Please sign in to comment.
Something went wrong with that request. Please try again.