Add function to validate SQL query