Make WordPress Core

Changeset 32415


Ignore:
Timestamp:
05/06/2015 09:12:33 PM (9 years ago)
Author:
johnbillion
Message:

WPDB: Allow queries to reference tables in the dbname.tablename format, and allow table names to contain any valid character, rather than just ASCII.

Merge of [32368] to the 3.8 branch.

Props pento, willstedt for the initial patch.

See #32090.

Location:
branches/3.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.8/src/wp-includes/wp-db.php

    r32406 r32415  
    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' );
     
    24062409                . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
    24072410                . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
    2408                 . ')\s+`?([\w-]+)`?/is', $query, $maybe ) ) {
    2409             return $maybe[1];
     2411                . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
     2412            return str_replace( '`', '', $maybe[1] );
    24102413        }
    24112414
     
    24142417                . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    24152418                . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    2416                 . ')\W([\w-]+)\W/is', $query, $maybe ) ) {
    2417             return $maybe[1];
     2419                . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
     2420            return str_replace( '`', '', $maybe[1] );
    24182421        }
    24192422
     
    24332436                . '|(?:GRANT|REVOKE).*ON\s+TABLE'
    24342437                . '|SHOW\s+(?:.*FROM|.*TABLE)'
    2435                 . ')\s+\(*\s*`?([\w-]+)`?\s*\)*/is', $query, $maybe ) ) {
    2436             return $maybe[1];
     2438                . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
     2439            return str_replace( '`', '', $maybe[1] );
    24372440        }
    24382441
  • branches/3.8/tests/phpunit/tests/db.php

    r32390 r32415  
    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(
     
    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;
Note: See TracChangeset for help on using the changeset viewer.