Added failed query logging to datalistfetcher
This commit is contained in:
@@ -73,7 +73,7 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
ApiDataListResponse r = await DataListFetcher.GetResponseAsync(listOptions.DataListKey, ct, listOptions, UserId, UserRoles);
|
||||
ApiDataListResponse r = await DataListFetcher.GetResponseAsync(listOptions.DataListKey, ct, listOptions, UserId, UserRoles, log);
|
||||
return Ok(r);
|
||||
}
|
||||
catch (System.UnauthorizedAccessException)
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Linq;
|
||||
using AyaNova.Biz;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Models;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -13,7 +13,7 @@ namespace AyaNova.DataList
|
||||
{
|
||||
internal static class DataListFetcher
|
||||
{
|
||||
internal static async Task<ApiDataListResponse> GetResponseAsync(string DataListKey, AyContext ct, ListOptions listOptions, long UserId, AuthorizationRoles UserRoles)
|
||||
internal static async Task<ApiDataListResponse> GetResponseAsync(string DataListKey, AyContext ct, ListOptions listOptions, long UserId, AuthorizationRoles UserRoles, ILogger log)
|
||||
{
|
||||
|
||||
var DataList = DataListFactory.GetAyaDataList(DataListKey);
|
||||
@@ -83,99 +83,114 @@ namespace AyaNova.DataList
|
||||
|
||||
//GET DATA RETURN ROWS
|
||||
command.CommandText = qDataQuery;
|
||||
using (var dr = await command.ExecuteReaderAsync())
|
||||
try
|
||||
{
|
||||
while (dr.Read())
|
||||
using (var dr = await command.ExecuteReaderAsync())
|
||||
{
|
||||
List<AyaFieldData> row = new List<AyaFieldData>(returnRowColumnCount);
|
||||
|
||||
|
||||
//INSERT REMAINING FIELDS FROM TEMPLATE INTO THE RETURN ROWS LIST
|
||||
foreach (string TemplateField in ListViewFieldList)
|
||||
while (dr.Read())
|
||||
{
|
||||
List<AyaFieldData> row = new List<AyaFieldData>(returnRowColumnCount);
|
||||
|
||||
//get the AyaObjectFieldDefinition
|
||||
AyaDataListFieldDefinition f = DataList.FieldDefinitions.FirstOrDefault(x => x.FieldKey == TemplateField);
|
||||
if (f.IsCustomField)
|
||||
|
||||
//INSERT REMAINING FIELDS FROM TEMPLATE INTO THE RETURN ROWS LIST
|
||||
foreach (string TemplateField in ListViewFieldList)
|
||||
{
|
||||
|
||||
AyaFieldData AyaField = new AyaFieldData();
|
||||
var cust = dr.GetString(SelectBuild.map[f.GetSqlValueColumnName()]);
|
||||
if (!string.IsNullOrWhiteSpace(cust))
|
||||
//get the AyaObjectFieldDefinition
|
||||
AyaDataListFieldDefinition f = DataList.FieldDefinitions.FirstOrDefault(x => x.FieldKey == TemplateField);
|
||||
if (f.IsCustomField)
|
||||
{
|
||||
JObject j = JObject.Parse(cust);
|
||||
//convert field name to cust name then get value
|
||||
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
|
||||
// AyaField.v = j[InternalCustomFieldName].Value<object>();
|
||||
JToken o = j[InternalCustomFieldName];
|
||||
if (o != null)
|
||||
AyaField.v = o.Value<object>();
|
||||
else
|
||||
AyaField.v = null;
|
||||
|
||||
row.Add(AyaField);
|
||||
}
|
||||
AyaFieldData AyaField = new AyaFieldData();
|
||||
var cust = dr.GetString(SelectBuild.map[f.GetSqlValueColumnName()]);
|
||||
if (!string.IsNullOrWhiteSpace(cust))
|
||||
{
|
||||
JObject j = JObject.Parse(cust);
|
||||
//convert field name to cust name then get value
|
||||
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
|
||||
// AyaField.v = j[InternalCustomFieldName].Value<object>();
|
||||
JToken o = j[InternalCustomFieldName];
|
||||
if (o != null)
|
||||
AyaField.v = o.Value<object>();
|
||||
else
|
||||
AyaField.v = null;
|
||||
|
||||
/*
|
||||
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.
|
||||
row.Add(AyaField);
|
||||
}
|
||||
|
||||
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
|
||||
/*
|
||||
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.
|
||||
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
AyaFieldData AyaField = new AyaFieldData();
|
||||
AyaField.v = dr.GetValue(SelectBuild.map[f.GetSqlValueColumnName()]);
|
||||
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
|
||||
|
||||
if (f.IsRowId)
|
||||
{
|
||||
AyaField.rid = true;
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
AyaField.rid = null;
|
||||
}
|
||||
AyaFieldData AyaField = new AyaFieldData();
|
||||
AyaField.v = dr.GetValue(SelectBuild.map[f.GetSqlValueColumnName()]);
|
||||
|
||||
if (f.SqlIdColumnName != null)
|
||||
{
|
||||
var ordinal = SelectBuild.map[f.SqlIdColumnName];
|
||||
if (!await dr.IsDBNullAsync(ordinal))
|
||||
AyaField.i = dr.GetInt64(ordinal);
|
||||
if (f.IsRowId)
|
||||
{
|
||||
AyaField.rid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AyaField.rid = null;
|
||||
}
|
||||
|
||||
if (f.SqlIdColumnName != null)
|
||||
{
|
||||
var ordinal = SelectBuild.map[f.SqlIdColumnName];
|
||||
if (!await dr.IsDBNullAsync(ordinal))
|
||||
AyaField.i = dr.GetInt64(ordinal);
|
||||
|
||||
}
|
||||
row.Add(AyaField);
|
||||
}
|
||||
row.Add(AyaField);
|
||||
}
|
||||
rows.Add(row);
|
||||
}
|
||||
}
|
||||
|
||||
//GET TOTAL RECORD COUNT
|
||||
command.CommandText = qTotalRecordsQuery;
|
||||
using (var dr = await command.ExecuteReaderAsync())
|
||||
{
|
||||
if (dr.Read())
|
||||
{
|
||||
totalRecordCount = dr.GetInt64(0);
|
||||
}
|
||||
rows.Add(row);
|
||||
}
|
||||
}
|
||||
|
||||
//GET TOTAL RECORD COUNT
|
||||
command.CommandText = qTotalRecordsQuery;
|
||||
using (var dr = await command.ExecuteReaderAsync())
|
||||
catch (Npgsql.PostgresException e)
|
||||
{
|
||||
if (dr.Read())
|
||||
{
|
||||
totalRecordCount = dr.GetInt64(0);
|
||||
}
|
||||
//log out the exception and the query
|
||||
log.LogInformation("DataList query failed unexpectedly. Data Query was:");
|
||||
log.LogInformation(qDataQuery);
|
||||
log.LogInformation("Count Query was:");
|
||||
log.LogInformation(qTotalRecordsQuery);
|
||||
log.LogInformation(e, "DB Exception");
|
||||
throw new System.Exception("DataListFetcher - Query failed see log");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT
|
||||
Newtonsoft.Json.Linq.JArray ColumnsJSON = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user