Make WordPress Core

Ticket #28155: 28155.2.diff

File 28155.2.diff, 2.3 KB (added by soulseekah, 9 years ago)

patch and unit tests

  • tests/phpunit/tests/db.php

     
    458458                $this->assertEquals( $expected2, $wpdb->last_query );
    459459                $wpdb->suppress_errors( $suppress );
    460460        }
     461
     462        /**
     463         * mysqli_ incorrect flush and further sync issues.
     464         *
     465         * @ticket 28155
     466         */
     467        function test_mysqli_flush_sync() {
     468                global $wpdb;
     469                if ( !$wpdb->use_mysqli )
     470                        $this->markTestSkipped( 'mysqli not being used' );
     471
     472                $suppress = $wpdb->suppress_errors( true );
     473
     474                $wpdb->query( 'DROP PROCEDURE IF EXISTS `test_mysqli_flush_sync_procedure`' );
     475                $wpdb->query( 'CREATE PROCEDURE `test_mysqli_flush_sync_procedure`() BEGIN
     476                        SELECT ID FROM `' . $wpdb->posts . '` LIMIT 1;
     477                END' );
     478
     479                if ( count( $wpdb->get_results( 'SHOW CREATE PROCEDURE `test_mysqli_flush_sync_procedure`' ) ) < 1 ) {
     480                        $wpdb->suppress_errors( $suppress );
     481                        $this->markTestSkipped( 'procedure could not be created (missing privileges?)' );
     482                }
     483
     484                $this->factory->post->create();
     485
     486                $this->assertNotEmpty( $wpdb->get_results( 'CALL `test_mysqli_flush_sync_procedure`' ) );
     487                $this->assertNotEmpty( $wpdb->get_results( "SELECT ID FROM `{$wpdb->posts}` LIMIT 1" ) );
     488
     489                $wpdb->query( 'DROP PROCEDURE IF EXISTS `test_mysqli_flush_sync_procedure`' );
     490                $wpdb->suppress_errors( $suppress );
     491        }
    461492}
  • src/wp-includes/wp-db.php

     
    13241324                $this->rows_affected = $this->num_rows = 0;
    13251325                $this->last_error  = '';
    13261326
    1327                 if ( is_resource( $this->result ) ) {
    1328                         if ( $this->use_mysqli ) {
    1329                                 mysqli_free_result( $this->result );
    1330                         } else {
    1331                                 mysql_free_result( $this->result );
    1332                         }
     1327                if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
     1328                        mysqli_free_result( $this->result );
     1329                        $this->result = null;
     1330                        if ( empty( $this->dbh ) || !( $this->dbh instanceof mysqli ) )
     1331                                return; // Sanity check before using the handle
     1332                        while ( $this->dbh->more_results() )
     1333                                $this->dbh->next_result();
     1334                } else if ( is_resource( $this->result ) ) {
     1335                        mysql_free_result( $this->result );
    13331336                }
    13341337        }
    13351338