Make WordPress Core


Ignore:
Timestamp:
11/10/2014 05:39:50 AM (10 years ago)
Author:
pento
Message:

wpdb::flush() was not flushing results correctly when using mysqli.

This change also allows stored procedures or queries made with mysqli_multi_query() to be flushed.

Includes unit tests.

Fixes #28155.

Props soulseekah.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/db.php

    r29701 r30297  
    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
     473        $suppress = $wpdb->suppress_errors( true );
     474
     475        $wpdb->query( 'DROP PROCEDURE IF EXISTS `test_mysqli_flush_sync_procedure`' );
     476        $wpdb->query( 'CREATE PROCEDURE `test_mysqli_flush_sync_procedure`() BEGIN
     477            SELECT ID FROM `' . $wpdb->posts . '` LIMIT 1;
     478        END' );
     479
     480        if ( count( $wpdb->get_results( 'SHOW CREATE PROCEDURE `test_mysqli_flush_sync_procedure`' ) ) < 1 ) {
     481            $wpdb->suppress_errors( $suppress );
     482            $this->markTestSkipped( 'procedure could not be created (missing privileges?)' );
     483        }
     484
     485        $this->factory->post->create();
     486
     487        $this->assertNotEmpty( $wpdb->get_results( 'CALL `test_mysqli_flush_sync_procedure`' ) );
     488        $this->assertNotEmpty( $wpdb->get_results( "SELECT ID FROM `{$wpdb->posts}` LIMIT 1" ) );
     489
     490        $wpdb->query( 'DROP PROCEDURE IF EXISTS `test_mysqli_flush_sync_procedure`' );
     491        $wpdb->suppress_errors( $suppress );
     492    }
    461493}
Note: See TracChangeset for help on using the changeset viewer.