From ea235a9a0c4d46450575bc997c6bc33c9dfac0ab Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 18 Mar 2020 18:07:16 +0000 Subject: [PATCH] --- server/AyaNova/PickList/PickListSqlBuilder.cs | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/server/AyaNova/PickList/PickListSqlBuilder.cs b/server/AyaNova/PickList/PickListSqlBuilder.cs index 7aa9fb1f..677eafa0 100644 --- a/server/AyaNova/PickList/PickListSqlBuilder.cs +++ b/server/AyaNova/PickList/PickListSqlBuilder.cs @@ -196,47 +196,51 @@ namespace AyaNova.PickList sb.Append(pickList.SQLFrom); - //WHERE - sb.Append(" where "); - - if (HasTagSpecificQuery) + //WHERE + //there is a condition where there is no where (inactive=true and no query of any kind) + if (lWhere.Count > 0 || HasTagSpecificQuery || IncludeInactive) { - sb.Append(TagSpecificWhereFragment); - sb.Append(" and "); - } + sb.Append(" where "); - if (!IncludeInactive) - { - sb.Append(ActiveWhereFragment); - sb.Append(" and "); - } - - if (lWhere.Count > 0) - { - //Put all the regular query terms in parenthesis to ensure it's all treated as one criteria - - sb.Append("("); - foreach (string s in lWhere) + if (HasTagSpecificQuery) { - sb.Append(s); - sb.Append(" or "); + sb.Append(TagSpecificWhereFragment); + sb.Append(" and "); } - //clear trailing or - sb.Length -= 4; - //enclosing parenthesis - - - sb.Append(")"); - } - else - { - //we might have a trailing and to remove - //jesus this stuff sucks, there must be a better way, it seems so fragile - if (!IncludeInactive || HasTagSpecificQuery) + if (!IncludeInactive) { - //trailing " and " to remove - sb.Length -= 5; + sb.Append(ActiveWhereFragment); + sb.Append(" and "); + } + + if (lWhere.Count > 0) + { + //Put all the regular query terms in parenthesis to ensure it's all treated as one criteria + + sb.Append("("); + foreach (string s in lWhere) + { + sb.Append(s); + sb.Append(" or "); + } + //clear trailing or + + sb.Length -= 4; + //enclosing parenthesis + + + sb.Append(")"); + } + else + { + //we might have a trailing and to remove + //jesus this stuff sucks, there must be a better way, it seems so fragile + if (!IncludeInactive || HasTagSpecificQuery) + { + //trailing " and " to remove + sb.Length -= 5; + } } }