<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[30400] trunk: WPDB: Force `STRICT_ALL_TABLES` to be enabled as soon as we connect to the MySQL server.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/30400">30400</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/30400","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>pento</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2014-11-20 01:45:10 +0000 (Thu, 20 Nov 2014)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>WPDB: Force `STRICT_ALL_TABLES` to be enabled as soon as we connect to the MySQL server.

This improves data integrity when inserting and updating rows in the database, particularly when trying to insert emoji into posts stored with character sets that don't support emoji.

See <a href="https://core.trac.wordpress.org/ticket/21212">#21212</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludeswpdbphp">trunk/src/wp-includes/wp-db.php</a></li>
<li><a href="#trunktestsphpunittestsdbphp">trunk/tests/phpunit/tests/db.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludeswpdbphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/wp-db.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/wp-db.php   2014-11-20 01:38:15 UTC (rev 30399)
+++ trunk/src/wp-includes/wp-db.php     2014-11-20 01:45:10 UTC (rev 30400)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -566,10 +566,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @access protected
</span><span class="cx" style="display: block; padding: 0 10px">         * @var array
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY',
-               'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', 'TRADITIONAL' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * A list of required SQL modes.
+        *
+        * @since 4.1.0
+        * @access protected
+        * @var array
+        */
+       protected $required_modes = array( 'STRICT_ALL_TABLES' );
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Whether to use mysqli over mysql.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 3.9.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -778,31 +786,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function set_sql_mode( $modes = array() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( empty( $modes ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( $this->use_mysqli ) {
-                               $res = mysqli_query( $this->dbh, 'SELECT @@SESSION.sql_mode' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $modes = $this->get_var( "SELECT @@SESSION.sql_mode" );
+                       if ( $modes ) {
+                               $modes = $original_modes = explode( ',', $modes );
</ins><span class="cx" style="display: block; padding: 0 10px">                         } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $res = mysql_query( 'SELECT @@SESSION.sql_mode', $this->dbh );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $modes = $original_modes = array();
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                       if ( empty( $res ) ) {
-                               return;
-                       }
-
-                       if ( $this->use_mysqli ) {
-                               $modes_array = mysqli_fetch_array( $res );
-                               if ( empty( $modes_array[0] ) ) {
-                                       return;
-                               }
-                               $modes_str = $modes_array[0];
-                       } else {
-                               $modes_str = mysql_result( $res, 0 );
-                       }
-
-                       if ( empty( $modes_str ) ) {
-                               return;
-                       }
-
-                       $modes = explode( ',', $modes_str );
</del><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $modes = array_change_key_case( $modes, CASE_UPPER );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -812,24 +801,36 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><span class="cx" style="display: block; padding: 0 10px">                 * @since 3.9.0
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @see wpdb::$incompatible_modes
-                *
</del><span class="cx" style="display: block; padding: 0 10px">                  * @param array $incompatible_modes An array of incompatible modes.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                $incompatible_modes = (array) apply_filters( 'incompatible_sql_modes', $this->incompatible_modes );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                foreach( $modes as $i => $mode ) {
-                       if ( in_array( $mode, $incompatible_modes ) ) {
-                               unset( $modes[ $i ] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Filter the list of required SQL modes to include.
+                *
+                * @since 4.1.0
+                *
+                * @param array $required_modes An array of required modes.
+                */
+               $required_modes = (array) apply_filters( 'required_sql_modes', $this->required_modes );
+
+               $modes = array_diff( $modes, $incompatible_modes );
+               $modes = array_unique( array_merge( $modes, $required_modes ) );
+
+               // Don't run SET SESSION if we have nothing to change.
+               if ( isset( $original_modes ) ) {
+                       sort( $original_modes );
+                       sort( $modes );
+                       if ( $original_modes === $modes ) {
+                               return;
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $modes_str = implode( ',', $modes );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $this->use_mysqli ) {
-                       mysqli_query( $this->dbh, "SET SESSION sql_mode='$modes_str'" );
-               } else {
-                       mysql_query( "SET SESSION sql_mode='$modes_str'", $this->dbh );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->query( "SET SESSION sql_mode='$modes_str'" );
+               if ( $this->last_error ) {
+                       dead_db();
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1482,8 +1483,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                } else if ( $this->dbh ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->has_connected = true;
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->set_charset( $this->dbh );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $this->ready = true;
</ins><span class="cx" style="display: block; padding: 0 10px">                         $this->set_sql_mode();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->ready = true;
</del><span class="cx" style="display: block; padding: 0 10px">                         $this->select( $this->dbname, $this->dbh );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        return true;
</span></span></pre></div>
<a id="trunktestsphpunittestsdbphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/db.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/db.php  2014-11-20 01:38:15 UTC (rev 30399)
+++ trunk/tests/phpunit/tests/db.php    2014-11-20 01:45:10 UTC (rev 30400)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -276,15 +276,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * Test that SQL modes are set correctly
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 26847
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_set_sql_mode() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function test_set_sql_mode() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $current_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $new_modes = array( 'IGNORE_SPACE', 'NO_AUTO_CREATE_USER' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $new_modes = $expected_modes = array( 'IGNORE_SPACE', 'NO_AUTO_CREATE_USER' );
+               $expected_modes[] = 'STRICT_ALL_TABLES';
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $wpdb->set_sql_mode( $new_modes );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $check_new_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( implode( ',', $new_modes ), $check_new_modes );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEqualSets( $expected_modes, explode( ',', $check_new_modes ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $wpdb->set_sql_mode( explode( ',', $current_modes ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -293,7 +296,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * Test that incompatible SQL modes are blocked
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 26847
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_set_incompatible_sql_mode() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function test_set_incompatible_sql_mode() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $current_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -301,7 +304,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $new_modes = array( 'IGNORE_SPACE', 'NO_ZERO_DATE', 'NO_AUTO_CREATE_USER' );
</span><span class="cx" style="display: block; padding: 0 10px">                $wpdb->set_sql_mode( $new_modes );
</span><span class="cx" style="display: block; padding: 0 10px">                $check_new_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertFalse( in_array( 'NO_ZERO_DATE', explode( ',', $check_new_modes ) ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertNotContains( 'NO_ZERO_DATE', explode( ',', $check_new_modes ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $wpdb->set_sql_mode( explode( ',', $current_modes ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -310,7 +313,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * Test that incompatible SQL modes can be changed
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 26847
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_set_allowed_incompatible_sql_mode() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function test_set_allowed_incompatible_sql_mode() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $current_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -322,7 +325,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                remove_filter( 'incompatible_sql_modes', array( $this, 'filter_allowed_incompatible_sql_mode' ), 1 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $check_new_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue( in_array( 'NO_ZERO_DATE', explode( ',', $check_new_modes ) ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertContains( 'NO_ZERO_DATE', explode( ',', $check_new_modes ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $wpdb->set_sql_mode( explode( ',', $current_modes ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -340,6 +343,146 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 21212
+        */
+       function test_set_sql_mode_strict() {
+               global $wpdb;
+               $wpdb->set_sql_mode();
+               $sql_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
+               $this->assertContains( 'STRICT_ALL_TABLES', explode( ',', $sql_modes ) );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_numeric_strings() {
+               global $wpdb;
+               $post_id = $this->factory->post->create();
+               $wpdb->update( $wpdb->posts, array( 'post_parent' => 4 ), array( 'ID' => $post_id ), array( '%s' ) );
+               $this->assertContains( "`post_parent` = '4'", $wpdb->last_query );
+               $this->assertEmpty( $wpdb->last_error );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_numeric_strings_using_query() {
+               global $wpdb;
+               $post_id = $this->factory->post->create();
+               $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %s WHERE ID = %s", '4', $post_id ) );
+               $this->assertEmpty( $wpdb->last_error );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_nan() {
+               global $wpdb;
+               $post_id = $this->factory->post->create();
+               $suppress = $wpdb->suppress_errors( true );
+               $wpdb->update( $wpdb->posts, array( 'post_parent' => 'foo' ), array( 'ID' => $post_id ), array( '%s' ) );
+               $this->assertContains( "`post_parent` = 'foo'", $wpdb->last_query );
+               $this->assertContains( 'Incorrect integer value', $wpdb->last_error );
+               $wpdb->suppress_errors( $suppress );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_nan_using_query() {
+               global $wpdb;
+               $post_id = $this->factory->post->create();
+               $suppress = $wpdb->suppress_errors( true );
+               $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %s WHERE ID = %s", 'foo', $post_id ) );
+               $this->assertContains( 'Incorrect integer value', $wpdb->last_error );
+               $wpdb->suppress_errors( $suppress );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_number_start_of_string() {
+               global $wpdb;
+               $post_id = $this->factory->post->create();
+               $suppress = $wpdb->suppress_errors( true );
+               $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %s WHERE ID = %s", '4foo', $post_id ) );
+               $this->assertContains( "Data truncated for column 'post_parent'", $wpdb->last_error );
+               $wpdb->suppress_errors( $suppress );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_booleans_true() {
+               global $wpdb;
+               $user_id = $this->factory->user->create();
+               $wpdb->query( "UPDATE $wpdb->users SET user_status = true WHERE ID = $user_id" );
+               $this->assertEmpty( $wpdb->last_error );
+               $user = get_userdata( $user_id );
+               $this->assertSame( '1', $user->user_status );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_booleans_false() {
+               global $wpdb;
+               $user_id = $this->factory->user->create();
+               $wpdb->query( "UPDATE $wpdb->users SET user_status = false WHERE ID = $user_id" );
+               $this->assertEmpty( $wpdb->last_error );
+               $user = get_userdata( $user_id );
+               $this->assertEquals( '0', $user->user_status );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_zero_date_is_valid() {
+               global $wpdb;
+               $user_id = $this->factory->user->create();
+               $wpdb->query( "UPDATE $wpdb->users SET user_registered = '0000-00-00' WHERE ID = $user_id" );
+               $this->assertEmpty( $wpdb->last_error );
+               $user = get_userdata( $user_id );
+               $this->assertEquals( '0000-00-00 00:00:00', $user->user_registered );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_zero_datetime_is_valid() {
+               global $wpdb;
+               $user_id = $this->factory->user->create();
+               $wpdb->query( "UPDATE $wpdb->users SET user_registered = '0000-00-00 00:00:00' WHERE ID = $user_id" );
+               $this->assertEmpty( $wpdb->last_error );
+               $user = get_userdata( $user_id );
+               $this->assertEquals( '0000-00-00 00:00:00', $user->user_registered );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_invalid_dates_are_invalid() {
+               global $wpdb;
+               $user_id = $this->factory->user->create();
+               $suppress = $wpdb->suppress_errors( true );
+               $wpdb->query( "UPDATE $wpdb->users SET user_registered = '2014-02-29 00:00:00' WHERE ID = $user_id" );
+               $this->assertContains( 'Incorrect datetime value', $wpdb->last_error );
+               $wpdb->suppress_errors( $suppress );
+       }
+
+       /**
+        * @ticket 21212
+        */
+       function test_strict_mode_nulls_are_invalid() {
+               global $wpdb;
+               $user_id = $this->factory->user->create();
+               $suppress = $wpdb->suppress_errors( true );
+               $wpdb->query( "UPDATE $wpdb->users SET user_nicename = NULL WHERE ID = $user_id" );
+               $this->assertContains( 'cannot be null', $wpdb->last_error );
+               $wpdb->suppress_errors( $suppress );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 25604
</span><span class="cx" style="display: block; padding: 0 10px">         * @expectedIncorrectUsage wpdb::prepare
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -766,7 +909,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @ ticket 21212
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @ticket 21212
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        function test_pre_get_col_charset_filter() {
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'pre_get_col_charset', array( $this, 'filter_pre_get_col_charset' ), 10, 3 );
</span></span></pre>
</div>
</div>

</body>
</html>