def Execute(self, query):
    """Executes the query and displays the results on screen."""
    csvh = None
    csv_match = _CSV_RE.match(query)
    if csv_match:
      csvh = csv.writer(sys.stdout)
      query = csv_match.group('query')

    self.ongoing_operation = self.dbh.Submit(query)
    results = self.dbh.Wait(self.ongoing_operation)
    for key, values in results.items():
      for value in values:
        results[key] = value
        # TODO(flamingcow): Handle multiple results here
        break
    self.ongoing_operation = None

    if csvh:
      if FLAGS.print_field_names:
        csvh.writerow(results.values()[0].GetFields())
      for result in results.itervalues():
        for row in result.GetRows():
          fields = []
          for field in row:
            if isinstance(field, unicode):
              fields.append(field.encode(FLAGS.charset))
            else:
              fields.append(field)
          csvh.writerow(fields)
      return
    by_result = {}
    result = None
    for name, result in results.iteritems():
      by_result.setdefault(result, []).append(name)
    if len(by_result) > 1:
      for result, names in by_result.iteritems():
        if not result:
          continue
        names.sort()
        print '%s:' % names
        _ShowTable(result)
    else:
      _ShowTable(result)
dataset/ETHPy150Open google/mysql-tools/sql.py/CancellableExecutor.Execute/original