From b387ef06aeebb41b781caa896085b41a98eb6607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Thu, 17 Jun 2021 17:26:11 +0200 Subject: [PATCH] B #5400,- : Bug fixes backport * Fix PoolSQL::exist for PostgreSQL * Sort hooks by execution id --- src/hm/HookLog.cc | 8 +++----- src/pool/PoolSQL.cc | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/hm/HookLog.cc b/src/hm/HookLog.cc index 280e0e563e..ee257e1dcf 100644 --- a/src/hm/HookLog.cc +++ b/src/hm/HookLog.cc @@ -66,11 +66,7 @@ int HookLog::_dump_log(int hkid, int exec_id, std::string &xml_log) cmd << "SELECT body FROM "<< table; - if ( hkid == -1 ) - { - cmd << " ORDER BY hkid DESC"; - } - else + if ( hkid != -1 ) { cmd << " WHERE hkid = " << hkid; } @@ -80,6 +76,8 @@ int HookLog::_dump_log(int hkid, int exec_id, std::string &xml_log) cmd << " AND exeid = " << exec_id; } + cmd << " ORDER BY hkid DESC, exeid"; + xml_log.append(""); cb.set_callback(&xml_log); diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index 80321e14be..317079970a 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -228,20 +228,31 @@ PoolObjectSQL * PoolSQL::get_ro(int oid) void PoolSQL::exist(const string& id_str, std::set& id_list) { std::vector existing_items; - std::set::iterator iterator; one_util::split_unique(id_str, ',', id_list); - search(existing_items, table.c_str(), "1 order by 1 ASC"); + if (Nebula::instance().get_db_backend() == "postgresql") + { + search(existing_items, table.c_str(), "true order by 1 ASC"); + } + else + { + search(existing_items, table.c_str(), "1 order by 1 ASC"); + } - for (iterator = id_list.begin(); iterator != id_list.end(); ++iterator) + for (auto iterator = id_list.begin(); iterator != id_list.end();) { if (!std::binary_search(existing_items.begin(), existing_items.end(), *iterator)) { - id_list.erase(iterator); + iterator = id_list.erase(iterator); + } + else + { + ++iterator; } } } + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */