Qore CsvUtil Module Reference  1.6.2
AbstractCsvWriter.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // Qore AbstractCsvWriter class definition
3 
4 /* AbstractCsvWriter.qc Copyright 2012 - 2018 Qore Technologies, s.r.o.
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // assume local var scope, do not use "$" for vars, members, and method calls
26 
28 namespace CsvUtil {
30 
139 class AbstractCsvWriter : protected CsvHelper {
140 
141 public:
142 protected:
144  const Options = (
145  "block": C_OPT1|C_OPT2,
146  "datamap": C_OPT1,
147  "date_format": C_OPT1|C_OPT2,
148  "date-format": C_OPT1|C_OPT2,
149  "encoding": C_OPT1|C_OPT2,
150  "eol": C_OPT1|C_OPT2,
151  "fields": C_OPT1,
152  "headers": C_OPT1,
153  "header_reorder": C_OPT1,
154  "info_log": C_OPT1|C_OPT2,
155  "number_format": C_OPT1|C_OPT2,
156  "optimal_quotes": C_OPT1|C_OPT2,
157  "optimal-quotes": C_OPT1|C_OPT2,
158  "quote": C_OPT1|C_OPT2,
159  "quote_escape": C_OPT1|C_OPT2,
160  "separator": C_OPT1|C_OPT2,
161  "verify_columns": C_OPT1|C_OPT2,
162  "verify-columns": C_OPT1|C_OPT2,
163  "write_headers": C_OPT1|C_OPT2,
164  "write-headers": C_OPT1|C_OPT2,
165  );
166 
168  string encoding;
169 
171  string separator = ",";
172 
174  string quote = "\"";
175 
177  string m_quoteEscapeChar = "\\";
178 
180  string eol = EOL_UNIX;
181 
184 
186  int lineNo = 0;
187 
189  int block = 1000;
190 
192  string baseTemplate;
193 
196 
199 
201  *code info_log;
202 
205 
208 
209 public:
210 
212 
218  constructor(string n_errname, *hash n_opts);
219 
220 
222 
230  constructor(string n_errname, hash spec, hash n_opts);
231 
232 
234 protected:
235  processCommonOptions(*hash n_opts, int C_OPTx);
236 public:
237 
238 
240 protected:
241  processSpec();
242 public:
243 
244 
246 protected:
247  writeHeaders();
248 public:
249 
250 
252 
257  writeLine(list values);
258 
259 
261 
266  writeLine(hash values);
267 
268 
270 
276  writeLine(string type, list values);
277 
278 
280 
286  writeLine(string type, hash values);
287 
288 
290 
297  write(Qore::AbstractIterator iterator);
298 
299 
301 
308  write(Qore::SQL::SQLStatement iterator);
309 
310 
312 
319  write(list l);
320 
321 
323 protected:
324  abstract writeRawLine(list values);
325 public:
326 
328 
333 protected:
334  string prepareRawLine(list values);
335 public:
336 
337 
338 protected:
339  string prepareRawLineIntern(list values);
340 public:
341 
342 
343  }; // AbstractCsvWriter class
344 }; // CsvUtil namespace
bool write_headers
this flag determines if any stored headers are output
Definition: AbstractCsvWriter.qc.dox.h:195
hash m_out_by_name
mapping output field by name
Definition: AbstractCsvWriter.qc.dox.h:204
processCommonOptions(*hash n_opts, int C_OPTx)
Process options and set internal variables.
writeHeaders()
Write csv headers.
const True
hash m_out_by_idx
mapping output field by index
Definition: AbstractCsvWriter.qc.dox.h:207
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
const False
string m_quoteEscapeChar
quote escape character
Definition: AbstractCsvWriter.qc.dox.h:177
*code info_log
a closure/call reference for informational logging when using write(SQLStatement) ...
Definition: AbstractCsvWriter.qc.dox.h:201
list list(...)
const Options
valid options for the object (a hash for quick lookups of valid keys)
Definition: AbstractCsvWriter.qc.dox.h:144
write(Qore::AbstractIterator iterator)
Stream an iterator into the output.
string eol
end of line sequence
Definition: AbstractCsvWriter.qc.dox.h:180
string separator
field separator
Definition: AbstractCsvWriter.qc.dox.h:171
string quote
field content delimiter
Definition: AbstractCsvWriter.qc.dox.h:174
processSpec()
Process specification and set internal variable for mapping.
The AbstractCsvWriter class provides a parent for all CSV writers.
Definition: AbstractCsvWriter.qc.dox.h:139
string baseTemplate
base template for value format
Definition: AbstractCsvWriter.qc.dox.h:192
const EOL_UNIX
Unix end of line character sequence (for new OS X too)
Definition: CsvUtil.qm.dox.h:308
constructor(string n_errname, *hash n_opts)
Creates the AbstractCsvWriter in single-type mode.
int lineNo
the latest line number
Definition: AbstractCsvWriter.qc.dox.h:186
string type(auto arg)
writeLine(list values)
Write a line with a list of values; data are checked against column rules.
string prepareRawLine(list values)
Prepare a string (line with EOF) with formatting and escaping.
int block
block size for bulk DML
Definition: AbstractCsvWriter.qc.dox.h:189
bool optimal_quotes
stores the optimal quotes option
Definition: AbstractCsvWriter.qc.dox.h:198
string encoding
output file character encoding
Definition: AbstractCsvWriter.qc.dox.h:168
the CsvUtil namespace. All classes used in the CsvUtil module should be inside this namespace ...
Definition: AbstractCsvIterator.qc.dox.h:28
hash hash(object obj)
abstract writeRawLine(list values)
This method must be overridden in child classes to provide the output implementation.