Compile subroutine Copy_Backlog_Records_To_SQL_DEV(VOID)
#pragma precomp SRP_PreCompiler

/*****************************************************************************\
	This is a utility function. For each record found in SQL_BACKLOG, it makes
	sure the identified record is copied to SQL. Then the backlog record is
	removed.
	
	History
	-------
	08/10/2010    KRF    Original Programmer
\*****************************************************************************/

$Insert APP_INSERTS

Declare subroutine Copy_Record_To_SQL, Delete_Record_From_SQL, obj_Notes, Set_Status
Declare function GetTickCount
StartTime   = GetTickCount()
If @User4 EQ 'DANIEL_ST' then debug
Open "SQL_BACKLOG" to hTable then
    Open 'SQL_BACKLOG_QUARANTINE' to qTable then
        ClearSelect
        Select hTable
        Done = 0
        Loop
            StatusCode = ''
            Set_Status(0)
            ReadNext Key else Done = 1
        Until Done
            Read Rec from hTable, Key then
                Table = Key[1, "*"]
                ID    = Key[Col2() + 1, Len(Key)]
                If ID[-7, 7] EQ "*DELETE" then
                    ID[-7, 7] = ""
                    Delete_Record_From_SQL(Table, ID, 1)
                    If Get_Status(StatusCode) then
                        // Copy record to quarantine queue
                        Write Rec to qTable, Key then
                            // Send notification
                            Recipients   = 'DANIEL_ST':@VM:'JONATHAN_O'
                            SentFrom     = @USER4
                            Subject      = 'SQL Backlog Quarantine Event'
                            Message      = Key 
                            AttachWindow = ''
                            AttachKey    = ''
                            SendToGroup  = ''
				            Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
                            obj_Notes('Create', Parms)
                        end
                    end
                    Delete hTable, Key
                end else
                    Copy_Record_To_SQL(Table, ID, 1)
                    If Get_Status(StatusCode) then
                        // Copy record to quarantine queue
                        Write Rec to qTable, Key then
                            // Send notification
                            Recipients   = 'DANIEL_ST':@VM:'JONATHAN_O'
                            SentFrom     = @USER4
                            Subject      = 'SQL Backlog Quarantine Event'
                            Message      = Key 
                            AttachWindow = ''
                            AttachKey    = ''
                            SendToGroup  = ''
				            Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
                            obj_Notes('Create', Parms)
                        end
                    end
                    Delete hTable, Key
                end
            end
        Repeat
    end
end

Return

