Delimiter //
/**
 * Add a Row in the Contact's loader table
 *
 * @author Jean-François
 */
Drop Procedure If Exists LOADER_TEST_MOCK_CONTACTS_PUSH//
Create Procedure LOADER_TEST_MOCK_CONTACTS_PUSH(
    In id Int
    , In datas Text
    , In id_status Int
    , In datas_status Text
)
Begin

    Set @id_status = id_status;
    If Coalesce(id_status,0) = 0 
        Then 
            Set @id_status = (Select Coalesce(Max(ID_LOADER_STATUS), 0) + 1 From LOADER_STATUS);
            call LOADER_TEST_MOCK_STATUS_PUSH(@id_status, datas_status);
    Else
        Set @found = (Select ID_LOADER_STATUS From LOADER_STATUS Where ID_LOADER_STATUS = @id_status);
        If @found Is Null Then
            -- Set @id_status = (Select Coalesce(Max(ID_LOADER_STATUS), 0) + 1 From LOADER_STATUS);
            call LOADER_TEST_MOCK_STATUS_PUSH(@id_status, datas_status);
        End If;
    End If;

    Set datas = Concat(
        'LOADER_STATUS_ID_LOADER_STATUS = ', @id_status 
        , ',ID_LOADER_CONTACTS = ', id
        , ',', datas);
    Set @query = Concat('Insert Into LOADER_CONTACTS Set ', datas);
    Prepare stmt FROM @query;
    Execute stmt;
    Deallocate prepare stmt;
End//
Delimiter ;