Use server_info to fallback from ANY_VALUE if needed

This commit is contained in:
Alexandre Alapetite 2017-04-15 12:40:32 +02:00
parent d2b3e0daf5
commit 5007be3cf5

View file

@ -20,6 +20,7 @@ class dba {
private $driver; private $driver;
public $connected = false; public $connected = false;
public $error = false; public $error = false;
private $_server_info = '';
function __construct($server, $user, $pass, $db, $install = false) { function __construct($server, $user, $pass, $db, $install = false) {
$a = get_app(); $a = get_app();
@ -103,18 +104,20 @@ class dba {
* @return string * @return string
*/ */
public function server_info() { public function server_info() {
switch ($this->driver) { if ($this->_server_info == '') {
case 'pdo': switch ($this->driver) {
$version = $this->db->getAttribute(PDO::ATTR_SERVER_VERSION); case 'pdo':
break; $this->_server_info = $this->db->getAttribute(PDO::ATTR_SERVER_VERSION);
case 'mysqli': break;
$version = $this->db->server_info; case 'mysqli':
break; $this->_server_info = $this->db->server_info;
case 'mysql': break;
$version = mysql_get_server_info($this->db); case 'mysql':
break; $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) { 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). //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 //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(), or nothing () in old MySQL 5.6- //A standard fallback is to use MIN()
//TODO: Skip this line when we know we are on a platform supporting ANY_VALUE() if (version_compare($server_info, '5.7.5', '<') ||
return str_ireplace('ANY_VALUE(', 'MIN(', $sql); (stripos($server_info, 'MariaDB') !== false)) {
$sql = str_ireplace('ANY_VALUE(', 'MIN(', $sql);
}
return $sql;
} }
// Function: q($sql,$args); // Function: q($sql,$args);