Delimiter //
/**
 * Initialize context to work with a given business table
 *
 * @author Jean-François
 */
Drop Procedure If Exists LOADER_TEST_MOCK_BUSINESS_START//
Create Procedure LOADER_TEST_MOCK_BUSINESS_START(
    In tablename Varchar(80)
)
Begin

    Set @tablenameTest = Concat('test_', Coalesce(tablename, ''));

    Call CASH_ISTABLE(@tablenameTest, @exists);
    If Coalesce(@exists, 0) = 0 Then

        Set @query = Concat('Create Temporary Table ', @tablenameTest ,' As Select * From ', Coalesce(tablename, ''));
        Prepare stmt From @query;
        Execute stmt;
        Deallocate prepare stmt;
        
        Set FOREIGN_KEY_CHECKS = 0;

        Set @query = Concat('Delete From ', Coalesce(tablename, ''));
        Prepare stmt From @query;
        Execute stmt;
        Deallocate prepare stmt;

        Set FOREIGN_KEY_CHECKS = 1;

    End If;

End//
Delimiter ;