Implement QUERY and LOCK