Encapsulate sql query.