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 = sqlConnection.CreateCommand();
|
||||||
sqlCommand.Transaction = sqlTransaction;
|
sqlCommand.Transaction = sqlTransaction;
|
||||||
List<String> distinctCountryCodes = (from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.CountryCode).Distinct().ToList();
|
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++)
|
for (int index = 0; index < distinctCountryCodes.Count; index++)
|
||||||
{
|
{
|
||||||
String countryCode = distinctCountryCodes[index];
|
String countryCode = distinctCountryCodes[index];
|
||||||
List<int> years = (from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.Year).Distinct().ToList();
|
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);
|
InsertEconomicIndicators(economicIndicators, sqlCommand, sqlTransaction);
|
||||||
sqlTransaction.Commit();
|
sqlTransaction.Commit();
|
||||||
@@ -251,13 +257,14 @@ namespace MarketData.DataAccess
|
|||||||
/// Remove items
|
/// Remove items
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <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;
|
String strQuery = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.Append("delete from EconomicIndicators ").Append(" where ");
|
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("country_code=").Append("'").Append(countryCode).Append("'").Append(" and ");
|
||||||
sb.Append("year in ").Append(SqlUtils.CreateInClause(years));
|
sb.Append("year in ").Append(SqlUtils.CreateInClause(years));
|
||||||
strQuery = sb.ToString();
|
strQuery = sb.ToString();
|
||||||
@@ -272,6 +279,31 @@ namespace MarketData.DataAccess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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>
|
/// <summary>
|
||||||
/// Insert items
|
/// Insert items
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user