Files
raven/server/AyaNova/PickList/PickListSqlBuilder.cs
2020-03-12 23:39:00 +00:00

132 lines
5.5 KiB
C#

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;
namespace AyaNova.PickList
{
internal static class PickListSqlBuilder
{
//Build the SELECT portion of a list query based on the ListView fields
internal static string Build(List<AyaPickListFieldDefinition> objectFieldsList, List<string> listViewFieldList)
{
throw new System.NotImplementedException();
TODO: build a sql select 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
// StringBuilder sb = new StringBuilder();
// sb.Append("SELECT ");
// //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)
// { //if any are custom field then add custom fields column to query
// var CustomFieldSqlColumnName = o.GetSqlValueColumnName();
// //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]);
// // }
// }
// 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?
// var idColumnName = o.SqlIdColumnName;
// if (!string.IsNullOrWhiteSpace(idColumnName))
// {
// if (!map.ContainsKey(idColumnName))
// {
// if (firstColumnAdded)
// sb.Append(", ");
// sb.Append(idColumnName);
// firstColumnAdded = true;
// map.Add(idColumnName, nOrdinal++);
// }
// }
// }
// }
// }
// // return new SqlSelectBuilderResult() { map = map, Select = sb.ToString() };
}
}//eoc
}//ens