From 907995af21b7ff9f224548f1e7f8b544174491b2 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 2 Sep 2017 14:12:53 +1000 Subject: [PATCH] Refactor sqlMode setting to be checking if 'STRICT_TRANS_TABLES' is present or not --- CRM/Core/DAO.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 60ab91ab64..1f16248a9d 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -118,12 +118,12 @@ class CRM_Core_DAO extends DB_DataObject { } $factory = new CRM_Contact_DAO_Factory(); CRM_Core_DAO::setFactory($factory); + $currentSqlMode = CRM_Core_DAO::singleValueQuery("SELECT @@GLOBAL.sql_mode"); + $currentModes = explode(',', $currentSqlMode); if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) { - if (self::supportsFullGroupBy()) { - CRM_Core_DAO::executeQuery("SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES'"); - } - else { - CRM_Core_DAO::executeQuery("SET SESSION sql_mode = 'STRICT_TRANS_TABLES'"); + if (!in_array('STRICT_TRANS_TABLES', $currentModes)) { + $modes = array_merge(array('STRICT_TRANS_TABLES'), $currentModes); + CRM_Core_DAO::executeQuery("SET SESSION sql_mode = %1", array(1 => array(implode(',', $modes), 'String'))); } } CRM_Core_DAO::executeQuery('SET NAMES utf8'); @@ -412,7 +412,7 @@ class CRM_Core_DAO extends DB_DataObject { * @return mixed */ public static function supportsFullGroupBy() { - return version_compare(CRM_Core_DAO::singleValueQuery('SELECT VERSION()'), '5.7.0', '>='); + return version_compare(CRM_Core_DAO::singleValueQuery('SELECT VERSION()'), '5.7', '>='); } /** -- 2.25.1