[PDI-13102] - fix and test

the test is provided in form of Integration Test since it's hardly possible to mock Database class behavior.