mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-02 03:34:33 +00:00
Ensure compatibility with MySQL 5.6 which has stricter SQL modes by default.
Disables NO_ZERO_DATE, ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, STRICT_ALL_TABLES, TRADITIONAL. Introduces wpdb::set_sql_mode() with an incompatible_sql_modes filter so a plugin can alter the set mode after the fact. props pento. fixes #26847. git-svn-id: https://develop.svn.wordpress.org/trunk@27072 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -126,4 +126,71 @@ class Tests_DB extends WP_UnitTestCase {
|
||||
$sql = $wpdb->prepare( "UPDATE test_table SET string_column = '%%f is a float, %%d is an int %d, %%s is a string', field = %s", 3, '4' );
|
||||
$this->assertEquals( "UPDATE test_table SET string_column = '%f is a float, %d is an int 3, %s is a string', field = '4'", $sql );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that SQL modes are set correctly
|
||||
* @ticket 26847
|
||||
*/
|
||||
public function test_set_sql_mode() {
|
||||
global $wpdb;
|
||||
|
||||
$current_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
|
||||
|
||||
$new_modes = array( 'IGNORE_SPACE', 'NO_AUTO_CREATE_USER' );
|
||||
$wpdb->set_sql_mode( $new_modes );
|
||||
$check_new_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
|
||||
$this->assertEquals( implode( ',', $new_modes ), $check_new_modes );
|
||||
|
||||
$wpdb->set_sql_mode( explode( ',', $current_modes ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that incompatible SQL modes are blocked
|
||||
* @ticket 26847
|
||||
*/
|
||||
public function test_set_incompatible_sql_mode() {
|
||||
global $wpdb;
|
||||
|
||||
$current_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
|
||||
|
||||
$new_modes = array( 'IGNORE_SPACE', 'NO_ZERO_DATE', 'NO_AUTO_CREATE_USER' );
|
||||
$wpdb->set_sql_mode( $new_modes );
|
||||
$check_new_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
|
||||
$this->assertFalse( in_array( 'NO_ZERO_DATE', explode( ',', $check_new_modes ) ) );
|
||||
|
||||
$wpdb->set_sql_mode( explode( ',', $current_modes ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that incompatible SQL modes can be changed
|
||||
* @ticket 26847
|
||||
*/
|
||||
public function test_set_allowed_incompatible_sql_mode() {
|
||||
global $wpdb;
|
||||
|
||||
$current_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
|
||||
|
||||
$new_modes = array( 'IGNORE_SPACE', 'NO_ZERO_DATE', 'NO_AUTO_CREATE_USER' );
|
||||
|
||||
add_filter( 'incompatible_sql_modes', array( $this, 'filter_allowed_incompatible_sql_mode' ), 1, 1 );
|
||||
$wpdb->set_sql_mode( $new_modes );
|
||||
remove_filter( 'incompatible_sql_modes', array( $this, 'filter_allowed_incompatible_sql_mode' ), 1 );
|
||||
|
||||
$check_new_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
|
||||
$this->assertTrue( in_array( 'NO_ZERO_DATE', explode( ',', $check_new_modes ) ) );
|
||||
|
||||
$wpdb->set_sql_mode( explode( ',', $current_modes ) );
|
||||
}
|
||||
|
||||
public function filter_allowed_incompatible_sql_mode( $modes ) {
|
||||
$pos = array_search( 'NO_ZERO_DATE', $modes );
|
||||
$this->assertGreaterThanOrEqual( 0, $pos );
|
||||
|
||||
if ( FALSE === $pos ) {
|
||||
return $modes;
|
||||
}
|
||||
|
||||
unset( $modes[ $pos ] );
|
||||
return $modes;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user