This commit is contained in:
@@ -104,27 +104,52 @@ namespace AyaNova.DataList
|
||||
|
||||
//GetOrdinal by name is flakey in npgsql so just going by field definition and ordinal numerically
|
||||
int nCurrentColumnPointer = 1;//start at 1
|
||||
|
||||
//INSERT REMAINING FIELDS FROM TEMPLATE INTO THE RETURN ROWS LIST
|
||||
// dr.GetOrdinal();
|
||||
// dr.GetName();
|
||||
//INSERT REMAINING FIELDS FROM TEMPLATE INTO THE RETURN ROWS LIST
|
||||
foreach (string TemplateField in ListViewFieldList)
|
||||
{
|
||||
if (TemplateField == "df")
|
||||
continue;
|
||||
//get the AyaObjectFieldDefinition
|
||||
AyaDataListFieldDefinition f = DataList.FieldDefinitions.FirstOrDefault(x => x.FieldKey == TemplateField);
|
||||
|
||||
AyaFieldData AyaField = new AyaFieldData();
|
||||
AyaField.v = dr.GetValue(nCurrentColumnPointer);
|
||||
nCurrentColumnPointer++;
|
||||
|
||||
if (f.SqlIdColumnName != null)//skip over df column id, it's not there
|
||||
if (f.IsCustomField)
|
||||
{
|
||||
if (!await dr.IsDBNullAsync(nCurrentColumnPointer))
|
||||
AyaField.i = dr.GetInt64(nCurrentColumnPointer);
|
||||
var v=dr;
|
||||
/*
|
||||
TODO: Custom field handling
|
||||
GetName works just not with multipart identifiers
|
||||
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
|
||||
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.
|
||||
|
||||
dr.GetOrdinal(f.SqlValueColumnName)
|
||||
'dr.GetOrdinal(f.SqlValueColumnName)' threw an exception of type 'System.IndexOutOfRangeException'
|
||||
f.SqlValueColumnName
|
||||
"awidget.customfields"
|
||||
dr.GetName(nCurrentColumnPointer)
|
||||
"customfields"
|
||||
dr.GetOrdinal("customfields");
|
||||
5
|
||||
|
||||
nCurrentColumnPointer++;
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
AyaFieldData AyaField = new AyaFieldData();
|
||||
AyaField.v = dr.GetValue(nCurrentColumnPointer);
|
||||
nCurrentColumnPointer++;
|
||||
|
||||
if (f.SqlIdColumnName != null)//skip over df column id, it's not there
|
||||
{
|
||||
if (!await dr.IsDBNullAsync(nCurrentColumnPointer))
|
||||
AyaField.i = dr.GetInt64(nCurrentColumnPointer);
|
||||
|
||||
nCurrentColumnPointer++;
|
||||
}
|
||||
row.Add(AyaField);
|
||||
}
|
||||
row.Add(AyaField);
|
||||
}
|
||||
rows.Add(row);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ namespace AyaNova.DataList
|
||||
var fld = cm["fld"].Value<string>();
|
||||
var dataType = objectFieldsList.Find(x => x.FieldKey.ToLowerInvariant() == fld).UiFieldDataType;
|
||||
AyaDataListFieldDefinition DataListField = objectFieldsList.FirstOrDefault(x => x.FieldKey == fld);
|
||||
|
||||
//No filtering on custom fields!
|
||||
if(DataListField.IsCustomField){
|
||||
continue;
|
||||
}
|
||||
#if (DEBUG)
|
||||
//Developers little helper
|
||||
if (DataListField == null)
|
||||
|
||||
@@ -31,6 +31,10 @@ namespace AyaNova.DataList
|
||||
var dir = cm["sort"].Value<string>();
|
||||
//Get the correct sql column name
|
||||
AyaDataListFieldDefinition DataListField = objectFieldsList.FirstOrDefault(x => x.FieldKey == fld);
|
||||
//No sorting on custom fields!
|
||||
if(DataListField.IsCustomField){
|
||||
continue;
|
||||
}
|
||||
#if (DEBUG)
|
||||
//Developers little helper
|
||||
if (DataListField == null)
|
||||
|
||||
@@ -37,7 +37,15 @@ namespace AyaNova.DataList
|
||||
|
||||
sb.Append(" AS df");
|
||||
|
||||
bool CustomFieldIncluded = false;
|
||||
//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>();
|
||||
|
||||
map.Add("df", 0);
|
||||
int nOrdinal = 0;
|
||||
foreach (string ColumnName in listViewFieldList)
|
||||
{
|
||||
//skip the df column, it's already been processed above
|
||||
@@ -54,29 +62,42 @@ namespace AyaNova.DataList
|
||||
if (o != null)
|
||||
{//Ignore missing fields in production
|
||||
|
||||
|
||||
if (o.IsCustomField && !CustomFieldIncluded)
|
||||
|
||||
if (o.IsCustomField)
|
||||
{ //if any are custom field then add custom fields column to query
|
||||
CustomFieldIncluded=true;
|
||||
sb.Append(", ");
|
||||
sb.Append(o.GetSqlValueColumnName());
|
||||
var CustomFieldSqlColumnName = o.GetSqlValueColumnName();
|
||||
//has it been added yet?
|
||||
if (!map.ContainsKey(CustomFieldSqlColumnName))
|
||||
{ //nope
|
||||
sb.Append(", ");
|
||||
sb.Append(CustomFieldSqlColumnName);
|
||||
map.Add(CustomFieldSqlColumnName, ++nOrdinal);
|
||||
}
|
||||
//if it was already added then can just ignore it
|
||||
// else
|
||||
// {
|
||||
// map.Add(ColumnName, CustomFieldColumnsAddedToQuery[CustomFieldSqlColumnName]);
|
||||
// }
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(", ");
|
||||
sb.Append(o.GetSqlValueColumnName());
|
||||
map.Add(o.GetSqlValueColumnName(), ++nOrdinal);
|
||||
|
||||
//does it also have an ID column?
|
||||
if (!string.IsNullOrWhiteSpace(o.SqlIdColumnName))
|
||||
{
|
||||
sb.Append(", ");
|
||||
sb.Append(o.SqlIdColumnName);
|
||||
map.Add(o.SqlIdColumnName, ++nOrdinal);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
TODO: return map and sb as composite object here
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user