Make WordPress Core

Ticket #32090: 32090-39.patch

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

3.9

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

     
    22092209                }
    22102210
    22112211                $charsets = $columns = array();
    2212                 $results = $this->get_results( "SHOW FULL COLUMNS FROM `$table`" );
     2212
     2213                $table_parts = explode( '.', $table );
     2214                $table = '`' . implode( '`.`', $table_parts ) . '`';
     2215                $results = $this->get_results( "SHOW FULL COLUMNS FROM $table" );
    22132216                if ( ! $results ) {
    22142217                        return new WP_Error( 'wpdb_get_table_charset_failure' );
    22152218                }
     
    27822785                                . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?'
    27832786                                . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
    27842787                                . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
    2785                                 . ')\s+`?([\w-]+)`?/is', $query, $maybe ) ) {
    2786                         return $maybe[1];
     2788                                . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
     2789                        return str_replace( '`', '', $maybe[1] );
    27872790                }
    27882791
    27892792                // SHOW TABLE STATUS and SHOW TABLES
    27902793                if ( preg_match( '/^\s*(?:'
    27912794                                . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    27922795                                . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    2793                                 . ')\W([\w-]+)\W/is', $query, $maybe ) ) {
    2794                         return $maybe[1];
     2796                                . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
     2797                        return str_replace( '`', '', $maybe[1] );
    27952798                }
    27962799
    27972800                // Big pattern for the rest of the table-related queries.
     
    28092812                                . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE'
    28102813                                . '|(?:GRANT|REVOKE).*ON\s+TABLE'
    28112814                                . '|SHOW\s+(?:.*FROM|.*TABLE)'
    2812                                 . ')\s+\(*\s*`?([\w-]+)`?\s*\)*/is', $query, $maybe ) ) {
    2813                         return $maybe[1];
     2815                                . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
     2816                        return str_replace( '`', '', $maybe[1] );
    28142817                }
    28152818
    28162819                return false;
  • branches/3.9/tests/phpunit/tests/db.php

     
    392392         */
    393393        function data_get_table_from_query() {
    394394                $table = 'a_test_table_name';
     395                $db_table = '`a_test_db`.`another_test_table`';
    395396
    396397                $queries = array(
    397398                        // Basic
     
    494495                        "SHOW INDEX FROM $table",
    495496                );
    496497
    497                 foreach ( $queries as &$query ) {
    498                         $query = array( $query, $table );
     498                $querycount = count( $queries );
     499                for ( $ii = 0; $ii < $querycount; $ii++ ) {
     500                        $db_query = str_replace( $table, $db_table, $queries[ $ii ] );
     501                        $expected_db_table = str_replace( '`', '', $db_table );
     502
     503                        $queries[ $ii ] = array( $queries[ $ii ], $table );
     504                        $queries[] = array( $db_query, $expected_db_table );
    499505                }
    500506                return $queries;
    501507        }