docstr: Check context variables in query and replace them with values.
  Should be used before exec query in database.
  
  Input:
  - query: input query
  - params are used to find current values of context variables
    - dn: datanode
    - session: mindsdb server session
  
  Returns:
   - query with replaced context variables
   - callback to call with result of the query. it is used to update context variables
docstr_tok: ["Check","context","variables","in","query","and","replace","them","with","values",".","Should","be","used","before","exec","query","in","database",".","Input",":","-","query",":","input","query","-","params","are","used","to","find","current","values","of","context","variables","-","dn",":","datanode","-","session",":","mindsdb","server","session","Returns",":","-","query","with","replaced","context","variables","-","callback","to","call","with","result","of","the","query",".","it","is","used","to","update","context","variables"]
code: def handle_db_context_vars(
      self, query: ASTNode, dn, session
  ) -> tuple:
      """
      Check context variables in query and replace them with values.
      Should be used before exec query in database.
  
      Input:
      - query: input query
      - params are used to find current values of context variables
        - dn: datanode
        - session: mindsdb server session
  
      Returns:
       - query with replaced context variables
       - callback to call with result of the query. it is used to update context variables
  
      """
      context_name = self.get_current_context()
  
      l_query = LastQuery(query)
      if l_query.query is None:
          # no last keyword, exit
          return query, None
  
      if context_name == self.IGNORE_CONTEXT:
          # return with empty constants
          return l_query.query, None
  
      query_str = l_query.to_string()
  
      rec = self.__get_context_record(context_name, query_str)
  
      if rec is None or len(rec.values) == 0:
          values = self.__get_init_last_values(l_query, dn, session)
          if rec is None:
              self.__add_context_record(context_name, query_str, values)
          else:
              rec.values = values
      else:
          values = rec.values
  
      db.session.commit()
  
      query_out = l_query.apply_values(values)
  
      def callback(data, columns_info):
          self._result_callback(
              l_query, context_name, query_str, data, columns_info
          )
  
      return query_out, callback
  
imports: from typing import List
  import pandas
  from mindsdb_sql.parser.ast import Identifier, BinaryOperation, Last, Constant, ASTNode
  from mindsdb_sql.planner.utils import query_traversal
  from mindsdb.interfaces.storage import db
  from mindsdb.utilities.context import context
  from .last_query import LastQuery
label_desc: Use image node_id 1 for calling the QueryContextController obj's underlying member method code with example usage: obj.handle_db_context_vars(query, dn, session) and returns: query_out,  callback, query,  None, l_query,  None