Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #693 Add query log on exceptions #698

Merged
merged 5 commits into from
Apr 4, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/698-bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add logging of query statements to QueryToExecute for exceptions
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using ReusableLibraryCode.DataAccess;
using FAnsi.Discovery;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using MapsDirectlyToDatabaseTable;
using MySqlConnector;
using NLog;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.Curation.Data.Spontaneous;
using Rdmp.Core.Repositories;
using Rdmp.Core.QueryBuilding;
using Rdmp.Core.Repositories;
using ReusableLibraryCode.DataAccess;
using System;
using System.Collections.Generic;
using System.Data.Common;

namespace Microservices.CohortExtractor.Execution.RequestFulfillers
{
public class QueryToExecute
{
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();

protected QueryToExecuteColumnSet Columns { get; }

/// <summary>
/// The column to search for in the WHERE logic
/// </summary>
Expand Down Expand Up @@ -125,33 +126,45 @@ public IEnumerable<QueryToExecuteResult> Execute(string valueToLookup, List<IRej
using (DbConnection con = Server.GetConnection())
{
con.Open();
DbDataReader r = Server.GetCommand(GetSqlForKeyValue(valueToLookup), con).ExecuteReader();

while (r.Read())
string sqlString = GetSqlForKeyValue(valueToLookup);

DbDataReader reader;
try
{
reader = Server.GetCommand(sqlString, con).ExecuteReader();
}
catch (MySqlException)
{
_logger.Error($"The following query resulted in an exception: {sqlString}");
throw;
}

while (reader.Read())
{
object imagePath = r[path];
object imagePath = reader[path];

if (imagePath == DBNull.Value)
continue;

bool reject = false;
string rejectReason = null;

//Ask the rejectors how good this record is
foreach (IRejector rejector in rejectors)
{
if (rejector.Reject(r, out rejectReason))
if (rejector.Reject(reader, out rejectReason))
{
reject = true;
break;
}
}
yield return
new QueryToExecuteResult((string) imagePath,
study == null ? null : (string) r[study],
series == null ? null : (string) (string) r[series],
instance == null ? null : (string) (string) r[instance],

yield return
new QueryToExecuteResult((string)imagePath,
study == null ? null : (string)reader[study],
series == null ? null : (string)(string)reader[series],
instance == null ? null : (string)(string)reader[instance],
reject,
rejectReason);
}
Expand Down