Take cancel into account while executing a query