This commit is contained in:
@@ -15,7 +15,7 @@ namespace AyaNova.PickList
|
|||||||
{
|
{
|
||||||
internal static class PickListFetcher
|
internal static class PickListFetcher
|
||||||
{
|
{
|
||||||
internal static async Task<List<NameIdActiveItem>> GetResponseAsync(AyaType ayaType, string query, AyContext ct, AuthorizationRoles userRoles)
|
internal static async Task<List<NameIdActiveItem>> GetResponseAsync(AyaType ayaType, string autoCompleteQuery, AyContext ct, AuthorizationRoles userRoles)
|
||||||
{
|
{
|
||||||
|
|
||||||
var PickList = PickListFactory.GetAyaPickList(ayaType);
|
var PickList = PickListFactory.GetAyaPickList(ayaType);
|
||||||
@@ -53,12 +53,12 @@ namespace AyaNova.PickList
|
|||||||
|
|
||||||
//BUILD THE QUERY
|
//BUILD THE QUERY
|
||||||
|
|
||||||
var q = PickListSqlBuilder.Build(PickList.ColumnDefinitions, TemplateColumnNames);
|
var q = PickListSqlBuilder.Build(PickList, TemplateColumnNames, autoCompleteQuery);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//RETURN OBJECTS
|
//RETURN OBJECTS
|
||||||
var ret=new List<NameIdActiveItem>();
|
var ret = new List<NameIdActiveItem>();
|
||||||
|
|
||||||
|
|
||||||
//QUERY THE DB
|
//QUERY THE DB
|
||||||
@@ -72,72 +72,72 @@ namespace AyaNova.PickList
|
|||||||
{
|
{
|
||||||
while (dr.Read())
|
while (dr.Read())
|
||||||
{
|
{
|
||||||
// List<AyaFieldData> row = new List<AyaFieldData>(returnRowColumnCount);
|
// List<AyaFieldData> row = new List<AyaFieldData>(returnRowColumnCount);
|
||||||
|
|
||||||
|
|
||||||
// //INSERT REMAINING FIELDS FROM TEMPLATE INTO THE RETURN ROWS LIST
|
// //INSERT REMAINING FIELDS FROM TEMPLATE INTO THE RETURN ROWS LIST
|
||||||
// foreach (string TemplateField in ListViewFieldList)
|
// foreach (string TemplateField in ListViewFieldList)
|
||||||
// {
|
// {
|
||||||
|
|
||||||
// //get the AyaObjectFieldDefinition
|
// //get the AyaObjectFieldDefinition
|
||||||
// AyaPickListFieldDefinition f = PickList.FieldDefinitions.FirstOrDefault(x => x.FieldKey == TemplateField);
|
// AyaPickListFieldDefinition f = PickList.FieldDefinitions.FirstOrDefault(x => x.FieldKey == TemplateField);
|
||||||
// if (f.IsCustomField)
|
// if (f.IsCustomField)
|
||||||
// {
|
// {
|
||||||
|
|
||||||
// AyaFieldData AyaField = new AyaFieldData();
|
// AyaFieldData AyaField = new AyaFieldData();
|
||||||
// var cust = dr.GetString(SelectBuild.map[f.GetSqlValueColumnName()]);
|
// var cust = dr.GetString(SelectBuild.map[f.GetSqlValueColumnName()]);
|
||||||
// if (!string.IsNullOrWhiteSpace(cust))
|
// if (!string.IsNullOrWhiteSpace(cust))
|
||||||
// {
|
// {
|
||||||
// JObject j = JObject.Parse(cust);
|
// JObject j = JObject.Parse(cust);
|
||||||
// //convert field name to cust name then get value
|
// //convert field name to cust name then get value
|
||||||
// var InternalCustomFieldName = AyaFormFieldDefinitions.TranslateLTCustomFieldToInternalCustomFieldName(TemplateField);
|
// var InternalCustomFieldName = AyaFormFieldDefinitions.TranslateLTCustomFieldToInternalCustomFieldName(TemplateField);
|
||||||
// //Sometimes a custom field is specified but doesn't exist in the collection so don't assume it's there
|
// //Sometimes a custom field is specified but doesn't exist in the collection so don't assume it's there
|
||||||
// // AyaField.v = j[InternalCustomFieldName].Value<object>();
|
// // AyaField.v = j[InternalCustomFieldName].Value<object>();
|
||||||
// JToken o = j[InternalCustomFieldName];
|
// JToken o = j[InternalCustomFieldName];
|
||||||
// if (o != null)
|
// if (o != null)
|
||||||
// AyaField.v = o.Value<object>();
|
// AyaField.v = o.Value<object>();
|
||||||
// else
|
// else
|
||||||
// AyaField.v = null;
|
// AyaField.v = null;
|
||||||
|
|
||||||
// row.Add(AyaField);
|
// row.Add(AyaField);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// /*
|
// /*
|
||||||
// TODO: Custom field handling
|
// TODO: Custom field handling
|
||||||
// GetName works just not with multipart identifiers
|
// GetName works just not with multipart identifiers
|
||||||
// I could force naming by making all fields and AS, or
|
// I could force naming by making all fields and AS, or
|
||||||
// I could map the ordinal when generating the Select fields so that I have a map to refer to here
|
// I could map the ordinal when generating the Select fields so that I have a map to refer to here
|
||||||
// mapping in advance actually makes a lot of sense, then no more of this fragility of going by pointer index and hoping for the best
|
// mapping in advance actually makes a lot of sense, then no more of this fragility of going by pointer index and hoping for the best
|
||||||
// it would just be premapped out.
|
// it would just be premapped out.
|
||||||
|
|
||||||
// dr.GetOrdinal(f.SqlValueColumnName)
|
// dr.GetOrdinal(f.SqlValueColumnName)
|
||||||
// 'dr.GetOrdinal(f.SqlValueColumnName)' threw an exception of type 'System.IndexOutOfRangeException'
|
// 'dr.GetOrdinal(f.SqlValueColumnName)' threw an exception of type 'System.IndexOutOfRangeException'
|
||||||
// f.SqlValueColumnName
|
// f.SqlValueColumnName
|
||||||
// "awidget.customfields"
|
// "awidget.customfields"
|
||||||
// dr.GetName(nCurrentColumnPointer)
|
// dr.GetName(nCurrentColumnPointer)
|
||||||
// "customfields"
|
// "customfields"
|
||||||
// dr.GetOrdinal("customfields");
|
// dr.GetOrdinal("customfields");
|
||||||
// 5
|
// 5
|
||||||
|
|
||||||
// */
|
// */
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// AyaFieldData AyaField = new AyaFieldData();
|
// AyaFieldData AyaField = new AyaFieldData();
|
||||||
// AyaField.v = dr.GetValue(SelectBuild.map[f.GetSqlValueColumnName()]);
|
// AyaField.v = dr.GetValue(SelectBuild.map[f.GetSqlValueColumnName()]);
|
||||||
|
|
||||||
|
|
||||||
// if (f.SqlIdColumnName != null)
|
// if (f.SqlIdColumnName != null)
|
||||||
// {
|
// {
|
||||||
// var ordinal = SelectBuild.map[f.SqlIdColumnName];
|
// var ordinal = SelectBuild.map[f.SqlIdColumnName];
|
||||||
// if (!await dr.IsDBNullAsync(ordinal))
|
// if (!await dr.IsDBNullAsync(ordinal))
|
||||||
// AyaField.i = dr.GetInt64(ordinal);
|
// AyaField.i = dr.GetInt64(ordinal);
|
||||||
|
|
||||||
// }
|
// }
|
||||||
// row.Add(AyaField);
|
// row.Add(AyaField);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// rows.Add(row);
|
// rows.Add(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ namespace AyaNova.PickList
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,116 +13,55 @@ namespace AyaNova.PickList
|
|||||||
internal static class PickListSqlBuilder
|
internal static class PickListSqlBuilder
|
||||||
{
|
{
|
||||||
|
|
||||||
//Build the SELECT portion of a list query based on the ListView fields
|
//Build the query for a picklist request
|
||||||
internal static string Build(List<AyaPickListFieldDefinition> objectFieldsList, List<string> listViewFieldList)
|
internal static string Build(IAyaPickList pickList, List<string> templateColumnNames, string autoCompleteQuery)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//TODO: if no autocompletequery returns the first XX results without querying in natural order by column names
|
||||||
|
//if autocomplete returns teh first XX results with query in natural order by column names
|
||||||
|
|
||||||
//TODO: build a sql select and order by and a where clause that searches appropriately in each field (tags)
|
//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
|
//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
|
//and the fields should be combined in a standard way separated by spaces "Widget widgetserial username" for compactness
|
||||||
|
|
||||||
// StringBuilder sb = new StringBuilder();
|
//lists to collect the clauses so to avoid comma fuckery
|
||||||
// sb.Append("SELECT ");
|
List<string> lSelect = new List<string>();
|
||||||
|
List<string> lWhere = new List<string>();
|
||||||
// //DEPRECATED
|
|
||||||
// // //Default ID column for each row (always is aliased as df)
|
|
||||||
// // AyaPickListFieldDefinition def = objectFieldsList.FirstOrDefault(x => x.FieldKey == "df");
|
|
||||||
// // if (def == null)
|
|
||||||
// // {
|
|
||||||
// // throw new System.ArgumentNullException("PickListSqlSelectBuilder: objectFieldList is missing the df default field");
|
|
||||||
// // }
|
|
||||||
// // if (string.IsNullOrEmpty(def.SqlIdColumnName))
|
|
||||||
// // {
|
|
||||||
// // sb.Append("id");//default when no alternate column is specified
|
|
||||||
// // }
|
|
||||||
// // else
|
|
||||||
// // {
|
|
||||||
// // sb.Append(def.SqlIdColumnName);
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // sb.Append(" AS df");
|
|
||||||
|
|
||||||
// //keep track of which custom fields columns were added already
|
|
||||||
// //this ensures that if there is more than one set of custom fields like from two different objects in the list
|
|
||||||
// //only unique ones will be returned by query
|
|
||||||
// // Dictionary<string, int> CustomFieldColumnsAddedToQuery = new Dictionary<string, int>();
|
|
||||||
// //map sql column name to ordinal name
|
|
||||||
// Dictionary<string, int> map = new Dictionary<string, int>();
|
|
||||||
|
|
||||||
// //DEPRECATED map.Add("df", 0);
|
|
||||||
// int nOrdinal = 0;
|
|
||||||
|
|
||||||
// var firstColumnAdded = false;
|
|
||||||
// foreach (string ColumnName in listViewFieldList)
|
|
||||||
// {
|
|
||||||
// // //skip the df column, it's already been processed above
|
|
||||||
// // if (ColumnName == "df")
|
|
||||||
// // continue;
|
|
||||||
// AyaPickListFieldDefinition o = objectFieldsList.FirstOrDefault(x => x.FieldKey == ColumnName);
|
|
||||||
// #if (DEBUG)
|
|
||||||
// //Developers little helper
|
|
||||||
// if (o == null)
|
|
||||||
// {
|
|
||||||
// throw new System.ArgumentNullException($"DEV ERROR in PickListSqlSelectBuilder.cs: field {ColumnName} specified in template was NOT found in ObjectFields list");
|
|
||||||
// }
|
|
||||||
// #endif
|
|
||||||
// if (o != null)
|
|
||||||
// {//Ignore missing fields in production
|
|
||||||
|
|
||||||
|
|
||||||
// if (o.IsCustomField)
|
//Add rowid column as it's always required
|
||||||
// { //if any are custom field then add custom fields column to query
|
AyaPickListFieldDefinition rowIdColumn = pickList.ColumnDefinitions.FirstOrDefault(x => x.IsRowId == true);
|
||||||
// var CustomFieldSqlColumnName = o.GetSqlValueColumnName();
|
lSelect.Add(rowIdColumn.SqlIdColumnName + " AS rowid");
|
||||||
// //has it been added yet?
|
|
||||||
// if (!map.ContainsKey(CustomFieldSqlColumnName))
|
|
||||||
// { //nope
|
|
||||||
// if (firstColumnAdded)
|
|
||||||
// sb.Append(", ");
|
|
||||||
// sb.Append(CustomFieldSqlColumnName);
|
|
||||||
// firstColumnAdded = true;
|
|
||||||
// map.Add(CustomFieldSqlColumnName, nOrdinal++);
|
|
||||||
// }
|
|
||||||
// //if it was already added then can just ignore it
|
|
||||||
// // else
|
|
||||||
// // {
|
|
||||||
// // map.Add(ColumnName, CustomFieldColumnsAddedToQuery[CustomFieldSqlColumnName]);
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// }
|
foreach (string ColumnName in templateColumnNames)
|
||||||
// else
|
{
|
||||||
// {
|
|
||||||
// var valueColumnName = o.GetSqlValueColumnName();
|
|
||||||
// if (!map.ContainsKey(valueColumnName))
|
|
||||||
// {
|
|
||||||
// if (firstColumnAdded)
|
|
||||||
// sb.Append(", ");
|
|
||||||
// sb.Append(valueColumnName);
|
|
||||||
// firstColumnAdded = true;
|
|
||||||
// map.Add(valueColumnName, nOrdinal++);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //does it also have an ID column?
|
AyaPickListFieldDefinition o = pickList.ColumnDefinitions.FirstOrDefault(x => x.FieldKey == ColumnName);
|
||||||
// var idColumnName = o.SqlIdColumnName;
|
#if (DEBUG)
|
||||||
// if (!string.IsNullOrWhiteSpace(idColumnName))
|
if (o == null)
|
||||||
// {
|
{
|
||||||
// if (!map.ContainsKey(idColumnName))
|
throw new System.ArgumentNullException($"DEV ERROR in PickListSqlBuilder.cs: field {ColumnName} specified in template was NOT found in columnDefinitions list");
|
||||||
// {
|
}
|
||||||
// if (firstColumnAdded)
|
#endif
|
||||||
// sb.Append(", ");
|
if (o != null)
|
||||||
// sb.Append(idColumnName);
|
{//Ignore missing fields in production
|
||||||
// firstColumnAdded = true;
|
|
||||||
// map.Add(idColumnName, nOrdinal++);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
var valueColumnName = o.GetSqlValueColumnName();
|
||||||
|
|
||||||
// }
|
lSelect.Add(valueColumnName);
|
||||||
// }
|
string sWhere=$"{valueColumnName} LIKE '%{autoCompleteQuery"
|
||||||
// // return new SqlSelectBuilderResult() { map = map, Select = sb.ToString() };
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return sbSelect.ToString() + pickList.SQLFrom + sbWhere.ToString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user