Fix places that remember a query context in a prepared expression

The query context typically points to the network server. Any actual operation on the (potentially shared) expression will pass the correct query context to be used.