fix probably broken sql query on sqlite and postgres for deleting items after a folder was deleted