CRM-21363 Only implement ONLY_FULL_GROUP_BY if it is in the default global sql_modes
authorSeamus Lee <seamuslee001@gmail.com>
Tue, 7 Nov 2017 21:09:50 +0000 (08:09 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Tue, 7 Nov 2017 21:09:50 +0000 (08:09 +1100)
CRM/Core/DAO.php
CRM/Utils/SQL.php

index 1077d8cbe0da8d4045390723d409da5a58b44091..503a896e76464152f6d5852ec0626500463cf56a 100644 (file)
@@ -120,7 +120,7 @@ class CRM_Core_DAO extends DB_DataObject {
     CRM_Core_DAO::setFactory($factory);
     $currentModes = CRM_Utils_SQL::getSqlModes();
     if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) {
-      if (CRM_Utils_SQL::supportsFullGroupBy() && !in_array('ONLY_FULL_GROUP_BY', $currentModes)) {
+      if (CRM_Utils_SQL::supportsFullGroupBy() && !in_array('ONLY_FULL_GROUP_BY', $currentModes) && CRM_Utils_SQL::isGroupByModeInDefault()) {
         $currentModes[] = 'ONLY_FULL_GROUP_BY';
       }
       if (!in_array('STRICT_TRANS_TABLES', $currentModes)) {
index 1e8897f802fe720772b935a2a6ceb0ccf8766ca7..fb4c41273b068f0113ef6d6618be366dbcd65310 100644 (file)
@@ -96,4 +96,19 @@ class CRM_Utils_SQL {
     return FALSE;
   }
 
+  /**
+   * CHeck if ONLY_FULL_GROUP_BY is in the global sql_modes
+   * @return bool
+   */
+  public static function isGroupByModeInDefault() {
+    if (!self::supportsFullGroupBy()) {
+      return FALSE;
+    }
+    $sqlModes = explode(',', CRM_Core_DAO::singleValueQuery('SELECT @@global.sql_mode'));
+    if (!in_array('ONLY_FULL_GROUP_BY', $sqlModes)) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+
 }