Compile subroutine Copy_Backlog_WO_LOG_Records_To_SQL(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
\*****************************************************************************/

Declare subroutine Copy_Record_To_SQL, Delete_Record_From_SQL
Declare function GetTickCount
StartTime = GetTickCount()
Open "SQL_BACKLOG_WO_LOG" to hTable then
    ClearSelect
    Select hTable
    Done = 0
    Loop
        ReadNext Key else Done = 1
        
    Until Done
*    Until Done OR (GetTickCount() - StartTime) >= 60000

        Table                  = Key[1, "*"]
        If Table NE 'WO_MAT' and Table NE 'WO_LOG' then
            TempKey                              = Key
            TempKey[1, Len(Table) + 1]           = ''
            TransTime                            = TempKey[-1, 'B*']
            TempKey[-1, Neg(Len(TransTime) + 1)] = ''
            TransDate                            = TempKey[-1, 'B*']
            TempKey[-1, Neg(Len(TransDate) + 1)] = ''
            Process                              = TempKey[-1, 'B*']
            TempKey[-1, Neg(Len(Process) + 1)]   = ''
            ID                                   = TempKey
            If Process EQ 'DELETE' then
                Delete_Record_From_SQL(Table, ID, 1)
                Delete hTable, Key
            end else
                Copy_Record_To_SQL(Table, ID, 1)
                Delete hTable, Key            
            end
        end else
            ID = Key[Col2() + 1, Len(Key)]
            If ID[-7, 7] EQ "*DELETE" then
                ID[-7, 7] = ""
                Delete_Record_From_SQL(Table, ID, 1)
                Delete hTable, Key
            end else
                Copy_Record_To_SQL(Table, ID, 1)
                Delete hTable, Key
            end
        end

*        Table   = Field(Key, '*', 1)
*        ID      = Field(Key, '*', 2)
*        Process = Field(Key, '*', 3)
*        If Process EQ 'DELETE' then
*            Delete_Record_From_SQL(Table, ID, 1)
*            Delete hTable, Key
*        end else
*            Copy_Record_To_SQL(Table, ID, 1)
*            Delete hTable, Key            
*        end

*        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)
*            Delete hTable, Key
*        end else
*            Copy_Record_To_SQL(Table, ID, 1)
*            Delete hTable, Key
*        end
    Repeat
end

Return
