From 8362e1885d085f39905fce645e179a2d07766898 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 22 Jan 2024 11:57:45 +0100 Subject: [PATCH] Jobs: truncate table before 'clearbeforefill' --- Jobs/GraphQL/GraphQLJob.vb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Jobs/GraphQL/GraphQLJob.vb b/Jobs/GraphQL/GraphQLJob.vb index 60fd33c4..0e4f3826 100644 --- a/Jobs/GraphQL/GraphQLJob.vb +++ b/Jobs/GraphQL/GraphQLJob.vb @@ -119,17 +119,21 @@ Public Class GraphQLJob ' Clear Table before inserting If pQuery.ClearBeforeFill = True Then - If DeleteWithQueryName(pQuery) = False Then + If DeleteHistoryTable(pQuery) = False Then Throw New ApplicationException($"Error while dropping history table before fill for Query [{pQuery.Name}]") End If If CreateHistoryTable(pQuery) = False Then Throw New ApplicationException($"Error while creating history table before fill for Query [{pQuery.Name}]") End If + + If TruncateTable(pQuery) = False Then + Throw New ApplicationException($"Error while truncating table before fill for Query [{pQuery.Name}]") + End If End If - ' Reset all records to status = 0 - If pQuery.ClearBeforeFill = False Then + ' Reset all records to status = 0 + If pQuery.ClearBeforeFill = False Then _Logger.Info("Resetting data for Query [{0}]", pQuery.Name) If UpdateWithStatus(pQuery, 0) = False Then Throw New ApplicationException($"Error while resetting status of current Records for Query [{pQuery.Name}]") @@ -200,7 +204,7 @@ Public Class GraphQLJob End Try End Function - Private Function DeleteWithQueryName(pQuery As GraphQL.Query) As Boolean + Private Function DeleteHistoryTable(pQuery As Query) As Boolean Dim oHistoryTableName = $"{pQuery.DestinationTable}_HISTORY" Dim oDeleteHistorySQL = $" IF (EXISTS (SELECT * @@ -214,6 +218,12 @@ Public Class GraphQLJob Return _MSSQL.ExecuteNonQuery(oDeleteHistorySQL) End Function + Private Function TruncateTable(pQuery As Query) + Dim oDeleteTableSQL = $"TRUNCATE TABLE {pQuery.DestinationTable}" + + Return _MSSQL.ExecuteNonQuery(oDeleteTableSQL) + End Function + Private Function CreateHistoryTable(pQuery As Query) As Boolean Dim oHistoryTableName = $"{pQuery.DestinationTable}_HISTORY" Dim oFillHistorySQL = $"SELECT * INTO {oHistoryTableName} FROM {pQuery.DestinationTable}"