]> git.mjollnir.org Git - moodle.git/commitdiff
Enforce strict mode in mysqli session in order to get consistent behaviour
authorstronk7 <stronk7>
Fri, 28 Aug 2009 11:17:47 +0000 (11:17 +0000)
committerstronk7 <stronk7>
Fri, 28 Aug 2009 11:17:47 +0000 (11:17 +0000)
in various operations (casting, altering columns...)

lib/dml/mysqli_native_moodle_database.php

index 1722d8358b5fca768529f83d438e086549296cdd..3a243f94ec58a60da9e715d49024b06907f74118 100644 (file)
@@ -173,6 +173,19 @@ class mysqli_native_moodle_database extends moodle_database {
         $this->mysqli->set_charset('utf8');
         $this->query_end(true);
 
+        // If available, enforce strict mode for the session. That guaranties
+        // standard behaviour under some situations, avoiding some MySQL nasty
+        // habits like truncating data or performing some transparent cast losses.
+        // With strict mode enforced, Moodle DB layer will be consistenly throwing
+        // the corresponding exceptions as expected.
+        $si = $this->get_server_info();
+        if (version_compare($si['version'], '5.0.2', '>=')) {
+            $sql = "SET SESSION sql_mode = 'STRICT_ALL_TABLES'";
+            $this->query_start($sql, null, SQL_QUERY_AUX);
+            $result = $this->mysqli->query($sql);
+            $this->query_end($result);
+        }
+
         return true;
     }