reworked db operations, fix #2229