Must include the indicator code when removing economic indicatos.
All checks were successful
Build .NET Project / build (push) Successful in 4m42s
All checks were successful
Build .NET Project / build (push) Successful in 4m42s
This commit is contained in:
@@ -207,11 +207,17 @@ namespace MarketData.DataAccess
|
||||
sqlCommand = sqlConnection.CreateCommand();
|
||||
sqlCommand.Transaction = sqlTransaction;
|
||||
List<String> distinctCountryCodes = (from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.CountryCode).Distinct().ToList();
|
||||
List<String> indicatorCodes = (from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.IndicatorCode).Distinct().ToList();
|
||||
if(indicatorCodes.Count>1)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("InsertUpdateEconomicIndicators Expected a single indicator code but found multiple '{0}'",Utility.ListToString(indicatorCodes)));
|
||||
return false;
|
||||
}
|
||||
for (int index = 0; index < distinctCountryCodes.Count; index++)
|
||||
{
|
||||
String countryCode = distinctCountryCodes[index];
|
||||
List<int> years = (from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.Year).Distinct().ToList();
|
||||
DeleteEconomicIndicator(countryCode, years, sqlCommand, sqlTransaction);
|
||||
DeleteEconomicIndicator(indicatorCodes.First(),countryCode, years, sqlCommand, sqlTransaction);
|
||||
}
|
||||
InsertEconomicIndicators(economicIndicators, sqlCommand, sqlTransaction);
|
||||
sqlTransaction.Commit();
|
||||
@@ -251,13 +257,14 @@ namespace MarketData.DataAccess
|
||||
/// Remove items
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static bool DeleteEconomicIndicator(String countryCode, List<int> years, MySqlCommand sqlCommand, MySqlTransaction sqlTransaction)
|
||||
private static bool DeleteEconomicIndicator(String indicatorCode,String countryCode, List<int> years, MySqlCommand sqlCommand, MySqlTransaction sqlTransaction)
|
||||
{
|
||||
String strQuery = null;
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("delete from EconomicIndicators ").Append(" where ");
|
||||
sb.Append("indicator_code=").Append("'").Append(indicatorCode).Append("'").Append(" and ");
|
||||
sb.Append("country_code=").Append("'").Append(countryCode).Append("'").Append(" and ");
|
||||
sb.Append("year in ").Append(SqlUtils.CreateInClause(years));
|
||||
strQuery = sb.ToString();
|
||||
@@ -271,6 +278,31 @@ namespace MarketData.DataAccess
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove items
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
// private static bool DeleteEconomicIndicator(String countryCode, List<int> years, MySqlCommand sqlCommand, MySqlTransaction sqlTransaction)
|
||||
// {
|
||||
// String strQuery = null;
|
||||
// try
|
||||
// {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.Append("delete from EconomicIndicators ").Append(" where ");
|
||||
// sb.Append("country_code=").Append("'").Append(countryCode).Append("'").Append(" and ");
|
||||
// sb.Append("year in ").Append(SqlUtils.CreateInClause(years));
|
||||
// strQuery = sb.ToString();
|
||||
// sqlCommand.CommandText = strQuery;
|
||||
// sqlCommand.ExecuteNonQuery();
|
||||
// return true;
|
||||
// }
|
||||
// catch (Exception exception)
|
||||
// {
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception:{0}, query was {1}", exception.ToString(), strQuery));
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Insert items
|
||||
|
||||
Reference in New Issue
Block a user