fix query mangling in cursor terminators