Escape queries correctly