$sqlMode = CRM_Core_DAO::singleValueQuery('SELECT @@sql_mode');
//return if ONLY_FULL_GROUP_BY is not enabled.
- if (CRM_Core_DAO::supportsFullGroupBy() && !empty($sqlMode) && in_array('ONLY_FULL_GROUP_BY', explode(',', $sqlMode))) {
+ if (CRM_Utils_SQL::supportsFullGroupBy() && !empty($sqlMode) && in_array('ONLY_FULL_GROUP_BY', explode(',', $sqlMode))) {
$regexToExclude = '/(ROUND|AVG|COUNT|GROUP_CONCAT|SUM|MAX|MIN)\(/i';
foreach ($selectClauses as $key => $val) {
$aliasArray = preg_split('/ as /i', $val);
}
$factory = new CRM_Contact_DAO_Factory();
CRM_Core_DAO::setFactory($factory);
- $currentSqlMode = CRM_Core_DAO::singleValueQuery("SELECT @@GLOBAL.sql_mode");
- $currentModes = explode(',', $currentSqlMode);
+ $currentModes = CRM_Utils_SQL::getSqlModes();
if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) {
- if (self::supportsFullGroupBy() && !in_array('ONLY_FULL_GROUP_BY', $currentModes)) {
+ if (CRM_Utils_SQL::supportsFullGroupBy() && !in_array('ONLY_FULL_GROUP_BY', $currentModes)) {
$currentModes[] = 'ONLY_FULL_GROUP_BY';
}
if (!in_array('STRICT_TRANS_TABLES', $currentModes)) {
}
}
- /**
- * Does this System support the MYSQL mode ONLY_FULL_GROUP_BY
- * @return mixed
- */
- public static function supportsFullGroupBy() {
- return version_compare(CRM_Core_DAO::singleValueQuery('SELECT VERSION()'), '5.7', '>=');
- }
-
/**
* Defines the default key as 'id'.
*
return $clauses;
}
+ /**
+ * Get current sqlModes of the session
+ * @return array
+ */
+ public static function getSqlModes() {
+ $sqlModes = explode(',', CRM_Core_DAO::singleValueQuery('SELECT @@sql_mode'));
+ return $sqlModes;
+ }
+
+ /**
+ * Does this System support the MYSQL mode ONLY_FULL_GROUP_BY
+ * @return mixed
+ */
+ public static function supportsFullGroupBy() {
+ return version_compare(CRM_Core_DAO::singleValueQuery('SELECT VERSION()'), '5.7', '>=');
+ }
+
}
* Test that known sql modes are present in session.
*/
public function testSqlModePresent() {
- $currentSqlModes = CRM_Core_DAO::singleValueQuery("SELECT @@sql_mode");
- $sqlModes = explode(',', $currentSqlModes);
+ $sqlModes = CRM_Utils_SQL::getSqlModes();
// assert we have strict trans
$this->assertContains('STRICT_TRANS_TABLES', $sqlModes);
- if (CRM_Core_DAO::supportsFullGroupBy()) {
+ if ($this->_supportFullGroupBy) {
$this->assertContains('ONLY_FULL_GROUP_BY', $sqlModes);
}
}
*/
private static $dbInit = FALSE;
+ /**
+ * Does the current setup support ONLY_FULL_GROUP_BY mode
+ */
+ protected $_supportFullGroupBy;
+
/**
* Database connection.
*
// Get and save a connection to the database
$this->_dbconn = $this->getConnection();
+ $this->_supportFullGroupBy = CRM_Utils_SQL::supportsFullGroupBy();
+
// reload database before each test
// $this->_populateDB();