Move SQL query parsing into separate method