fix db query