Qore CsvUtil Module Reference  1.7.2
CsvUtil::CsvFileWriter Class Reference

The CsvFileWriter class for safe CSV file creation. More...

Inheritance diagram for CsvUtil::CsvFileWriter:

Public Member Methods

 constructor (string path, *hash< auto > opts)
 creates the CsvFileWriter in single-type mode with the path of the file to create and an optional option hash More...
 
 constructor (string path, hash< auto > spec, hash< auto > opts)
 creates the CsvFileWriter in multi-type mode with the path of the file to create and an optional option hash More...
 
string getFileName ()
 returns the output file path More...
 
- Public Member Methods inherited from CsvUtil::AbstractCsvWriter
 constructor (string n_errname, *hash< auto > n_opts)
 Creates the AbstractCsvWriter in single-type mode. More...
 
 constructor (string n_errname, hash< auto > spec, hash< auto > n_opts)
 Creates the AbstractCsvWriter in single-type mode. More...
 
*hash< string, AbstractDataField > getRecordType ()
 Returns the description of the record type, if any.
 
 write (list< auto > l)
 Stream the contents of the list into the output. More...
 
 write (Qore::AbstractIterator iterator)
 Stream an iterator into the output. More...
 
 write (Qore::SQL::SQLStatement iterator)
 Stream an iterator into the output. More...
 
 writeLine (hash< auto > values)
 Write a line with headers-values hash. More...
 
 writeLine (list< auto > values)
 Write a line with a list of values; data are checked against column rules. More...
 
 writeLine (string type, hash< auto > values)
 Write a line for a specific record from a hash to the output. More...
 
 writeLine (string type, list< auto > values)
 Write a line with headers-values list. More...
 

Private Member Methods

 writeRawLine (list< auto > values)
 This method must be overridden in child classes to provide the output implementation.
 
- Private Member Methods inherited from CsvUtil::AbstractCsvWriter
string prepareRawLine (list< auto > values)
 Prepare a string (line with EOF) with formatting and escaping. More...
 
 processCommonOptions (*hash< auto > n_opts, int C_OPTx)
 Process options and set internal variables.
 
 processSpec ()
 Process specification and set internal variable for mapping.
 
 writeHeaders ()
 Write csv headers.
 

Private Attributes

Qore::File file
 the file to write
 
- Private Attributes inherited from CsvUtil::AbstractCsvWriter
string baseTemplate
 base template for value format
 
int block = 1000
 block size for bulk DML
 
bool checkElementCounts = False
 verify the column count for every row; if a row does not match, then throw a CSVFILEITERATOR-DATA-ERROR exception
 
string encoding
 output file character encoding
 
string eol = EOL_UNIX
 end of line sequence
 
*code info_log
 a closure/call reference for informational logging when using write(SQLStatement)
 
int lineNo = 0
 the latest line number
 
hash m_out_by_idx
 mapping output field by index
 
hash m_out_by_name
 mapping output field by name
 
string m_quoteEscapeChar = "\\"
 quote escape character
 
bool optimal_quotes = True
 stores the optimal quotes option
 
const Options = ...
 valid options for the object (a hash for quick lookups of valid keys)
 
string quote = "\""
 field content delimiter
 
string separator = ","
 field separator
 
bool write_headers = True
 this flag determines if any stored headers are output
 

Detailed Description

The CsvFileWriter class for safe CSV file creation.

See also
  • CsvWriter for a stream-based class providing the same functionality as this class in a more generic way

Member Function Documentation

◆ constructor() [1/2]

CsvUtil::CsvFileWriter::constructor ( string  path,
*hash< auto >  opts 
)

creates the CsvFileWriter in single-type mode with the path of the file to create and an optional option hash

Parameters
patha file name (with path optionally) to write
optsAbstractCsvWriter Constructor Option Hash Overview

The file is created with O_CREAT, O_TRUNC, O_WRONLY and 0644 access.

Exceptions
CSVFILEITER-ERRORin the case of incorrect options

◆ constructor() [2/2]

CsvUtil::CsvFileWriter::constructor ( string  path,
hash< auto >  spec,
hash< auto >  opts 
)

creates the CsvFileWriter in multi-type mode with the path of the file to create and an optional option hash

Parameters
patha file name (with path optionally) to write
speca hash of field and type definition; see Option Field Hash for more information
optsAbstractCsvWriter Constructor Option Hash Overview

The file is created with O_CREAT, O_TRUNC, O_WRONLY and 0644 access.

Exceptions
CSVFILEITER-ERRORin the case of incorrect options

◆ getFileName()

string CsvUtil::CsvFileWriter::getFileName ( )

returns the output file path

Returns
the output file path
Since
CsvUtil 1.7