Compile subroutine Test_Update_SQL_Deletes(VOID)

Equ Update_Interval$ to 1000

Equ ErrorsOnly$ to 1
Equ NewRecordsOnly$ to 2
Equ CalledFromCopyAllTables$ to 3

$insert WO_MAT_EQUATES
Table = "WO_MAT"
OperationCode = 0
NumToCopy = 0
KeysToCopy = ""
Errors = ""

Declare function Copy_Record_To_SQL, GetTickCount, Get.RecCount, GetASyncKeyState, SQL_Format, SQL_Insert, SQL_Write, SQL_Write_MV, SRP_Com
Declare subroutine SRP_Com

// Make sure table is uppercase
Convert @LOWER_CASE to @UPPER_CASE in Table

// Create the SYSLIST key
ErrorKey = "COPY_TABLE_TO_SQL_ERRORS*":Table

NumCopied = 0

StartTime = GetTickCount()
BeginTime = StartTime
       
// Connect to the ODBC
If SRP_Com(Connection, "CREATE", "ADODB.Connection") then
    
    // Connect to the database via ODBC    
    SRP_Com(Connection, "SET", "Mode", adModeShareDenyNone)
    SRP_Com(Connection, "SET", "CursorLocation", adUseClient)
    If SRP_Com(Connection, "CALL", "Open", "LSL2SQL", "srpadmin", "0okm9ijn") EQ "" then

        Script = "Select WO_NO, CASS_NO From WO_MAT"
        RecordSetResult = SRP_Com(Connection, "CALL", "Execute", Script)
        KeyList = SRP_Com(RecordSetResult, "CALL", "GetString", adClipString, 1, @VM, @FM)
        SRP_Com(RecordSetResult, "RELEASE")
        Convert \0D09\ to @FM:"*" in KeyList
            Open "WO_MAT" to hTable then
            LenKeyList = Len(KeyList)
            Pos = 1
            Loop
                Key = KeyList[Pos, @FM]
                Pos = Col2() + 1
                ReadV Val from hTable, Key, 1 else
                    Script = "Delete from WO_MAT where WO_NO = ":Field(Key, "*", 1):" AND CASS_NO = ":Field(Key, "*", 2)
                    rv = SRP_Com(Connection, "CALL", "Execute", Script)
                    If rv NE 0 then
                        SRP_Com(rv, "RELEASE")
                    end else
                        Ans = SRP_Com(Connection, "ERROR")
                    end
                end
            Until Pos GE LenKeyList
            Repeat
        end
        

    end else
        Call Msg(@Window, SRP_Com(Connection, "ERROR"):@FM:@FM:@FM:"!")
    end
    
    SRP_Com(Connection, "CALL", "Close")
    SRP_Com(Connection, "RELEASE")
    
end else
    Call Msg(@Window, "Unable to create ADO Object.":@FM:@FM:@FM:"!")
end

Open "SYSLISTS" to hSYSLISTS then
    If Errors[-1, 1] EQ @FM then Errors[-1, 1] = ""
    If Len(Errors) then
        Write Errors to hSYSLISTS, ErrorKey
        Call SRP_Editor_Open("Record", "SYSLISTS":@FM:ErrorKey)
    end else
        Delete hSYSLISTS, ErrorKey else null
        If OperationCode NE CalledFromCopyAllTables$ then
            Call Msg(@Window, "No Errors")
        end
    end
end

Return
