public void updateVisitedBaseFromLog(enVisitType Refresh)
{
String sqlString;
try
{
if((Refresh & enVisitType.Systems) > 0)
{
sqlString = "insert into tbVisitedSystems(system_id, time)" +
" select L1.system_id, L1.time " +
" from tbLog L1 left join tbVisitedSystems V1 on L1.system_id = V1.system_id " +
" where L1.system_id is not null " +
" and L1.time > V1.time" +
" and not exists (select * from tbLog L2 " +
" where L1.system_id = L2.system_id" +
" and L1.time < L2.time)" +
"on duplicate key update time = L1.time";
Program.DBCon.Execute(sqlString);
}
if((Refresh & enVisitType.Stations) > 0)
{
sqlString = "insert into tbVisitedStations(station_id, time)" +
" select L1.station_id, L1.time " +
" from tbLog L1 left join tbVisitedStations V1 on L1.station_id = V1.station_id " +
" where L1.station_id is not null " +
" and L1.time > V1.time" +
" and not exists (select * from tbLog L2 " +
" where L1.station_id = L2.station_id" +
" and L1.time < L2.time)" +
" on duplicate key update time = L1.time";
Program.DBCon.Execute(sqlString);
}
}
catch (Exception ex)
{
throw new Exception("Error while updating the visited systems from log", ex);
}
}