sqlite: fix bug in get_nuggets when removing rows in the middle of loop