diff --git a/server/AyaNova/PickList/PickListSqlBuilder.cs b/server/AyaNova/PickList/PickListSqlBuilder.cs index 21f0c6b3..3a8b22c3 100644 --- a/server/AyaNova/PickList/PickListSqlBuilder.cs +++ b/server/AyaNova/PickList/PickListSqlBuilder.cs @@ -29,6 +29,9 @@ namespace AyaNova.PickList //it should return results based on the query where there is a single name (display) column and an id column for rowid //and the fields should be combined in a standard way separated by spaces "Widget widgetserial username" for compactness + //determine this in advance as it will be used in a loop later + bool HasAutoCompleteQuery = !string.IsNullOrWhiteSpace(autoCompleteQuery); + //lists to collect the clauses so to avoid comma fuckery List lSelect = new List(); List lWhere = new List(); @@ -46,7 +49,8 @@ namespace AyaNova.PickList { AyaPickListFieldDefinition activeColumn = pickList.ColumnDefinitions.FirstOrDefault(x => x.IsActiveColumn == true); //it's ok if there is no active column, it could happen so just roll with it - if(activeColumn!=null){ + if (activeColumn != null) + { lWhere.Add(activeColumn.SqlValueColumnName + " = true"); } } @@ -65,19 +69,25 @@ namespace AyaNova.PickList {//Ignore missing fields in production var valueColumnName = o.GetSqlValueColumnName(); - lSelect.Add(valueColumnName); - string sWhere = $"{valueColumnName} LIKE '%{autoCompleteQuery" - - - - + if (HasAutoCompleteQuery) + { + string sWhere = $"{valueColumnName} LIKE '%{autoCompleteQuery}%'"; + lWhere.Add(sWhere); + } } } +//Now build up the return query +//select +//from +//where +//orderby +//limit, actual sql: "LIMIT {MAXIMUM_RESULT_COUNT}" + return sbSelect.ToString() + pickList.SQLFrom + sbWhere.ToString(); }