This commit is contained in:
2020-03-13 20:29:19 +00:00
parent 559fb04bd5
commit 6c2370b053

View File

@@ -35,6 +35,7 @@ namespace AyaNova.PickList
//lists to collect the clauses so to avoid comma fuckery //lists to collect the clauses so to avoid comma fuckery
List<string> lSelect = new List<string>(); List<string> lSelect = new List<string>();
List<string> lWhere = new List<string>(); List<string> lWhere = new List<string>();
List<string> lOrderBy = new List<string>();
//Add rowid column as it's always required //Add rowid column as it's always required
@@ -51,6 +52,7 @@ namespace AyaNova.PickList
//it's ok if there is no active column, it could happen so just roll with it //it's ok if there is no active column, it could happen so just roll with it
if (activeColumn != null) if (activeColumn != null)
{ {
lSelect.Add(activeColumn.SqlValueColumnName);
lWhere.Add(activeColumn.SqlValueColumnName + " = true"); lWhere.Add(activeColumn.SqlValueColumnName + " = true");
} }
} }
@@ -70,25 +72,60 @@ namespace AyaNova.PickList
var valueColumnName = o.GetSqlValueColumnName(); var valueColumnName = o.GetSqlValueColumnName();
lSelect.Add(valueColumnName); lSelect.Add(valueColumnName);
lOrderBy.Add(valueColumnName);
if (HasAutoCompleteQuery) if (HasAutoCompleteQuery)
{ {
string sWhere = $"{valueColumnName} LIKE '%{autoCompleteQuery}%'"; string sWhere = $"({valueColumnName} LIKE '%{autoCompleteQuery}%')";
lWhere.Add(sWhere); lWhere.Add(sWhere);
} }
} }
} }
StringBuilder sb = new StringBuilder();
//Now build up the return query //SELECT
//select sb.Append("select ");
//from foreach (string s in lSelect)
//where {
//orderby sb.Append(s);
//limit, actual sql: "LIMIT {MAXIMUM_RESULT_COUNT}" sb.Append(",");
}
//clear trailing comma
sb.Length--;
return sbSelect.ToString() + pickList.SQLFrom + sbWhere.ToString(); //FROM
sb.Append(" ");
sb.Append(pickList.SQLFrom);
//WHERE
sb.Append(" ");
sb.Append("where ");
foreach (string s in lWhere)
{
sb.Append(s);
sb.Append(" or ");
}
//clear trailing or
sb.Length -= 4;
//ORDER BY
sb.Append("ORDER BY ");
foreach (string s in lOrderBy)
{
sb.Append(s);
sb.Append(",");
}
//clear trailing comma
sb.Length--;
//LIMIT
sb.Append(" ");
sb.Append($"LIMIT {MAXIMUM_RESULT_COUNT}");
return sb.ToString();
} }