From 4404bf1651c7ba6602e50ffe47b6448c14b9d0e8 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 9 Oct 2016 07:01:19 +0000 Subject: [PATCH 1/2] The creation of unique keys failed for MariaDB --- boot.php | 2 +- include/dbstructure.php | 5 +++-- update.php | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/boot.php b/boot.php index 348b786e4d..f39fb0369c 100644 --- a/boot.php +++ b/boot.php @@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_VERSION', '3.5.1-dev' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1205 ); +define ( 'DB_UPDATE_VERSION', 1206 ); /** * @brief Constant with a HTML line break. diff --git a/include/dbstructure.php b/include/dbstructure.php index d287b5e6d9..fdf09d90de 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -166,7 +166,8 @@ function update_structure($verbose, $action, $tables=null, $definition=null) { @$db->q($sql_config); // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements - if (version_compare($db->server_info(), '5.7.4') >= 0) { + if ((version_compare($db->server_info(), '5.7.4') >= 0) AND + !(strpos($db->server_info(), 'MariaDB') !== false)) { $ignore = ''; }else { $ignore = ' IGNORE'; @@ -196,7 +197,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) { if ($current_index_definition != $new_index_definition && substr($indexname, 0, 6) != 'local_') { $sql2=db_drop_index($indexname); if ($sql3 == "") - $sql3 = "ALTER TABLE `".$name."` ".$sql2; + $sql3 = "ALTER".$ignore." TABLE `".$name."` ".$sql2; else $sql3 .= ", ".$sql2; } diff --git a/update.php b/update.php index 01fa220673..7560911134 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Sun, 9 Oct 2016 07:18:52 +0000 Subject: [PATCH 2/2] Ensure that with multiple entries the newest one will be fetched --- include/Core/Config.php | 4 ++-- include/Core/PConfig.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/Core/Config.php b/include/Core/Config.php index e5515efafc..a93f188148 100644 --- a/include/Core/Config.php +++ b/include/Core/Config.php @@ -32,7 +32,7 @@ class Config { public static function load($family) { global $a; - $r = q("SELECT `v`, `k` FROM `config` WHERE `cat` = '%s'", dbesc($family)); + $r = q("SELECT `v`, `k` FROM `config` WHERE `cat` = '%s' ORDER BY `cat`, `k`, `id`", dbesc($family)); if(count($r)) { foreach($r as $rr) { $k = $rr['k']; @@ -90,7 +90,7 @@ class Config { } } - $ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", + $ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s' ORDER BY `id` DESC LIMIT 1", dbesc($family), dbesc($key) ); diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index 082f1c05c2..de8994d1de 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -29,7 +29,7 @@ class PConfig { */ public static function load($uid,$family) { global $a; - $r = q("SELECT `v`,`k` FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d", + $r = q("SELECT `v`,`k` FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d ORDER BY `cat`, `k`, `id`", dbesc($family), intval($uid) ); @@ -83,7 +83,7 @@ class PConfig { } } - $ret = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1", + $ret = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' ORDER BY `id` DESC LIMIT 1", intval($uid), dbesc($family), dbesc($key)