From ed0f8b0d54e0f1d18076fa997bf23b4a689ba7ea Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 14 May 2021 10:22:15 +0200 Subject: [PATCH 1/5] Rename the date column of reports to creation_time Changed all relevant entries in manage_sql.c from date to creation_time. Changed the relevant entries for the creation of the database in manage_pg.c accordingly. Added a function for the necessary database changes in manage_migrators.c. Set the Databaseversion to 245. --- CMakeLists.txt | 2 +- src/manage_migrators.c | 68 ++++++++++++++++++++++++++++++++++++++++++ src/manage_pg.c | 50 ++++++++++++++++++------------- src/manage_sql.c | 56 +++++++++++++++++----------------- 4 files changed, 127 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3530a951b..d43d5c394 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ include (CPack) ## Variables -set (GVMD_DATABASE_VERSION 244) +set (GVMD_DATABASE_VERSION 245) set (GVMD_SCAP_DATABASE_VERSION 18) diff --git a/src/manage_migrators.c b/src/manage_migrators.c index b984b9895..580cc574f 100644 --- a/src/manage_migrators.c +++ b/src/manage_migrators.c @@ -2714,6 +2714,73 @@ migrate_243_to_244 () return 0; } +/** + * @brief Migrate the database from version 244 to version 245. + * + * @return 0 success, -1 error. + */ +int +migrate_244_to_245 () +{ + sql_begin_immediate (); + + /* Ensure that the database is currently version 244. */ + + if (manage_db_version () != 244) + { + sql_rollback (); + return -1; + } + + /* Update the database. */ + + sql ("ALTER TABLE reports RENAME COLUMN date TO creation_time;"); + + + sql ("CREATE OR REPLACE FUNCTION task_last_report (integer)" + " RETURNS integer AS $$" + /* Get the report from the most recently completed invocation of task. */ + " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" + " ORDER BY creation_time DESC LIMIT 1;" + "$$ LANGUAGE SQL;", + TASK_STATUS_DONE); + + sql ("CREATE OR REPLACE FUNCTION task_second_last_report (integer)" + " RETURNS integer AS $$" + /* Get report from second most recently completed invocation of task. */ + " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" + " ORDER BY creation_time DESC LIMIT 1 OFFSET 1;" + "$$ LANGUAGE SQL;", + TASK_STATUS_DONE); + + sql ("CREATE OR REPLACE FUNCTION task_severity (integer," // task + " integer," // overrides + " integer)" // min_qod + " RETURNS double precision AS $$" + /* Calculate the severity of a task. */ + " SELECT CASE" + " WHEN (SELECT target = 0" + " FROM tasks WHERE id = $1)" + " THEN CAST (NULL AS double precision)" + " ELSE" + " (SELECT report_severity ((SELECT id FROM reports" + " WHERE task = $1" + " AND scan_run_status = %u" + " ORDER BY creation_time DESC" + " LIMIT 1 OFFSET 0), $2, $3))" + " END;" + "$$ LANGUAGE SQL;", + TASK_STATUS_DONE); + + /* Set the database version to 245. */ + + set_db_version (245); + + sql_commit (); + + return 0; +} + #undef UPDATE_DASHBOARD_SETTINGS @@ -2765,6 +2832,7 @@ static migrator_t database_migrators[] = { {242, migrate_241_to_242}, {243, migrate_242_to_243}, {244, migrate_243_to_244}, + {245, migrate_244_to_245}, /* End marker. */ {-1, NULL}}; diff --git a/src/manage_pg.c b/src/manage_pg.c index 7ce29eadd..fd1934b31 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -1114,24 +1114,32 @@ manage_create_sql_functions () " END;" "$$ LANGUAGE SQL;"); - sql ("CREATE OR REPLACE FUNCTION task_last_report (integer)" - " RETURNS integer AS $$" - /* Get the report from the most recently completed invocation of task. */ - " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" - " ORDER BY date DESC LIMIT 1;" - "$$ LANGUAGE SQL;", - TASK_STATUS_DONE); - - sql ("CREATE OR REPLACE FUNCTION task_second_last_report (integer)" - " RETURNS integer AS $$" - /* Get report from second most recently completed invocation of task. */ - " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" - " ORDER BY date DESC LIMIT 1 OFFSET 1;" - "$$ LANGUAGE SQL;", - TASK_STATUS_DONE); + /* column date in table reports was renamed to creation_time in version 245 */ + if (current_db_version >= 245) { + sql ("CREATE OR REPLACE FUNCTION task_last_report (integer)" + " RETURNS integer AS $$" + /* Get the report from the most recently completed invocation of task. */ + " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" + " ORDER BY creation_time DESC LIMIT 1;" + "$$ LANGUAGE SQL;", + TASK_STATUS_DONE); + } + + /* column date in table reports was renamed to creation_time in version 245 */ + if (current_db_version >= 245) { + sql ("CREATE OR REPLACE FUNCTION task_second_last_report (integer)" + " RETURNS integer AS $$" + /* Get report from second most recently completed invocation of task. */ + " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" + " ORDER BY creation_time DESC LIMIT 1 OFFSET 1;" + "$$ LANGUAGE SQL;", + TASK_STATUS_DONE); + } - /* result_nvt column (in OVERRIDES_SQL) was added in version 189. */ - if (current_db_version >= 189) + /* result_nvt column (in OVERRIDES_SQL) was added in version 189. */ + /* if (current_db_version >= 189) */ + /* column date in table reports was renamed to creation_time in version 245 */ + if (current_db_version >= 245) { sql ("CREATE OR REPLACE FUNCTION task_severity (integer," // task " integer," // overrides " integer)" // min_qod @@ -1145,11 +1153,12 @@ manage_create_sql_functions () " (SELECT report_severity ((SELECT id FROM reports" " WHERE task = $1" " AND scan_run_status = %u" - " ORDER BY date DESC" + " ORDER BY creation_time DESC" " LIMIT 1 OFFSET 0), $2, $3))" " END;" "$$ LANGUAGE SQL;", TASK_STATUS_DONE); + } sql ("CREATE OR REPLACE FUNCTION task_trend (integer, integer, integer)" " RETURNS text AS $$" @@ -2302,13 +2311,14 @@ create_tables () " uuid text UNIQUE NOT NULL," " owner integer REFERENCES users (id) ON DELETE RESTRICT," " task integer REFERENCES tasks (id) ON DELETE RESTRICT," - " date integer," + " creation_time integer," " start_time integer," " end_time integer," " comment text," " scan_run_status integer," " slave_progress integer," - " flags integer);"); + " flags integer," + " modification_time integer);"); sql ("CREATE TABLE IF NOT EXISTS report_counts" " (id SERIAL PRIMARY KEY," diff --git a/src/manage_sql.c b/src/manage_sql.c index b1cba6752..430c6e39f 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -2931,7 +2931,7 @@ filter_clause (const char* type, const char* filter, " FROM (SELECT report_progress (id) AS temp" " FROM reports" " WHERE task = tasks.id" - " ORDER BY date DESC LIMIT 1)" + " ORDER BY creation_time DESC LIMIT 1)" " AS temp_sub)" " END)" " ASC"); @@ -3123,7 +3123,7 @@ filter_clause (const char* type, const char* filter, " FROM (SELECT report_progress (id) AS temp" " FROM reports" " WHERE task = tasks.id" - " ORDER BY date DESC LIMIT 1)" + " ORDER BY creation_time DESC LIMIT 1)" " AS temp_sub)" " END)" " DESC"); @@ -12022,7 +12022,7 @@ generate_report_filename (report_t report, report_format_t report_format, report_id = report_uuid (report); creation_time - = sql_string ("SELECT iso_time (date)" + = sql_string ("SELECT iso_time (creation_time)" " FROM reports" " WHERE id = %llu", report); @@ -14545,7 +14545,7 @@ append_to_task_string (task_t task, const char* field, const char* value) "(SELECT uuid FROM reports WHERE task = tasks.id" \ /* TODO 1 == TASK_STATUS_DONE */ \ " AND scan_run_status = 1" \ - " ORDER BY date ASC LIMIT 1)", \ + " ORDER BY creation_time ASC LIMIT 1)", \ "first_report", \ KEYWORD_TYPE_STRING \ }, \ @@ -14554,7 +14554,7 @@ append_to_task_string (task_t task, const char* field, const char* value) "(SELECT uuid FROM reports WHERE task = tasks.id" \ /* TODO 1 == TASK_STATUS_DONE */ \ " AND scan_run_status = 1" \ - " ORDER BY date DESC LIMIT 1)", \ + " ORDER BY creation_time DESC LIMIT 1)", \ "last_report", \ KEYWORD_TYPE_STRING \ }, \ @@ -14607,18 +14607,18 @@ append_to_task_string (task_t task, const char* field, const char* value) KEYWORD_TYPE_INTEGER \ }, \ { \ - "(SELECT date FROM reports WHERE task = tasks.id" \ + "(SELECT creation_time FROM reports WHERE task = tasks.id" \ /* TODO 1 == TASK_STATUS_DONE */ \ " AND scan_run_status = 1" \ - " ORDER BY date ASC LIMIT 1)", \ + " ORDER BY creation_time ASC LIMIT 1)", \ "first", \ KEYWORD_TYPE_INTEGER \ }, \ { \ - "(SELECT date FROM reports WHERE task = tasks.id" \ + "(SELECT creation_time FROM reports WHERE task = tasks.id" \ /* TODO 1 == TASK_STATUS_DONE */ \ " AND scan_run_status = 1" \ - " ORDER BY date DESC LIMIT 1)", \ + " ORDER BY creation_time DESC LIMIT 1)", \ "last", \ KEYWORD_TYPE_INTEGER \ }, \ @@ -17810,9 +17810,9 @@ task_report_previous (task_t task, report_t report, report_t *previous) "SELECT id FROM reports" " WHERE task = %llu" " AND scan_run_status = %u" - " AND date < (SELECT date FROM reports" + " AND creation_time < (SELECT creation_time FROM reports" " WHERE id = %llu)" - " ORDER BY date DESC LIMIT 1;", + " ORDER BY creation_time DESC LIMIT 1;", task, TASK_STATUS_DONE, report)) @@ -17846,7 +17846,7 @@ task_last_report (task_t task, report_t *report) switch (sql_int64 (report, "SELECT id FROM reports WHERE task = %llu" " AND scan_run_status = %u" - " ORDER BY date DESC LIMIT 1;", + " ORDER BY creation_time DESC LIMIT 1;", task, TASK_STATUS_DONE)) { @@ -17878,7 +17878,7 @@ task_last_report_any_status (task_t task, report_t *report) { switch (sql_int64 (report, "SELECT id FROM reports WHERE task = %llu" - " ORDER BY date DESC LIMIT 1;", + " ORDER BY creation_time DESC LIMIT 1;", task)) { case 0: @@ -17910,7 +17910,7 @@ task_second_last_report (task_t task, report_t *report) switch (sql_int64 (report, "SELECT id FROM reports WHERE task = %llu" " AND scan_run_status = %u" - " ORDER BY date DESC LIMIT 1 OFFSET 1;", + " ORDER BY creation_time DESC LIMIT 1 OFFSET 1;", task, TASK_STATUS_DONE)) { @@ -17944,7 +17944,7 @@ task_last_resumable_report (task_t task, report_t *report) "SELECT id FROM reports WHERE task = %llu" " AND (scan_run_status = %u" " OR scan_run_status = %u)" - " ORDER BY date DESC LIMIT 1;", + " ORDER BY creation_time DESC LIMIT 1;", task, TASK_STATUS_STOPPED, TASK_STATUS_INTERRUPTED)) @@ -17976,7 +17976,7 @@ task_second_last_report_id (task_t task) { return sql_string ("SELECT uuid FROM reports WHERE task = %llu" " AND scan_run_status = %u" - " ORDER BY date DESC LIMIT 1 OFFSET 1;", + " ORDER BY creation_time DESC LIMIT 1 OFFSET 1;", task, TASK_STATUS_DONE); } @@ -18442,7 +18442,7 @@ task_severity_double (task_t task, int overrides, int min_qod, int offset) "SELECT id FROM reports" " WHERE reports.task = %llu" " AND reports.scan_run_status = %u" - " ORDER BY reports.date DESC" + " ORDER BY reports.creation_time DESC" " LIMIT 1 OFFSET %d", task, TASK_STATUS_DONE, offset); @@ -20108,7 +20108,7 @@ report_clear_count_cache (report_t report, report_t make_report (task_t task, const char* uuid, task_status_t status) { - sql ("INSERT into reports (uuid, owner, task, date, comment," + sql ("INSERT into reports (uuid, owner, task, creation_time, comment," " scan_run_status, slave_progress)" " VALUES ('%s'," " (SELECT owner FROM tasks WHERE tasks.id = %llu)," @@ -20924,11 +20924,11 @@ report_add_result (report_t report, result_t result) * @brief Filter columns for report iterator. */ #define REPORT_ITERATOR_FILTER_COLUMNS \ - { ANON_GET_ITERATOR_FILTER_COLUMNS, "task_id", "name", "date", "status", \ - "task", "severity", "false_positive", "log", "low", "medium", "high", \ - "hosts", "result_hosts", "fp_per_host", "log_per_host", "low_per_host", \ - "medium_per_host", "high_per_host", "duration", "duration_per_host", \ - "start_time", "end_time", "scan_start", "scan_end", \ + { ANON_GET_ITERATOR_FILTER_COLUMNS, "task_id", "name", "creation_time", \ + "status", "task", "severity", "false_positive", "log", "low", "medium", \ + "high", "hosts", "result_hosts", "fp_per_host", "log_per_host", \ + "low_per_host", "medium_per_host", "high_per_host", "duration", \ + "duration_per_host", "start_time", "end_time", "scan_start", "scan_end", \ NULL } /** @@ -20938,11 +20938,11 @@ report_add_result (report_t report, result_t result) { \ { "id", NULL, KEYWORD_TYPE_INTEGER }, \ { "uuid", NULL, KEYWORD_TYPE_STRING }, \ - { "iso_time (date)", "name", KEYWORD_TYPE_STRING }, \ + { "iso_time (creation_time)", "name", KEYWORD_TYPE_STRING }, \ { "''", NULL, KEYWORD_TYPE_STRING }, \ - { "iso_time (date)", NULL, KEYWORD_TYPE_STRING }, \ + { "iso_time (creation_time)", NULL, KEYWORD_TYPE_STRING }, \ { "iso_time (modification_time)", NULL, KEYWORD_TYPE_STRING }, \ - { "date", "created", KEYWORD_TYPE_INTEGER }, \ + { "creation_time", "created", KEYWORD_TYPE_INTEGER }, \ { "modification_time", "modified", KEYWORD_TYPE_INTEGER }, \ { "(SELECT name FROM users WHERE users.id = reports.owner)", \ "_owner", \ @@ -20964,7 +20964,7 @@ report_add_result (report_t report, result_t result) "task_id", \ KEYWORD_TYPE_STRING \ }, \ - { "date", NULL, KEYWORD_TYPE_INTEGER }, \ + { "creation_time", NULL, KEYWORD_TYPE_INTEGER }, \ { "(SELECT name FROM tasks WHERE tasks.id = task)", "task" }, \ { \ "report_severity (id, opts.override, opts.min_qod)", \ @@ -23626,7 +23626,7 @@ int report_timestamp (const char* report_id, gchar** timestamp) { const char* stamp; - time_t time = sql_int ("SELECT date FROM reports where uuid = '%s';", + time_t time = sql_int ("SELECT creation_time FROM reports where uuid = '%s';", report_id); stamp = iso_time (&time); if (stamp == NULL) return -1; From 4a1e4f0643ebc60f49f31787e4d56f3dd43200dc Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 14 May 2021 10:54:24 +0200 Subject: [PATCH 2/5] Added entry for the rename of the date column to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 252b0ce73..26c4ed807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Update default log config [#1501](https://github.com/greenbone/gvmd/pull/1501) - Change report timestamp filter and iterator columns [#1512](https://github.com/greenbone/gvmd/pull/1512) +- Rename the date column of reports to creation_time [#1520](https://github.com/greenbone/gvmd/pull/1520) ### Fixed - Improve VT version handling for CVE & OVAL results [#1496](https://github.com/greenbone/gvmd/pull/1496) From 4d3ff58a0fd11ec45076a698e6de7fd127b0e5d6 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Tue, 18 May 2021 11:09:05 +0200 Subject: [PATCH 3/5] Improvements for the "Rename the date column of reports to creation_time AP-1343" issue. Removed 3 "CREATE OR REPLACE FUNCTION"-statements from manage_migrators.c, because they are redundant. Added "date" as an alias for "creation_time" to the corresponding line of the REPORT_ITERATOR_WHERE_COLUMNS columns and added it to the REPORT_ITERATOR_FILTER_COLUMNS columns. Did a few code format changes. --- src/manage_migrators.c | 36 ------------------------------------ src/manage_pg.c | 15 +++++++++------ src/manage_sql.c | 8 ++++---- 3 files changed, 13 insertions(+), 46 deletions(-) diff --git a/src/manage_migrators.c b/src/manage_migrators.c index 580cc574f..e77553dea 100644 --- a/src/manage_migrators.c +++ b/src/manage_migrators.c @@ -2736,42 +2736,6 @@ migrate_244_to_245 () sql ("ALTER TABLE reports RENAME COLUMN date TO creation_time;"); - - sql ("CREATE OR REPLACE FUNCTION task_last_report (integer)" - " RETURNS integer AS $$" - /* Get the report from the most recently completed invocation of task. */ - " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" - " ORDER BY creation_time DESC LIMIT 1;" - "$$ LANGUAGE SQL;", - TASK_STATUS_DONE); - - sql ("CREATE OR REPLACE FUNCTION task_second_last_report (integer)" - " RETURNS integer AS $$" - /* Get report from second most recently completed invocation of task. */ - " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" - " ORDER BY creation_time DESC LIMIT 1 OFFSET 1;" - "$$ LANGUAGE SQL;", - TASK_STATUS_DONE); - - sql ("CREATE OR REPLACE FUNCTION task_severity (integer," // task - " integer," // overrides - " integer)" // min_qod - " RETURNS double precision AS $$" - /* Calculate the severity of a task. */ - " SELECT CASE" - " WHEN (SELECT target = 0" - " FROM tasks WHERE id = $1)" - " THEN CAST (NULL AS double precision)" - " ELSE" - " (SELECT report_severity ((SELECT id FROM reports" - " WHERE task = $1" - " AND scan_run_status = %u" - " ORDER BY creation_time DESC" - " LIMIT 1 OFFSET 0), $2, $3))" - " END;" - "$$ LANGUAGE SQL;", - TASK_STATUS_DONE); - /* Set the database version to 245. */ set_db_version (245); diff --git a/src/manage_pg.c b/src/manage_pg.c index fd1934b31..07e56d643 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -1115,7 +1115,8 @@ manage_create_sql_functions () "$$ LANGUAGE SQL;"); /* column date in table reports was renamed to creation_time in version 245 */ - if (current_db_version >= 245) { + if (current_db_version >= 245) + { sql ("CREATE OR REPLACE FUNCTION task_last_report (integer)" " RETURNS integer AS $$" /* Get the report from the most recently completed invocation of task. */ @@ -1123,10 +1124,11 @@ manage_create_sql_functions () " ORDER BY creation_time DESC LIMIT 1;" "$$ LANGUAGE SQL;", TASK_STATUS_DONE); - } + } /* column date in table reports was renamed to creation_time in version 245 */ - if (current_db_version >= 245) { + if (current_db_version >= 245) + { sql ("CREATE OR REPLACE FUNCTION task_second_last_report (integer)" " RETURNS integer AS $$" /* Get report from second most recently completed invocation of task. */ @@ -1134,12 +1136,13 @@ manage_create_sql_functions () " ORDER BY creation_time DESC LIMIT 1 OFFSET 1;" "$$ LANGUAGE SQL;", TASK_STATUS_DONE); - } + } /* result_nvt column (in OVERRIDES_SQL) was added in version 189. */ /* if (current_db_version >= 189) */ /* column date in table reports was renamed to creation_time in version 245 */ - if (current_db_version >= 245) { + if (current_db_version >= 245) + { sql ("CREATE OR REPLACE FUNCTION task_severity (integer," // task " integer," // overrides " integer)" // min_qod @@ -1158,7 +1161,7 @@ manage_create_sql_functions () " END;" "$$ LANGUAGE SQL;", TASK_STATUS_DONE); - } + } sql ("CREATE OR REPLACE FUNCTION task_trend (integer, integer, integer)" " RETURNS text AS $$" diff --git a/src/manage_sql.c b/src/manage_sql.c index 430c6e39f..a68687445 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -17811,7 +17811,7 @@ task_report_previous (task_t task, report_t report, report_t *previous) " WHERE task = %llu" " AND scan_run_status = %u" " AND creation_time < (SELECT creation_time FROM reports" - " WHERE id = %llu)" + " WHERE id = %llu)" " ORDER BY creation_time DESC LIMIT 1;", task, TASK_STATUS_DONE, @@ -20925,8 +20925,8 @@ report_add_result (report_t report, result_t result) */ #define REPORT_ITERATOR_FILTER_COLUMNS \ { ANON_GET_ITERATOR_FILTER_COLUMNS, "task_id", "name", "creation_time", \ - "status", "task", "severity", "false_positive", "log", "low", "medium", \ - "high", "hosts", "result_hosts", "fp_per_host", "log_per_host", \ + "date", "status", "task", "severity", "false_positive", "log", "low", \ + "medium", "high", "hosts", "result_hosts", "fp_per_host", "log_per_host", \ "low_per_host", "medium_per_host", "high_per_host", "duration", \ "duration_per_host", "start_time", "end_time", "scan_start", "scan_end", \ NULL } @@ -20964,7 +20964,7 @@ report_add_result (report_t report, result_t result) "task_id", \ KEYWORD_TYPE_STRING \ }, \ - { "creation_time", NULL, KEYWORD_TYPE_INTEGER }, \ + { "creation_time", "date", KEYWORD_TYPE_INTEGER }, \ { "(SELECT name FROM tasks WHERE tasks.id = task)", "task" }, \ { \ "report_severity (id, opts.override, opts.min_qod)", \ From d4a5e5b2c9354d5b6f437e71afb77447dd81c05b Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Tue, 18 May 2021 14:06:27 +0200 Subject: [PATCH 4/5] Corrected wrong indentation in source code. --- src/manage_sql.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index a68687445..ec8350f69 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -17811,7 +17811,7 @@ task_report_previous (task_t task, report_t report, report_t *previous) " WHERE task = %llu" " AND scan_run_status = %u" " AND creation_time < (SELECT creation_time FROM reports" - " WHERE id = %llu)" + " WHERE id = %llu)" " ORDER BY creation_time DESC LIMIT 1;", task, TASK_STATUS_DONE, From a1baeaeb42c1139a153a6bfe95592f309da416bb Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Tue, 18 May 2021 14:18:52 +0200 Subject: [PATCH 5/5] Corrected wrong formatting in source code. --- src/manage_pg.c | 64 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/manage_pg.c b/src/manage_pg.c index 07e56d643..667142912 100644 --- a/src/manage_pg.c +++ b/src/manage_pg.c @@ -1117,25 +1117,25 @@ manage_create_sql_functions () /* column date in table reports was renamed to creation_time in version 245 */ if (current_db_version >= 245) { - sql ("CREATE OR REPLACE FUNCTION task_last_report (integer)" - " RETURNS integer AS $$" - /* Get the report from the most recently completed invocation of task. */ - " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" - " ORDER BY creation_time DESC LIMIT 1;" - "$$ LANGUAGE SQL;", - TASK_STATUS_DONE); + sql ("CREATE OR REPLACE FUNCTION task_last_report (integer)" + " RETURNS integer AS $$" + /* Get the report from the most recently completed invocation of task. */ + " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" + " ORDER BY creation_time DESC LIMIT 1;" + "$$ LANGUAGE SQL;", + TASK_STATUS_DONE); } /* column date in table reports was renamed to creation_time in version 245 */ if (current_db_version >= 245) { - sql ("CREATE OR REPLACE FUNCTION task_second_last_report (integer)" - " RETURNS integer AS $$" - /* Get report from second most recently completed invocation of task. */ - " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" - " ORDER BY creation_time DESC LIMIT 1 OFFSET 1;" - "$$ LANGUAGE SQL;", - TASK_STATUS_DONE); + sql ("CREATE OR REPLACE FUNCTION task_second_last_report (integer)" + " RETURNS integer AS $$" + /* Get report from second most recently completed invocation of task. */ + " SELECT id FROM reports WHERE task = $1 AND scan_run_status = %u" + " ORDER BY creation_time DESC LIMIT 1 OFFSET 1;" + "$$ LANGUAGE SQL;", + TASK_STATUS_DONE); } /* result_nvt column (in OVERRIDES_SQL) was added in version 189. */ @@ -1143,24 +1143,24 @@ manage_create_sql_functions () /* column date in table reports was renamed to creation_time in version 245 */ if (current_db_version >= 245) { - sql ("CREATE OR REPLACE FUNCTION task_severity (integer," // task - " integer," // overrides - " integer)" // min_qod - " RETURNS double precision AS $$" - /* Calculate the severity of a task. */ - " SELECT CASE" - " WHEN (SELECT target = 0" - " FROM tasks WHERE id = $1)" - " THEN CAST (NULL AS double precision)" - " ELSE" - " (SELECT report_severity ((SELECT id FROM reports" - " WHERE task = $1" - " AND scan_run_status = %u" - " ORDER BY creation_time DESC" - " LIMIT 1 OFFSET 0), $2, $3))" - " END;" - "$$ LANGUAGE SQL;", - TASK_STATUS_DONE); + sql ("CREATE OR REPLACE FUNCTION task_severity (integer," // task + " integer," // overrides + " integer)" // min_qod + " RETURNS double precision AS $$" + /* Calculate the severity of a task. */ + " SELECT CASE" + " WHEN (SELECT target = 0" + " FROM tasks WHERE id = $1)" + " THEN CAST (NULL AS double precision)" + " ELSE" + " (SELECT report_severity ((SELECT id FROM reports" + " WHERE task = $1" + " AND scan_run_status = %u" + " ORDER BY creation_time DESC" + " LIMIT 1 OFFSET 0), $2, $3))" + " END;" + "$$ LANGUAGE SQL;", + TASK_STATUS_DONE); } sql ("CREATE OR REPLACE FUNCTION task_trend (integer, integer, integer)"