Make WordPress Core

Ticket #32090: 32090-38.patch

File 32090-38.patch, 2.7 KB (added by johnbillion, 8 years ago)

3.8

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

     
    18321832                }
    18331833
    18341834                $charsets = $columns = array();
    1835                 $results = $this->get_results( "SHOW FULL COLUMNS FROM `$table`" );
     1835
     1836                $table_parts = explode( '.', $table );
     1837                $table = '`' . implode( '`.`', $table_parts ) . '`';
     1838                $results = $this->get_results( "SHOW FULL COLUMNS FROM $table" );
    18361839                if ( ! $results ) {
    18371840                        return new WP_Error( 'wpdb_get_table_charset_failure' );
    18381841                }
     
    23992402                                . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?'
    24002403                                . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
    24012404                                . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
    2402                                 . ')\s+`?([\w-]+)`?/is', $query, $maybe ) ) {
    2403                         return $maybe[1];
     2405                                . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
     2406                        return str_replace( '`', '', $maybe[1] );
    24042407                }
    24052408
    24062409                // SHOW TABLE STATUS and SHOW TABLES
    24072410                if ( preg_match( '/^\s*(?:'
    24082411                                . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    24092412                                . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    2410                                 . ')\W([\w-]+)\W/is', $query, $maybe ) ) {
    2411                         return $maybe[1];
     2413                                . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
     2414                        return str_replace( '`', '', $maybe[1] );
    24122415                }
    24132416
    24142417                // Big pattern for the rest of the table-related queries.
     
    24262429                                . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE'
    24272430                                . '|(?:GRANT|REVOKE).*ON\s+TABLE'
    24282431                                . '|SHOW\s+(?:.*FROM|.*TABLE)'
    2429                                 . ')\s+\(*\s*`?([\w-]+)`?\s*\)*/is', $query, $maybe ) ) {
    2430                         return $maybe[1];
     2432                                . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
     2433                        return str_replace( '`', '', $maybe[1] );
    24312434                }
    24322435
    24332436                return false;
  • branches/3.8/tests/phpunit/tests/db.php

     
    290290         */
    291291        function data_get_table_from_query() {
    292292                $table = 'a_test_table_name';
     293                $db_table = '`a_test_db`.`another_test_table`';
    293294
    294295                $queries = array(
    295296                        // Basic
     
    392393                        "SHOW INDEX FROM $table",
    393394                );
    394395
    395                 foreach ( $queries as &$query ) {
    396                         $query = array( $query, $table );
     396                $querycount = count( $queries );
     397                for ( $ii = 0; $ii < $querycount; $ii++ ) {
     398                        $db_query = str_replace( $table, $db_table, $queries[ $ii ] );
     399                        $expected_db_table = str_replace( '`', '', $db_table );
     400
     401                        $queries[ $ii ] = array( $queries[ $ii ], $table );
     402                        $queries[] = array( $db_query, $expected_db_table );
    397403                }
    398404                return $queries;
    399405        }