diff --git a/server/AyaNova/PickList/PickListSqlBuilder.cs b/server/AyaNova/PickList/PickListSqlBuilder.cs index 8d4d97cc..f947da32 100644 --- a/server/AyaNova/PickList/PickListSqlBuilder.cs +++ b/server/AyaNova/PickList/PickListSqlBuilder.cs @@ -8,6 +8,15 @@ namespace AyaNova.PickList internal static class PickListSqlBuilder { + /*Example + select awidget.id as plId, awidget.active as plActive, awidget.name || ' ' || awidget.serial || ' ' || auser.name as plname, awidget.tags + from awidget left outer join auser on (awidget.userid=auser.id) + where array_to_string(awidget.tags,',') like '%zone-8%' + and awidget.active = true + and ((awidget.name like '%we%') or (cast (awidget.serial as text) like '%we%') or (auser.name like '%we%')) + order by awidget.name,awidget.serial,auser.name limit 100 + */ + //Maximum number of results to return at any given time //did a little research and may adjust this but it can be fairly girthy in this day and age //and many people might not want or need to autocomplete type if we provide enough leeway. @@ -188,32 +197,39 @@ namespace AyaNova.PickList if (HasTagSpecificQuery) { sb.Append(TagSpecificWhereFragment); - sb.Append(" and ("); + sb.Append(" and "); } if (!IncludeInactive) { sb.Append(ActiveWhereFragment); - sb.Append(" and ("); + sb.Append(" and "); } - foreach (string s in lWhere) + if (lWhere.Count > 0) { - sb.Append(s); - sb.Append(" or "); - } - //clear trailing or - sb.Length -= 4; - //enclosing parenthesis + //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 + - if (HasTagSpecificQuery) - { - sb.Append(")"); - } - - if (!IncludeInactive) - { 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; + } } //ORDER BY