Compile subroutine Copy_Sql_Errors_Record_To_Sql(Date, Silent)

Equ Update_Interval$ to 1000

Declare function GetTickCount, Get.RecCount, Copy_Record_To_Sql

// Counters
NumCopied = 0
StartTime = GetTickCount()

If Assigned(Date) else Date = ""
If Assigned(Silent) else Silent = 0
If Silent EQ "" then Silent = 0
    
// Get the errors
NewErrors = ""
Errors = Xlate("SQL_ERROR", Date, "", "X")
LenErrors = Len(Errors)
If LenErrors then
    
    // Loop through the errors
    NumErrors = Count(Errors, @FM) + 1
    For iError = 1 to NumErrors
        Error = Errors<1>
        Table = Error<1, 1>
        Key = Error<1, 2>
        GoSub Copy_Key
    Next iError
    NewErrors[-1, 1] = ""

    // Save the remaining errors or delete the record if there are none
    Open "SQL_ERROR" to hSqlError then
        If Len(NewErrors) then
            Write NewErrors to hSqlError, Date
            If Silent EQ 0 then
                Call SRP_Editor_Open("Record", "SQL_ERROR":@FM:Date)
            end
        end else
            Delete hSqlError, Date else null
            If Silent EQ 0 then
                Call Msg(@Window, "All Errors Processed Successfully.")
            end
        end
    end

end else
    If Silent EQ 0 then
        Call Msg(@Window, Date:" not found.")
    end
end

Return NumCopied

Copy_Key:

    Error = Copy_Record_To_SQL(Table, Key)
    If Len(Error) then
        NewErrors := Key:@VM:Error:@FM
    end
        
    NumCopied += 1
    If GetTickCount() - StartTime GE Update_Interval$ then
        Call SRP_Editor_Send_Info("[":Date:"] Processed: ":NumCopied:" / ":NumErrors)
        StartTime = GetTickCount()
    end
        
return
