From 03559c1115aaa8c38f81b19ac32b74a0765a71ae Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Thu, 21 Apr 2022 17:08:42 -0400 Subject: [PATCH 1/2] Bugfix: DB throws an error when pull out BT-list, if SOW-list is empty --- src/pd/utilities_timecard3.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pd/utilities_timecard3.cpp b/src/pd/utilities_timecard3.cpp index 87fb7a0..3aaa94f 100644 --- a/src/pd/utilities_timecard3.cpp +++ b/src/pd/utilities_timecard3.cpp @@ -743,12 +743,16 @@ static auto __GetBTList(const string &sow_where_statement, const string &sow_lim auto sow_ids = GetValuesFromDB(sow_statement, db); return - "\"sow\":[" + GetSOWInJSONFormat("SELECT * FROM `contracts_sow` WHERE `id` IN (" + join(sow_ids, ",") + ");", db, user, true, false, false, true) + "]," - "\"bt\":[" + GetBTsInJSONFormat( - "SELECT * FROM `bt` WHERE " - "`contract_sow_id` IN (" + join(sow_ids, ",") + ")" - + bt_where_statement + - ";", db, user, isExtended) + "]" + "\"sow\":[" + (sow_ids.size() ? GetSOWInJSONFormat("SELECT * FROM `contracts_sow` WHERE `id` IN (" + join(sow_ids, ",") + ");", db, user, true, false, false, true) + : "") + + "]," + "\"bt\":[" + (sow_ids.size() ? GetBTsInJSONFormat( + "SELECT * FROM `bt` WHERE " + "`contract_sow_id` IN (" + join(sow_ids, ",") + ")" + + bt_where_statement + + ";", db, user, isExtended) + : "") + + "]" ; } From 694b9867d809652655968026369659c43224fcba Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Thu, 21 Apr 2022 17:10:56 -0400 Subject: [PATCH 2/2] code clean-up --- src/pd/utilities_timecard3.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/pd/utilities_timecard3.cpp b/src/pd/utilities_timecard3.cpp index 3aaa94f..8c47285 100644 --- a/src/pd/utilities_timecard3.cpp +++ b/src/pd/utilities_timecard3.cpp @@ -743,10 +743,10 @@ static auto __GetBTList(const string &sow_where_statement, const string &sow_lim auto sow_ids = GetValuesFromDB(sow_statement, db); return - "\"sow\":[" + (sow_ids.size() ? GetSOWInJSONFormat("SELECT * FROM `contracts_sow` WHERE `id` IN (" + join(sow_ids, ",") + ");", db, user, true, false, false, true) + "\"sow\":[" + (sow_ids.size() ? GetSOWInJSONFormat("SELECT * FROM `contracts_sow` WHERE `id` IN (" + join(sow_ids, ",") + ");", db, user, true, false, false, true) : "") + "]," - "\"bt\":[" + (sow_ids.size() ? GetBTsInJSONFormat( + "\"bt\":[" + (sow_ids.size() ? GetBTsInJSONFormat( "SELECT * FROM `bt` WHERE " "`contract_sow_id` IN (" + join(sow_ids, ",") + ")" + bt_where_statement + @@ -797,15 +797,20 @@ static auto __GetTimecardList(const string &sow_where_statement, const string &s auto sow_ids = GetValuesFromDB(sow_statement, db); return - "\"sow\":[" + (sow_ids.size() ? GetSOWInJSONFormat("SELECT * FROM `contracts_sow` WHERE `id` IN (" + join(sow_ids, ",") + ");", db, user, false, false, false, true) : "") + "]," - "\"timecards\":[" + (sow_ids.size() ? - GetTimecardsInJSONFormat( - "SELECT * FROM `timecards` WHERE " - "`contract_sow_id` IN (" + join(sow_ids, ",") + ")" - + timecard_where_statement + - ";", db, user) - : "") + "]," - "\"holiday_calendar\":[" + (sow_ids.size() ? GetHolidayCalendarInJSONFormat("SELECT * FROM `holiday_calendar` WHERE `agency_company_id` IN (SELECT `agency_company_id` FROM `contracts_sow` WHERE " + sow_where_statement + ");", db, user) : "") + "]" + "\"sow\":[" + (sow_ids.size() ? GetSOWInJSONFormat("SELECT * FROM `contracts_sow` WHERE `id` IN (" + join(sow_ids, ",") + ");", db, user, false, false, false, true) + : "") + + "]," + "\"timecards\":[" + (sow_ids.size() ? + GetTimecardsInJSONFormat( + "SELECT * FROM `timecards` WHERE " + "`contract_sow_id` IN (" + join(sow_ids, ",") + ")" + + timecard_where_statement + + ";", db, user) + : "") + + "]," + "\"holiday_calendar\":[" + (sow_ids.size() ? GetHolidayCalendarInJSONFormat("SELECT * FROM `holiday_calendar` WHERE `agency_company_id` IN (SELECT `agency_company_id` FROM `contracts_sow` WHERE " + sow_where_statement + ");", db, user) + : "") + + "]" ; }