Qore CsvUtil Module Reference 1.2

- Main Page
- Related Pages
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Functions Variables Groups Pages
Public Member Functions | Private Attributes | List of all members
CsvUtil::AbstractCsvWriter Class Referenceabstract

the AbstractCsvWriter class provides a parent for all CSV writers More...

Inheritance diagram for CsvUtil::AbstractCsvWriter:
[legend]

## Public Member Functions
| constructor (string errname, *hash opts)
| creates the AbstractCsvWriter More...
private string | dateFormat (int ix)
| format date to string by options. Priority: 1) column definition 2) standard format
private string | prepareRawLine (list values)
| Prepare a string (line with EOF) with formatting and escaping. More...
| write (AbstractIterator iterator)
| stream iterator into the file. More...
| writeLine (list values)
| write a line with list of values. Data are checked against column rules. More...
| writeLine (hash values)
| write a line with headers-values hash More...
abstract private | writeRawLine (list values)
| real write implementation. Without any checking.

## Private Attributes
const | Options
| valid options for the object (a hash for quick lookups of valid keys)

## Additional Inherited Members
Private Member Functions inherited from CsvHelper
private | setFields ()
| sets field description list

## Detailed Description

the AbstractCsvWriter class provides a parent for all CSV writers

Any inherited class has to implement pure virtual (abstract) method, where should be the real physical write action placed.

private writeRawLine(list $values)

# AbstractCsvWriter Constructor Option Hash Overview

The AbstractCsvWriter class constructor takes an optional hash with possible keys given in the following table. Note that key names are case-sensitive, and data types are soft (conversions are made when possible).

AbstractCsvWriter Options

Option | Data Type | Description
`"encoding"` | String | the character encoding for the file (and for tagging string data read); if the value of this key is not a string then it will be ignored
`"separator"` | String | the string separating the fields in the file (default: `","`)
`"quote"` | String | the field quote character (default: `'"'`)
`"eol"` | String | the end of line character(s) (default: auto-detect); if the value of this key is not a string then it will be ignored
`"headers"` | List of strings | list of header / column names for the data iterated
`"verify-columns"` | Boolean | if True (the default is False) then if a line is parsed with a different column count than other lines, a `CSVFILEWRITER-DATA-ERROR` exception is thrown
`"date-format"` | String | the default mask for date values formatting
`"write-headers"` | bool | set to False to suppress the output of headers; the default is True, meaning to output headers if they are present
`"optimal-quotes"` | bool | set to False to disable optimal quoting; when optimal quoting is disabled, all fields are quoted regardless of type or content, when it is enabled, then fields are quoted only if they require quoting (i.e. they contain a quote or separator character); the default is True

## Member Function Documentation

CsvUtil::AbstractCsvWriter::constructor | ( | string | errname,
|  | *hash | opts
| ) |  |

creates the AbstractCsvWriter

Parameters

  errname | a string to construct child class error message. For example: value 'FOO' will result in exception names 'CSVFOOWRITER-ERROR'
  opts | AbstractCsvWriter Constructor Option Hash Overview

Exceptions

  CSV<errname>ITER-ERROR | in the case of incorrect options

private string CsvUtil::AbstractCsvWriter::prepareRawLine | ( | list | values | ) |

Prepare a string (line with EOF) with formatting and escaping.

Parameters

  values | a list with values

Returns
  string a formatted and escaped line with EOF

CsvUtil::AbstractCsvWriter::write | ( | AbstractIterator | iterator | ) |

stream iterator into the file.

Parameters

  iterator | an iterator to stream data into file

The iterator has to contain List or Hash as a return value of `getValue()` method.

Exceptions

  CSVFILEWRITER-DATA-ERROR | when the data does not fit defined column constraints or when `getValue` does not return list or hash

CsvUtil::AbstractCsvWriter::writeLine | ( | list | values | ) |

write a line with list of values. Data are checked against column rules.

Parameters

  values | a list with values

Exceptions

  CSVFILEWRITER-DATA-ERROR | when the data does not fit defined column constraints

CsvUtil::AbstractCsvWriter::writeLine | ( | hash | values | ) |

write a line with headers-values hash

Parameters

  values | a hash with keys as column headers.

Exceptions

  CSVFILEWRITER-DATA-ERROR | when the data does not fit defined column constraints