Make WordPress Core

Ticket #32090: 32090-40.patch

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

4.0

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

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

     
    491491         */
    492492        function data_get_table_from_query() {
    493493                $table = 'a_test_table_name';
     494                $db_table = '`a_test_db`.`another_test_table`';
    494495
    495496                $queries = array(
    496497                        // Basic
     
    593594                        "SHOW INDEX FROM $table",
    594595                );
    595596
    596                 foreach ( $queries as &$query ) {
    597                         $query = array( $query, $table );
     597                $querycount = count( $queries );
     598                for ( $ii = 0; $ii < $querycount; $ii++ ) {
     599                        $db_query = str_replace( $table, $db_table, $queries[ $ii ] );
     600                        $expected_db_table = str_replace( '`', '', $db_table );
     601
     602                        $queries[ $ii ] = array( $queries[ $ii ], $table );
     603                        $queries[] = array( $db_query, $expected_db_table );
    598604                }
    599605                return $queries;
    600606        }