WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/17/2016 04:20:22 AM (5 years ago)
Author:
pento
Message:

Database: Add support for LIKE-escaped tables in ::get_table_from_query().

The SHOW TABLES LIKE query can be used to search for tables that match a pattern, wp\_123\_%, for example. While this isn't the name of an actual table, the wp_123_ prefix can be used by database drop-ins to direct the query correctly. This change removes the escaping and % modifier, to provide this usable prefix.

Props andy, pento.
Fixes #38751.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/db.php

    r38580 r39275  
    566566            "DELETE `a` FROM $table a",
    567567
    568             // STATUS
    569             "SHOW TABLE STATUS LIKE '$table'",
    570             "SHOW TABLE STATUS WHERE NAME='$table'",
    571 
    572             "SHOW TABLES LIKE '$table'",
    573             "SHOW FULL TABLES LIKE '$table'",
    574             "SHOW TABLES WHERE NAME='$table'",
    575 
    576568            // Extended
    577569            "EXPLAIN SELECT * FROM $table",
     
    672664
    673665    /**
     666     * @ticket 38751
     667     */
     668    function data_get_escaped_table_from_show_query() {
     669        return array(
     670            // Equality
     671            array( "SHOW TABLE STATUS WHERE Name = 'test_name'", 'test_name' ),
     672            array( "SHOW TABLE STATUS WHERE NAME=\"test_name\"", 'test_name' ),
     673            array( "SHOW TABLES WHERE Name = \"test_name\"",     'test_name' ),
     674            array( "SHOW FULL TABLES WHERE Name='test_name'",    'test_name' ),
     675
     676            // LIKE
     677            array( "SHOW TABLE STATUS LIKE 'test\_prefix\_%'",   'test_prefix_' ),
     678            array( "SHOW TABLE STATUS LIKE \"test\_prefix\_%\"", 'test_prefix_' ),
     679            array( "SHOW TABLES LIKE 'test\_prefix\_%'",         'test_prefix_' ),
     680            array( "SHOW FULL TABLES LIKE \"test\_prefix\_%\"",  'test_prefix_' ),
     681        );
     682    }
     683
     684    /**
     685     * @dataProvider data_get_escaped_table_from_show_query
     686     * @ticket 38751
     687     */
     688    function test_get_escaped_table_from_show_query( $query, $table ) {
     689        $this->assertEquals( $table, self::$_wpdb->get_table_from_query( $query ) );
     690    }
     691
     692    /**
    674693     * @ticket 21212
    675694     */
Note: See TracChangeset for help on using the changeset viewer.