]> git.mxchange.org Git - friendica.git/commitdiff
Use server_info to fallback from ANY_VALUE if needed
authorAlexandre Alapetite <alexandre@alapetite.fr>
Sat, 15 Apr 2017 10:40:32 +0000 (12:40 +0200)
committerAlexandre Alapetite <alexandre@alapetite.fr>
Sat, 15 Apr 2017 10:40:32 +0000 (12:40 +0200)
include/dba.php

index 96df072cfa0b0921943c1fa31bdd4b41f5cfa2b0..665580124d895685cfebfe3c9c9616fa2599f25a 100644 (file)
@@ -20,6 +20,7 @@ class dba {
        private $driver;
        public  $connected = false;
        public  $error = false;
+       private $_server_info = '';
 
        function __construct($server, $user, $pass, $db, $install = false) {
                $a = get_app();
@@ -103,18 +104,20 @@ class dba {
         * @return string
         */
        public function server_info() {
-               switch ($this->driver) {
-                       case 'pdo':
-                               $version = $this->db->getAttribute(PDO::ATTR_SERVER_VERSION);
-                               break;
-                       case 'mysqli':
-                               $version = $this->db->server_info;
-                               break;
-                       case 'mysql':
-                               $version = mysql_get_server_info($this->db);
-                               break;
+               if ($this->_server_info == '') {
+                       switch ($this->driver) {
+                               case 'pdo':
+                                       $this->_server_info = $this->db->getAttribute(PDO::ATTR_SERVER_VERSION);
+                                       break;
+                               case 'mysqli':
+                                       $this->_server_info = $this->db->server_info;
+                                       break;
+                               case 'mysql':
+                                       $this->_server_info = mysql_get_server_info($this->db);
+                                       break;
+                       }
                }
-               return $version;
+               return $this->_server_info;
        }
 
        /**
@@ -505,11 +508,16 @@ function dbesc($str) {
 }
 
 function any_value_fallback($sql) {
+       global $db;
+       $server_info = $db->server_info();
        //Considerations for Standard SQL, or MySQL with ONLY_FULL_GROUP_BY (default since 5.7.5).
-       //ANY_VALUE() is available from MySQL 5.7 https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html
-       //A standard fallback is to use MIN(), or nothing () in old MySQL 5.6-
-       //TODO: Skip this line when we know we are on a platform supporting ANY_VALUE()
-       return str_ireplace('ANY_VALUE(', 'MIN(', $sql);
+       //ANY_VALUE() is available from MySQL 5.7.5 https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html
+       //A standard fallback is to use MIN()
+       if (version_compare($server_info, '5.7.5', '<') ||
+               (stripos($server_info, 'MariaDB') !== false)) {
+               $sql = str_ireplace('ANY_VALUE(', 'MIN(', $sql);
+       }
+       return $sql;
 }
 
 // Function: q($sql,$args);