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

    Set @datas = datas;

    -- default values
    If Coalesce(@datas, '') Not Regexp 'LOADER_STATUS_BATCH_NUM' 
        Then
            Set @datas = Concat('LOADER_STATUS_BATCH_NUM = 1', Coalesce(Concat(' , ', @datas ), '') );
    End If;

    If Coalesce(@datas, '') Not Regexp 'SRC_TABLE_ID' 
        Then
            Set @id_src = (Select Coalesce(Max(SRC_TABLE_ID), 0) + 1 From LOADER_STATUS);
            Set @datas = Concat('SRC_TABLE_ID = ', @id_src, Coalesce(Concat(' , ', @datas ), '') );
    End If;

    If id > 0 Then
        Set @datas = Concat(
            'ID_LOADER_STATUS = ', id
            , Coalesce(Concat(',', @datas), '')
        );
    End If;

    If Coalesce(@datas, '') != '' Then 
        Set @query = Concat('Insert Into LOADER_STATUS Set ', Coalesce(@datas, ''), ';');
        Prepare stmt FROM @query;
        Execute stmt;
        Deallocate prepare stmt;
    End If;

End//
Delimiter ;
