This commit is contained in:
@@ -20,57 +20,29 @@ namespace AyaNova.DataList
|
||||
//Build the SELECT portion of a list query based on the ListView fields
|
||||
internal static SqlSelectBuilderResult Build(List<AyaDataListFieldDefinition> objectFieldsList, List<string> listViewFieldList)
|
||||
{
|
||||
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("SELECT ");
|
||||
|
||||
//DEPRECATED
|
||||
// //Default ID column for each row (always is aliased as df)
|
||||
// AyaDataListFieldDefinition def = objectFieldsList.FirstOrDefault(z => z.FieldKey == "df");
|
||||
// if (def == null)
|
||||
// {
|
||||
// throw new System.ArgumentNullException("DataListSqlSelectBuilder: 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>();
|
||||
//only unique ones will be returned by query
|
||||
//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;
|
||||
AyaDataListFieldDefinition o = objectFieldsList.FirstOrDefault(z => z.FieldKey == ColumnName);
|
||||
#if (DEBUG)
|
||||
//Developers little helper
|
||||
if (o == null)
|
||||
{
|
||||
throw new System.ArgumentNullException($"DEV ERROR in DataListSqlSelectBuilder.cs: field {ColumnName} specified in template was NOT found in ObjectFields list");
|
||||
throw new System.ArgumentNullException($"DEV ERROR in DataListSqlSelectBuilder.cs:Build() 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();
|
||||
@@ -83,12 +55,6 @@ namespace AyaNova.DataList
|
||||
firstColumnAdded = true;
|
||||
map.Add(CustomFieldSqlColumnName, nOrdinal++);
|
||||
}
|
||||
//if it was already added then can just ignore it
|
||||
// else
|
||||
// {
|
||||
// map.Add(ColumnName, CustomFieldColumnsAddedToQuery[CustomFieldSqlColumnName]);
|
||||
// }
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -115,16 +81,64 @@ namespace AyaNova.DataList
|
||||
map.Add(idColumnName, nOrdinal++);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return new SqlSelectBuilderResult() { map = map, Select = sb.ToString() };
|
||||
}//eof
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Build the SELECT portion of a list query but only to return rowid's
|
||||
internal static SqlSelectBuilderResult BuildForReportIdListOnly(List<AyaDataListFieldDefinition> objectFieldsList, List<string> listViewFieldList)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("SELECT ");
|
||||
//map sql column name to ordinal name
|
||||
Dictionary<string, int> map = new Dictionary<string, int>();
|
||||
int nOrdinal = 0;
|
||||
|
||||
var firstColumnAdded = false;
|
||||
foreach (string ColumnName in listViewFieldList)
|
||||
{
|
||||
AyaDataListFieldDefinition o = objectFieldsList.FirstOrDefault(z => z.FieldKey == ColumnName);
|
||||
#if (DEBUG)
|
||||
//Developers little helper
|
||||
if (o == null)
|
||||
{
|
||||
throw new System.ArgumentNullException($"DEV ERROR in DataListSqlSelectBuilder.cs:BuildForReportIdListOnly() field {ColumnName} specified in template was NOT found in ObjectFields list");
|
||||
}
|
||||
#endif
|
||||
if (o != null && o.IsRowId)//only return the rowid column
|
||||
{//Ignore missing fields in production
|
||||
|
||||
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() };
|
||||
}//eof
|
||||
|
||||
|
||||
}//eoc
|
||||
|
||||
Reference in New Issue
Block a user