示例#1
0
文件: csvdiff.go 项目: gwenn/csvdiff
func writeRow(w *yacr.Writer, r row) {
	for _, field := range r {
		w.Write(field)
	}
	w.EndOfRecord()
	if err := w.Err(); err != nil {
		log.Fatalf("Error while writing diff: '%s'\n", err)
	}
}
示例#2
0
// ExportToCSV exports statement result to CSV.
// 'headers' flag turns output of headers on or off.
// NULL values are output as specified by 'nullvalue' parameter.
func (s *Stmt) ExportToCSV(nullvalue string, headers bool, w *yacr.Writer) error {
	if headers {
		for _, header := range s.ColumnNames() {
			w.Write([]byte(header))
		}
		w.EndOfRecord()
		if err := w.Err(); err != nil {
			return err
		}
	}
	s.Select(func(s *Stmt) error {
		for i := 0; i < s.ColumnCount(); i++ {
			rb, null := s.ScanRawBytes(i)
			if null {
				w.Write([]byte(nullvalue))
			} else {
				w.Write(rb)
			}
		}
		w.EndOfRecord()
		return w.Err()
	})
	w.Flush()
	return w.Err()
}