This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Biz;
|
||||
|
||||
namespace AyaNova.PickList
|
||||
{
|
||||
@@ -28,12 +24,20 @@ namespace AyaNova.PickList
|
||||
//TODO: build a sql List<AyaPickListFieldDefinition> columnDefinitionsselect and order by and a where clause that searches appropriately in each field (tags)
|
||||
//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
|
||||
//WORKING QUERY
|
||||
//select awidget.id AS rowid,awidget.active,awidget.name,awidget.serial,auser.name from awidget left outer join auser on (awidget.userid=auser.id)
|
||||
//where awidget.active = true and ((awidget.name like '%some%') or (cast (awidget.serial as text) like '%some%') or (auser.name like '%some%') ) order by awidget.name,awidget.serial,auser.name limit 100
|
||||
|
||||
|
||||
//TODO: TAGS
|
||||
//TODO: Clean out unnneeded stuff in AyaPickListFieldDefinition (stuff from datalist copied over)
|
||||
|
||||
//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<string> lSelect = new List<string>();
|
||||
string ActiveWhereFragment = string.Empty;
|
||||
List<string> lWhere = new List<string>();
|
||||
List<string> lOrderBy = new List<string>();
|
||||
|
||||
@@ -53,7 +57,7 @@ namespace AyaNova.PickList
|
||||
if (activeColumn != null)
|
||||
{
|
||||
lSelect.Add(activeColumn.SqlValueColumnName);
|
||||
lWhere.Add(activeColumn.SqlValueColumnName + " = true");
|
||||
ActiveWhereFragment = activeColumn.SqlValueColumnName + " = true";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,12 +75,33 @@ namespace AyaNova.PickList
|
||||
{//Ignore missing fields in production
|
||||
|
||||
var valueColumnName = o.GetSqlValueColumnName();
|
||||
|
||||
lSelect.Add(valueColumnName);
|
||||
lOrderBy.Add(valueColumnName);
|
||||
|
||||
if (HasAutoCompleteQuery)
|
||||
{
|
||||
string sWhere = $"({valueColumnName} LIKE '%{autoCompleteQuery}%')";
|
||||
string sWhere = string.Empty;
|
||||
|
||||
//Tag?
|
||||
if (o.ColumnDataType == UiFieldDataType.Tags)
|
||||
{
|
||||
|
||||
}
|
||||
else if (o.ColumnDataType == UiFieldDataType.Text || o.ColumnDataType == UiFieldDataType.EmailAddress || o.ColumnDataType == UiFieldDataType.HTTP)
|
||||
{
|
||||
//regular text field
|
||||
sWhere = $"({valueColumnName} LIKE '%{autoCompleteQuery}%')";
|
||||
}
|
||||
else
|
||||
{
|
||||
//needs to be cast to text
|
||||
//(cast (awidget.serial as text) like '%some%')
|
||||
sWhere = $"(cast ({valueColumnName} as text) LIKE '%{autoCompleteQuery}%')";
|
||||
}
|
||||
|
||||
|
||||
|
||||
lWhere.Add(sWhere);
|
||||
}
|
||||
|
||||
@@ -100,9 +125,14 @@ namespace AyaNova.PickList
|
||||
sb.Append(pickList.SQLFrom);
|
||||
|
||||
|
||||
//WHERE
|
||||
sb.Append(" ");
|
||||
sb.Append("where ");
|
||||
//WHERE
|
||||
sb.Append(" where ");
|
||||
if (!IncludeInactive)
|
||||
{
|
||||
sb.Append(ActiveWhereFragment);
|
||||
sb.Append(" and (");
|
||||
}
|
||||
|
||||
foreach (string s in lWhere)
|
||||
{
|
||||
sb.Append(s);
|
||||
@@ -110,9 +140,14 @@ namespace AyaNova.PickList
|
||||
}
|
||||
//clear trailing or
|
||||
sb.Length -= 4;
|
||||
//enclosing parenthesis
|
||||
if (!IncludeInactive)
|
||||
{
|
||||
sb.Append(")");
|
||||
}
|
||||
|
||||
//ORDER BY
|
||||
sb.Append("ORDER BY ");
|
||||
sb.Append(" order by ");
|
||||
foreach (string s in lOrderBy)
|
||||
{
|
||||
sb.Append(s);
|
||||
@@ -121,9 +156,8 @@ namespace AyaNova.PickList
|
||||
//clear trailing comma
|
||||
sb.Length--;
|
||||
|
||||
//LIMIT
|
||||
sb.Append(" ");
|
||||
sb.Append($"LIMIT {MAXIMUM_RESULT_COUNT}");
|
||||
//LIMIT
|
||||
sb.Append($" limit {MAXIMUM_RESULT_COUNT}");
|
||||
|
||||
return sb.ToString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user