From a2ed62b3c4fca65dc87888ea835e1d33aadbf75c Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 8 Nov 2017 08:09:50 +1100 Subject: [PATCH] CRM-21363 Only implement ONLY_FULL_GROUP_BY if it is in the default global sql_modes --- CRM/Core/DAO.php | 2 +- CRM/Utils/SQL.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 1077d8cbe0..503a896e76 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -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)) { diff --git a/CRM/Utils/SQL.php b/CRM/Utils/SQL.php index 1e8897f802..fb4c41273b 100644 --- a/CRM/Utils/SQL.php +++ b/CRM/Utils/SQL.php @@ -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; + } + } -- 2.25.1