fix broken sql statement when deleting folders