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
|
//GetOrdinal by name is flakey in npgsql so just going by field definition and ordinal numerically
|
||||||
int nCurrentColumnPointer = 1;//start at 1
|
int nCurrentColumnPointer = 1;//start at 1
|
||||||
|
// dr.GetOrdinal();
|
||||||
//INSERT REMAINING FIELDS FROM TEMPLATE INTO THE RETURN ROWS LIST
|
// dr.GetName();
|
||||||
|
//INSERT REMAINING FIELDS FROM TEMPLATE INTO THE RETURN ROWS LIST
|
||||||
foreach (string TemplateField in ListViewFieldList)
|
foreach (string TemplateField in ListViewFieldList)
|
||||||
{
|
{
|
||||||
if (TemplateField == "df")
|
if (TemplateField == "df")
|
||||||
continue;
|
continue;
|
||||||
//get the AyaObjectFieldDefinition
|
//get the AyaObjectFieldDefinition
|
||||||
AyaDataListFieldDefinition f = DataList.FieldDefinitions.FirstOrDefault(x => x.FieldKey == TemplateField);
|
AyaDataListFieldDefinition f = DataList.FieldDefinitions.FirstOrDefault(x => x.FieldKey == TemplateField);
|
||||||
|
if (f.IsCustomField)
|
||||||
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))
|
var v=dr;
|
||||||
AyaField.i = dr.GetInt64(nCurrentColumnPointer);
|
/*
|
||||||
|
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.
|
||||||
|
|
||||||
nCurrentColumnPointer++;
|
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
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
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);
|
rows.Add(row);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ namespace AyaNova.DataList
|
|||||||
var fld = cm["fld"].Value<string>();
|
var fld = cm["fld"].Value<string>();
|
||||||
var dataType = objectFieldsList.Find(x => x.FieldKey.ToLowerInvariant() == fld).UiFieldDataType;
|
var dataType = objectFieldsList.Find(x => x.FieldKey.ToLowerInvariant() == fld).UiFieldDataType;
|
||||||
AyaDataListFieldDefinition DataListField = objectFieldsList.FirstOrDefault(x => x.FieldKey == fld);
|
AyaDataListFieldDefinition DataListField = objectFieldsList.FirstOrDefault(x => x.FieldKey == fld);
|
||||||
|
|
||||||
|
//No filtering on custom fields!
|
||||||
|
if(DataListField.IsCustomField){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
//Developers little helper
|
//Developers little helper
|
||||||
if (DataListField == null)
|
if (DataListField == null)
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ namespace AyaNova.DataList
|
|||||||
var dir = cm["sort"].Value<string>();
|
var dir = cm["sort"].Value<string>();
|
||||||
//Get the correct sql column name
|
//Get the correct sql column name
|
||||||
AyaDataListFieldDefinition DataListField = objectFieldsList.FirstOrDefault(x => x.FieldKey == fld);
|
AyaDataListFieldDefinition DataListField = objectFieldsList.FirstOrDefault(x => x.FieldKey == fld);
|
||||||
|
//No sorting on custom fields!
|
||||||
|
if(DataListField.IsCustomField){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
//Developers little helper
|
//Developers little helper
|
||||||
if (DataListField == null)
|
if (DataListField == null)
|
||||||
|
|||||||
@@ -37,7 +37,15 @@ namespace AyaNova.DataList
|
|||||||
|
|
||||||
sb.Append(" AS df");
|
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)
|
foreach (string ColumnName in listViewFieldList)
|
||||||
{
|
{
|
||||||
//skip the df column, it's already been processed above
|
//skip the df column, it's already been processed above
|
||||||
@@ -55,28 +63,41 @@ namespace AyaNova.DataList
|
|||||||
{//Ignore missing fields in production
|
{//Ignore missing fields in production
|
||||||
|
|
||||||
|
|
||||||
if (o.IsCustomField && !CustomFieldIncluded)
|
if (o.IsCustomField)
|
||||||
{ //if any are custom field then add custom fields column to query
|
{ //if any are custom field then add custom fields column to query
|
||||||
CustomFieldIncluded=true;
|
var CustomFieldSqlColumnName = o.GetSqlValueColumnName();
|
||||||
sb.Append(", ");
|
//has it been added yet?
|
||||||
sb.Append(o.GetSqlValueColumnName());
|
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
|
else
|
||||||
{
|
{
|
||||||
sb.Append(", ");
|
sb.Append(", ");
|
||||||
sb.Append(o.GetSqlValueColumnName());
|
sb.Append(o.GetSqlValueColumnName());
|
||||||
|
map.Add(o.GetSqlValueColumnName(), ++nOrdinal);
|
||||||
|
|
||||||
//does it also have an ID column?
|
//does it also have an ID column?
|
||||||
if (!string.IsNullOrWhiteSpace(o.SqlIdColumnName))
|
if (!string.IsNullOrWhiteSpace(o.SqlIdColumnName))
|
||||||
{
|
{
|
||||||
sb.Append(", ");
|
sb.Append(", ");
|
||||||
sb.Append(o.SqlIdColumnName);
|
sb.Append(o.SqlIdColumnName);
|
||||||
|
map.Add(o.SqlIdColumnName, ++nOrdinal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TODO: return map and sb as composite object here
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user