284 const FieldAttrs = (
"type",
"format",
"timezone",
"code",
"header");
299 bool headerReorder =
True;
305 constructor (
string n_errname);
309 private bool isMultiType();
313 private checkType(
string fld_errs,
string key,
string value);
317 private hash getSpec(*
hash fields,
string fld_errs,
int C_OPTx);
320 private hash getSpec1(*
hash fields);
330 private list adjustFieldsFromHeaders(
string type, *
list headers);
598 "date_format": C_OPT1|C_OPT2,
599 "date-format": C_OPT1|C_OPT2,
600 "encoding": C_OPT1|C_OPT2,
601 "eol": C_OPT1|C_OPT2,
602 "extended_record": C_OPT2,
604 "header-lines": C_OPT1|C_OPT2,
605 "header_lines": C_OPT1|C_OPT2,
606 "header-names": C_OPT1|C_OPT2,
607 "header_names": C_OPT1|C_OPT2,
608 "header_reorder": C_OPT1|C_OPT2,
610 "ignore-empty": C_OPT1|C_OPT2,
611 "ignore_empty": C_OPT1|C_OPT2,
612 "ignore-whitespace": C_OPT1|C_OPT2,
613 "ignore_whitespace": C_OPT1|C_OPT2,
614 "quote": C_OPT1|C_OPT2,
615 "separator": C_OPT1|C_OPT2,
616 "timezone": C_OPT1|C_OPT2,
617 "tolwr": C_OPT1|C_OPT2,
618 "verify-columns": C_OPT1|C_OPT2,
619 "verify_columns": C_OPT1|C_OPT2,
623 string separator =
",";
629 softint headerLines = 0;
632 bool headerNames =
False;
635 bool ignoreEmptyLines =
True;
638 bool ignoreWhitespace =
True;
644 bool checkElementCounts =
False;
647 bool extendedRecord =
False;
656 hash m_resolve_by_rule;
659 hash m_resolve_by_count;
662 hash m_resolve_by_idx;
665 bool fakeHeaderNames;
871 private any handleType(
hash fh, *
string val);
930 any memberGate(
string name);
977 any memberGate(
string name);
1109 "block": C_OPT1|C_OPT2,
1111 "date_format": C_OPT1|C_OPT2,
1112 "date-format": C_OPT1|C_OPT2,
1113 "encoding": C_OPT1|C_OPT2,
1114 "eol": C_OPT1|C_OPT2,
1117 "header_reorder": C_OPT1,
1118 "info_log": C_OPT1|C_OPT2,
1119 "optimal_quotes": C_OPT1|C_OPT2,
1120 "optimal-quotes": C_OPT1|C_OPT2,
1121 "quote": C_OPT1|C_OPT2,
1122 "quote_escape": C_OPT1|C_OPT2,
1123 "separator": C_OPT1|C_OPT2,
1124 "verify_columns": C_OPT1|C_OPT2,
1125 "verify-columns": C_OPT1|C_OPT2,
1126 "write_headers": C_OPT1|C_OPT2,
1127 "write-headers": C_OPT1|C_OPT2,
1328 private openFile(
string path);
1366 private initContent();
private writeRawLine(list values)
This method must be overridden in child classes to provide the output implementation.
bool write_headers
this flag determines if any stored headers are output
Definition: CsvUtil.qm.dox.h:1158
constructor(string data, *hash opts)
Creates the CsvDataIterator with the input data and optionally an option hash.
hash m_out_by_name
mapping output field by name
Definition: CsvUtil.qm.dox.h:1167
constructor(*hash opts)
creates the CsvStringWriter single-type mode with content in the memory
private string prepareRawLine(list values)
Prepare a string (line with EOF) with formatting and escaping.
int index()
Returns the row index being iterated, which does not necessarily correspond to the line number when t...
string write(Qore::AbstractIterator iterator)
Stream iterator and return a CSV-formatted output string.
the AbstractCsvIterator class is an abstract base class that allows abstract CSV data to be iterated ...
Definition: CsvUtil.qm.dox.h:592
private *string getDataName()
Returns the name of the input data.
private bool nextLineImpl()
Moves the current line / record position to the next line / record; returns False if there are no mor...
const Options
valid options for the object (a hash for quick lookups of valid keys)
Definition: CsvUtil.qm.dox.h:597
hash m_out_by_idx
mapping output field by index
Definition: CsvUtil.qm.dox.h:1170
private processCommonOptions(*hash opts, int C_OPTx)
process common options and and assing internal fields
string getQuote()
Returns the current quote string.
private processSpec()
Process specification and set internal variable for mapping.
abstract private int lineNumberImpl()
Returns the current line number.
private writeRawLine(list values)
This method must be overridden in child classes to provide the output implementation.
bool checkElementCounts
verify the column count for every row; if a row does not match, then throw a CSVFILEITERATOR-DATA-ERR...
Definition: CsvUtil.qm.dox.h:1146
private int lineNumberImpl()
Returns the current line number.
constructor(string path, *hash opts)
Creates the CsvFileIterator in single-type mode with the path of the file to read and an option hash...
private hash parseLine()
Parses a line in the file and returns a processed list of the fields.
private list getLineAndSplit()
Read line split by separator/quote into list.
string m_quoteEscapeChar
quote escape character
Definition: CsvUtil.qm.dox.h:1140
private *string getDataName()
Returns the name of the input data.
*code info_log
a closure/call reference for informational logging when using write(SQLStatement) ...
Definition: CsvUtil.qm.dox.h:1164
const Options
valid options for the object (a hash for quick lookups of valid keys)
Definition: CsvUtil.qm.dox.h:1108
write(Qore::AbstractIterator iterator)
Stream an iterator into the output.
The CsvFileIterator class allows CSV files to be iterated on a record basis.
Definition: CsvUtil.qm.dox.h:911
string getContent()
Get the current in-memory content as a string.
string eol
end of line sequence
Definition: CsvUtil.qm.dox.h:1143
string getSeparator()
Returns the current separator string.
any getRecordList()
Returns the current record as a list.
private processCommonOptions(*hash n_opts, int C_OPTx)
Process options and set internal variables.
The CsvStringWriter class for in-memory string CSV creation.
Definition: CsvUtil.qm.dox.h:1337
string separator
field separator
Definition: CsvUtil.qm.dox.h:1134
string quote
field content delimiter
Definition: CsvUtil.qm.dox.h:1137
any memberGate(string name)
Returns the given column value for the current row.
The AbstractCsvWriter class provides a parent for all CSV writers.
Definition: CsvUtil.qm.dox.h:1103
private processSpec(hash spec)
process specification and assing internal data for resolving
private writeHeaders()
Write csv headers.
string baseTemplate
base template for value format
Definition: CsvUtil.qm.dox.h:1155
const EOL_MACINTOSH
Old (pre-OSX) Macintosh end of line character sequence.
Definition: CsvUtil.qm.dox.h:342
const CSV_TYPE_UNKNOWN
Record type when non matching any type.
Definition: CsvUtil.qm.dox.h:348
abstract private string getLineValueImpl()
Returns the current line.
private bool nextLineImpl()
Moves the current line / record position to the next line / record; returns False if there are no mor...
const EOL_UNIX
Unix end of line character sequence (for new OS X too)
Definition: CsvUtil.qm.dox.h:338
*list getHeaders()
Returns the current record headers or NOTHING if no headers have been detected or saved yet...
private *string identifyTypeImpl(list rec)
Identify a input record, given the raw line string. This method performs a lookup to a precalculated ...
constructor(string n_errname, *hash n_opts)
Creates the AbstractCsvWriter in single-type mode.
private prepareFieldsFromHeaders(*list headers)
match headers provided at Csv header or in options, never called for multi-type because header_names ...
private int lineNumberImpl()
Returns the current line number; returns 0 if not pointing at any data.
int lineNo
the latest line number
Definition: CsvUtil.qm.dox.h:1149
writeLine(list values)
Write a line with a list of values; data are checked against column rules.
hash getValue()
Returns the current record as a hash.
private string getLineValueImpl()
Returns the current line trimmed of the EOL character(s)
const EOL_WIN
MS DOS/Windows end of line character sequence.
Definition: CsvUtil.qm.dox.h:340
constructor(*hash opts)
creates the AbstractCsvIterator with an option hash in single-type mode
The CsvDataIterator class allows arbitrary CSV string data to be iterated on a record basis...
Definition: CsvUtil.qm.dox.h:956
constructor(string path, *hash opts)
creates the CsvFileWriter in single-type mode with the path of the file to read and an optional optio...
int block
block size for bulk DML
Definition: CsvUtil.qm.dox.h:1152
string identifyType(list rec)
Identify a fixed-length line type using identifyTypeImpl(); may be overridden if necessary.
bool optimal_quotes
stores the optimal quotes option
Definition: CsvUtil.qm.dox.h:1161
string encoding
output file character encoding
Definition: CsvUtil.qm.dox.h:1131
abstract private bool nextLineImpl()
Moves the current line / record position to the next line / record; returns False if there are no mor...
The CsvFileWriter class for safe CSV file creation.
Definition: CsvUtil.qm.dox.h:1293
private string getLineValueImpl()
Returns the current line trimmed of the EOL character(s)
abstract private writeRawLine(list values)
This method must be overridden in child classes to provide the output implementation.
bool next()
Moves the current line / record position to the next line / record; returns False if there are no mor...
const CSV_TYPE_SINGLE
Record type when multi-type is disabled.
Definition: CsvUtil.qm.dox.h:350
hash getRecord()
Returns the current record as a hash.
int lineNumber()
Returns the current iterator line number in the file (the first line is line 1) or 0 if not pointing ...