Loading...
Searching...
No Matches
AbstractCsvWriter.qc.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// Qore AbstractCsvWriter class definition
/* AbstractCsvWriter.qc Copyright 2012 - 2022 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// assume local var scope, do not use "$" for vars, members, and method calls
namespace CsvUtil {
class AbstractCsvWriter : protected CsvHelper {
public:
protected:
const Options = {
"block": C_OPT1|C_OPT2,
"datamap": C_OPT1,
"date_format": C_OPT1|C_OPT2,
"date-format": C_OPT1|C_OPT2,
"encoding": C_OPT1|C_OPT2,
"eol": C_OPT1|C_OPT2,
"fields": C_OPT1,
"headers": C_OPT1,
"header_reorder": C_OPT1,
"info_log": C_OPT1|C_OPT2,
"number_format": C_OPT1|C_OPT2,
"optimal_quotes": C_OPT1|C_OPT2,
"optimal-quotes": C_OPT1|C_OPT2,
"quote": C_OPT1|C_OPT2,
"quote_escape": C_OPT1|C_OPT2,
"separator": C_OPT1|C_OPT2,
"verify_columns": C_OPT1|C_OPT2,
"verify-columns": C_OPT1|C_OPT2,
"write_headers": C_OPT1|C_OPT2,
"write-headers": C_OPT1|C_OPT2,
};
string encoding;
string separator = ",";
string quote = "\"";
string m_quoteEscapeChar = "\\";
string eol = EOL_UNIX;
bool checkElementCounts = False;
int lineNo = 0;
int block = 1000;
string baseTemplate;
bool write_headers = True;
bool optimal_quotes = True;
*code info_log;
hash m_out_by_name;
hash m_out_by_idx;
public:
constructor(string n_errname, *hash<auto> n_opts);
constructor(string n_errname, hash<auto> spec, hash<auto> n_opts);
*hash<string, AbstractDataField> getRecordType();
protected:
processCommonOptions(*hash<auto> n_opts, int C_OPTx);
public:
protected:
processSpec();
public:
protected:
writeHeaders();
public:
writeLine(list<auto> values);
writeLine(hash<auto> values);
writeLine(string type, list<auto> values);
writeLine(string type, hash<auto> values);
write(Qore::AbstractIterator iterator);
write(Qore::SQL::SQLStatement iterator);
write(list<auto> l);
protected:
abstract writeRawLine(list<auto> values);
public:
protected:
string prepareRawLine(list<auto> values);
public:
protected:
string prepareRawLineIntern(list<auto> values);
public:
}; // AbstractCsvWriter class
}; // CsvUtil namespace
CsvUtil::AbstractCsvWriter
The AbstractCsvWriter class provides a parent for all CSV writers.
Definition: AbstractCsvWriter.qc.dox.h:139
CsvUtil::AbstractCsvWriter::baseTemplate
string baseTemplate
base template for value format
Definition: AbstractCsvWriter.qc.dox.h:192
CsvUtil::AbstractCsvWriter::write
write(Qore::AbstractIterator iterator)
Stream an iterator into the output.
CsvUtil::AbstractCsvWriter::writeRawLine
abstract writeRawLine(list< auto > values)
This method must be overridden in child classes to provide the output implementation.
CsvUtil::AbstractCsvWriter::writeLine
writeLine(hash< auto > values)
Write a line with headers-values hash.
CsvUtil::AbstractCsvWriter::writeLine
writeLine(string type, hash< auto > values)
Write a line for a specific record from a hash to the output.
CsvUtil::AbstractCsvWriter::prepareRawLine
string prepareRawLine(list< auto > values)
Prepare a string (line with EOF) with formatting and escaping.
CsvUtil::AbstractCsvWriter::constructor
constructor(string n_errname, hash< auto > spec, hash< auto > n_opts)
Creates the AbstractCsvWriter in single-type mode.
CsvUtil::AbstractCsvWriter::write
write(list< auto > l)
Stream the contents of the list into the output.
CsvUtil::AbstractCsvWriter::write
write(Qore::SQL::SQLStatement iterator)
Stream an iterator into the output.
CsvUtil::AbstractCsvWriter::block
int block
block size for bulk DML
Definition: AbstractCsvWriter.qc.dox.h:189
CsvUtil::AbstractCsvWriter::getRecordType
*hash< string, AbstractDataField > getRecordType()
Returns the description of the record type, if any.
CsvUtil::AbstractCsvWriter::encoding
string encoding
output file character encoding
Definition: AbstractCsvWriter.qc.dox.h:168
CsvUtil::AbstractCsvWriter::m_out_by_name
hash m_out_by_name
mapping output field by name
Definition: AbstractCsvWriter.qc.dox.h:204
CsvUtil::AbstractCsvWriter::quote
string quote
field content delimiter
Definition: AbstractCsvWriter.qc.dox.h:174
CsvUtil::AbstractCsvWriter::eol
string eol
end of line sequence
Definition: AbstractCsvWriter.qc.dox.h:180
CsvUtil::AbstractCsvWriter::writeHeaders
writeHeaders()
Write csv headers.
CsvUtil::AbstractCsvWriter::write_headers
bool write_headers
this flag determines if any stored headers are output
Definition: AbstractCsvWriter.qc.dox.h:195
CsvUtil::AbstractCsvWriter::info_log
*code info_log
a closure/call reference for informational logging when using write(SQLStatement)
Definition: AbstractCsvWriter.qc.dox.h:201
CsvUtil::AbstractCsvWriter::optimal_quotes
bool optimal_quotes
stores the optimal quotes option
Definition: AbstractCsvWriter.qc.dox.h:198
CsvUtil::AbstractCsvWriter::m_quoteEscapeChar
string m_quoteEscapeChar
quote escape character
Definition: AbstractCsvWriter.qc.dox.h:177
CsvUtil::AbstractCsvWriter::Options
const Options
valid options for the object (a hash for quick lookups of valid keys)
Definition: AbstractCsvWriter.qc.dox.h:144
CsvUtil::AbstractCsvWriter::checkElementCounts
bool checkElementCounts
verify the column count for every row; if a row does not match, then throw a CSVFILEITERATOR-DATA-ERR...
Definition: AbstractCsvWriter.qc.dox.h:183
CsvUtil::AbstractCsvWriter::separator
string separator
field separator
Definition: AbstractCsvWriter.qc.dox.h:171
CsvUtil::AbstractCsvWriter::lineNo
int lineNo
the latest line number
Definition: AbstractCsvWriter.qc.dox.h:186
CsvUtil::AbstractCsvWriter::constructor
constructor(string n_errname, *hash< auto > n_opts)
Creates the AbstractCsvWriter in single-type mode.
CsvUtil::AbstractCsvWriter::m_out_by_idx
hash m_out_by_idx
mapping output field by index
Definition: AbstractCsvWriter.qc.dox.h:207
CsvUtil::AbstractCsvWriter::writeLine
writeLine(string type, list< auto > values)
Write a line with headers-values list.
CsvUtil::AbstractCsvWriter::writeLine
writeLine(list< auto > values)
Write a line with a list of values; data are checked against column rules.
CsvUtil::AbstractCsvWriter::processCommonOptions
processCommonOptions(*hash< auto > n_opts, int C_OPTx)
Process options and set internal variables.
CsvUtil::AbstractCsvWriter::processSpec
processSpec()
Process specification and set internal variable for mapping.
Qore::AbstractIterator
Qore::SQL::SQLStatement
CsvUtil
the CsvUtil namespace. All classes used in the CsvUtil module should be inside this namespace
Definition: AbstractCsvIterator.qc.dox.h:28
CsvUtil::EOL_UNIX
const EOL_UNIX
Unix end of line character sequence (for new OS X too)
Definition: CsvUtil.qm.dox.h:337