Make WordPress Core

Ticket #32090: 32090-41.patch

File 32090-41.patch, 2.7 KB (added by johnbillion, 10 years ago)

4.1

  • branches/4.1/src/wp-includes/wp-db.php

     
    22462246                }
    22472247
    22482248                $charsets = $columns = array();
    2249                 $results = $this->get_results( "SHOW FULL COLUMNS FROM `$table`" );
     2249
     2250                $table_parts = explode( '.', $table );
     2251                $table = '`' . implode( '`.`', $table_parts ) . '`';
     2252                $results = $this->get_results( "SHOW FULL COLUMNS FROM $table" );
    22502253                if ( ! $results ) {
    22512254                        return new WP_Error( 'wpdb_get_table_charset_failure' );
    22522255                }
     
    28192822                                . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?'
    28202823                                . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
    28212824                                . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
    2822                                 . ')\s+`?([\w-]+)`?/is', $query, $maybe ) ) {
    2823                         return $maybe[1];
     2825                                . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
     2826                        return str_replace( '`', '', $maybe[1] );
    28242827                }
    28252828
    28262829                // SHOW TABLE STATUS and SHOW TABLES
    28272830                if ( preg_match( '/^\s*(?:'
    28282831                                . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    28292832                                . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    2830                                 . ')\W([\w-]+)\W/is', $query, $maybe ) ) {
    2831                         return $maybe[1];
     2833                                . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
     2834                        return str_replace( '`', '', $maybe[1] );
    28322835                }
    28332836
    28342837                // Big pattern for the rest of the table-related queries.
     
    28462849                                . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE'
    28472850                                . '|(?:GRANT|REVOKE).*ON\s+TABLE'
    28482851                                . '|SHOW\s+(?:.*FROM|.*TABLE)'
    2849                                 . ')\s+\(*\s*`?([\w-]+)`?\s*\)*/is', $query, $maybe ) ) {
    2850                         return $maybe[1];
     2852                                . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
     2853                        return str_replace( '`', '', $maybe[1] );
    28512854                }
    28522855
    28532856                return false;
  • branches/4.1/tests/phpunit/tests/db.php

     
    526526         */
    527527        function data_get_table_from_query() {
    528528                $table = 'a_test_table_name';
     529                $db_table = '`a_test_db`.`another_test_table`';
    529530
    530531                $queries = array(
    531532                        // Basic
     
    628629                        "SHOW INDEX FROM $table",
    629630                );
    630631
    631                 foreach ( $queries as &$query ) {
    632                         $query = array( $query, $table );
     632                $querycount = count( $queries );
     633                for ( $ii = 0; $ii < $querycount; $ii++ ) {
     634                        $db_query = str_replace( $table, $db_table, $queries[ $ii ] );
     635                        $expected_db_table = str_replace( '`', '', $db_table );
     636
     637                        $queries[ $ii ] = array( $queries[ $ii ], $table );
     638                        $queries[] = array( $db_query, $expected_db_table );
    633639                }
    634640                return $queries;
    635641        }