docs: def _csv(self, cursor, fieldnames, output_fh):
          """Writes the rows of `cursor` in CSV format to `output_fh`
          and returns it.
  
          :param cursor: database cursor containing data to be output
          :type cursor: `sqlite3.Cursor`
          :param fieldnames: row headings
          :type fieldnames: `list`
          :param output_fh: file to write data to
          :type output_fh: file object
          :rtype: file object
  
          """
          self._logger.info('Finished query; outputting results in CSV format')
          # Specify a lineterminator to avoid an extra \r being added on
          # Windows; see
          # https://stackoverflow.com/questions/3191528/csv-in-python-adding-extra-carriage-return
          if sys.platform in ('win32', 'cygwin') and output_fh is sys.stdout:
              writer = csv.writer(output_fh, lineterminator='\n')
          else:
              writer = csv.writer(output_fh)
          writer.writerow(fieldnames)
          for row in cursor:
              writer.writerow(row)
          self._logger.info('Finished outputting results')
          return output_fh