graphql: create history table before running

This commit is contained in:
Jonathan Jenne 2024-01-18 15:54:25 +01:00
parent dc6ad9afac
commit 6e5b192fb6

View File

@ -120,7 +120,11 @@ Public Class GraphQLJob
' Clear Table before inserting ' Clear Table before inserting
If pQuery.ClearBeforeFill = True Then If pQuery.ClearBeforeFill = True Then
If DeleteWithQueryName(pQuery) = False Then If DeleteWithQueryName(pQuery) = False Then
Throw New ApplicationException($"Error while clearing table before fill for Query [{pQuery.Name}]") 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 End If
End If End If
@ -196,12 +200,28 @@ Public Class GraphQLJob
End Try End Try
End Function End Function
Private Function DeleteWithQueryName(pQuery) Private Function DeleteWithQueryName(pQuery As GraphQL.Query) As Boolean
Dim oDeleteSQL = $"TRUNCATE TABLE {pQuery.DestinationTable}" Dim oHistoryTableName = $"{pQuery.DestinationTable}_HISTORY"
Return _MSSQL.ExecuteNonQuery(oDeleteSQL) Dim oDeleteHistorySQL = $"
IF (EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = '{oHistoryTableName}'))
BEGIN
DROP TABLE {oHistoryTableName};
END"
Return _MSSQL.ExecuteNonQuery(oDeleteHistorySQL)
End Function End Function
Private Function DeleteWithStatus(pQuery As Query, pStatus As Integer) Private Function CreateHistoryTable(pQuery As Query) As Boolean
Dim oHistoryTableName = $"{pQuery.DestinationTable}_HISTORY"
Dim oFillHistorySQL = $"SELECT * INTO {oHistoryTableName} FROM {pQuery.DestinationTable}"
Return _MSSQL.ExecuteNonQuery(oFillHistorySQL)
End Function
Private Function DeleteWithStatus(pQuery As Query, pStatus As Integer) As Boolean
Dim oDeleteSQL = $"DELETE FROM {pQuery.DestinationTable} WHERE STATUS = {pStatus} AND ADDED_QUERY_ID = '{pQuery.Id}'" Dim oDeleteSQL = $"DELETE FROM {pQuery.DestinationTable} WHERE STATUS = {pStatus} AND ADDED_QUERY_ID = '{pQuery.Id}'"
Return _MSSQL.ExecuteNonQuery(oDeleteSQL) Return _MSSQL.ExecuteNonQuery(oDeleteSQL)
End Function End Function