From 758210e085dfa307b04bb95c42ee6d0af74b0fbe Mon Sep 17 00:00:00 2001 From: Ahmed Abdelsalam Date: Fri, 10 Jan 2025 17:31:29 +0100 Subject: [PATCH] Fix: Use regular expressions to count & filter compliance results --- src/manage_pg.c | 8 ++++---- src/manage_sql.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/manage_pg.c b/src/manage_pg.c index ada46ee6c..a6aedacf4 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -938,15 +938,15 @@ manage_create_sql_functions () " CASE" " WHEN (SELECT count(*) FROM results" " WHERE report = report_id" - " AND description LIKE 'Compliant:%%NO%%') > 0" + " AND description ~ '^Compliant:[\\s]*NO[\\s]*') > 0" " THEN RETURN 'no';" " WHEN (SELECT count(*) FROM results" " WHERE report = report_id" - " AND description LIKE 'Compliant:%%INCOMPLETE%%') > 0" + " AND description ~ '^Compliant:[\\s]*INCOMPLETE[\\s]*') > 0" " THEN RETURN 'incomplete';" " WHEN (SELECT count(*) FROM results" " WHERE report = report_id" - " AND description LIKE 'Compliant:%%YES%%') > 0" + " AND description ~ '^Compliant:[\\s]*YES[\\s]*') > 0" " THEN RETURN 'yes';" " ELSE RETURN 'undefined';" " END CASE;" @@ -962,7 +962,7 @@ manage_create_sql_functions () " BEGIN" " WITH compliance_count AS" " (SELECT count(*) AS total FROM results WHERE report = report_id" - " AND description LIKE 'Compliant:%%' || compliance || '%%')" + " AND description ~ ('^Compliant:[\\s]*' || compliance || '[\\s]*'))" " SELECT total FROM compliance_count" " INTO count;" " RETURN count;" diff --git a/src/manage_sql.c b/src/manage_sql.c index 4578ce058..59ae301f2 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -22118,7 +22118,7 @@ report_compliance_by_uuid (const char *report_id, *compliance_yes = sql_int ("SELECT count(*) FROM results" " WHERE report = %llu" - " AND description LIKE 'Compliant:%%YES%%';", + " AND description ~ '^Compliant:[\\s]*YES[\\s]*';", report); } @@ -22127,7 +22127,7 @@ report_compliance_by_uuid (const char *report_id, *compliance_no = sql_int ("SELECT count(*) FROM results" " WHERE report = %llu" - " AND description LIKE 'Compliant:%%NO%%';", + " AND description ~ '^Compliant:[\\s]*NO[\\s]*';", report); } @@ -22136,7 +22136,7 @@ report_compliance_by_uuid (const char *report_id, *compliance_incomplete = sql_int ("SELECT count(*) FROM results" " WHERE report = %llu" - " AND description LIKE 'Compliant:%%INCOMPLETE%%';", + " AND description ~ '^Compliant:[\\s]*INCOMPLETE[\\s]*';", report); } if (compliance_undefined) @@ -22144,7 +22144,7 @@ report_compliance_by_uuid (const char *report_id, *compliance_undefined = sql_int ("SELECT count(*) FROM results" " WHERE report = %llu" - " AND description NOT LIKE 'Compliant:%%';", + " AND description !~ '^Compliant:[\\s]*';", report); }