From ca929946f897f869e5f44cd6cdea70d10b240d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Thu, 6 Feb 2025 12:15:40 +0000 Subject: [PATCH] Delete on stats_mysql_query_events without LIMIT SQLite amalgamation doesn't support DELETE with ORDER BY . Thus the DELETE with ORDER BY was replaced by a SELECT to retrieve the maximum id, followed by a DELETE up to that id. --- lib/MySQL_Logger.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/MySQL_Logger.cpp b/lib/MySQL_Logger.cpp index d245ebe6d..28b538fb2 100644 --- a/lib/MySQL_Logger.cpp +++ b/lib/MySQL_Logger.cpp @@ -1460,7 +1460,9 @@ int MySQL_Logger::processEvents(SQLite3DB * statsdb , SQLite3DB * statsdb_disk) int rows_to_keep = maxInMemorySize - events.size(); if (current_rows > rows_to_keep) { int rows_to_delete = (current_rows - rows_to_keep); - string delete_stmt = "DELETE FROM stats_mysql_query_events ORDER BY id LIMIT " + to_string(rows_to_delete); + string query = "SELECT MAX(id) FROM (SELECT id FROM stats_mysql_query_events ORDER BY id LIMIT " + to_string(rows_to_delete) + ")"; + int maxIdToDelete = statsdb->return_one_int(query.c_str()); + string delete_stmt = "DELETE FROM stats_mysql_query_events WHERE id <= " + to_string(maxIdToDelete); statsdb->execute(delete_stmt.c_str()); } }