From 5da01d776aacd0cfa9c221396f6f584c66550eb6 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 3 Dec 2020 18:18:58 +0000 Subject: [PATCH] --- server/AyaNova/PickList/PickListSqlBuilder.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/server/AyaNova/PickList/PickListSqlBuilder.cs b/server/AyaNova/PickList/PickListSqlBuilder.cs index 93f11223..c34a715b 100644 --- a/server/AyaNova/PickList/PickListSqlBuilder.cs +++ b/server/AyaNova/PickList/PickListSqlBuilder.cs @@ -21,7 +21,7 @@ namespace AyaNova.PickList //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. - //for example, if you're selecting a + const int MAXIMUM_RESULT_COUNT = 100; //Build the query for a picklist request @@ -52,6 +52,8 @@ namespace AyaNova.PickList throw new System.ArgumentNullException($"DEV ERROR in PickListSqlBuilder.cs: picklist for {pickList.DefaultListObjectType.ToString()} has no rowId column specified in columnDefinitions list"); PlIdSelectFragment = rowIdColumn.SqlIdColumnName + " as plId"; + + if (preId != 0) { PredefinedOnlyWhereFragment = rowIdColumn.SqlIdColumnName + " = " + preId.ToString(); @@ -67,6 +69,7 @@ namespace AyaNova.PickList AyaPickListFieldDefinition activeColumn = pickList.ColumnDefinitions.FirstOrDefault(z => z.IsActiveColumn == true); if (activeColumn == null) { + //no active column which is normal for some types of objects //so make a fake one and return them all as active=true as all lists must return the same format ActiveSelectFragment = "true as plActive"; @@ -83,7 +86,16 @@ namespace AyaNova.PickList //if there is an override to see inactive too then we just don't set the filter on active if (!IncludeInactive) { - ActiveWhereFragment = activeColumn.SqlValueColumnName + " = true"; + if (preId != 0) + { + //pre-selected need to always appear regardless of active status + ActiveWhereFragment = $"({rowIdColumn.SqlIdColumnName} = {preId}) or ({activeColumn.SqlValueColumnName} = true)"; + } + else + { + ActiveWhereFragment = activeColumn.SqlValueColumnName + " = true"; + } + } } @@ -169,10 +181,10 @@ namespace AyaNova.PickList //Where fragment is different for non text fields: it needs to be cast to text to like query on it //(cast (awidget.serial as text) like '%some%') if (HasAutoCompleteQuery) - if (ServerGlobalBizSettings.SearchCaseSensitiveOnly) - sWhere = $"(cast ({valueColumnName} as text) like '%{autoCompleteQuery}%')"; + if (ServerGlobalBizSettings.SearchCaseSensitiveOnly) + sWhere = $"(cast ({valueColumnName} as text) like '%{autoCompleteQuery}%')"; else - sWhere = $"(lower(cast ({valueColumnName} as text)) like lower('%{autoCompleteQuery}%'))"; + sWhere = $"(lower(cast ({valueColumnName} as text)) like lower('%{autoCompleteQuery}%'))"; }