Skip to content

Commit edafbf9

Browse files
committed
clang build
1 parent 07a2529 commit edafbf9

6 files changed

Lines changed: 64 additions & 11 deletions

File tree

‎Data/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include $(POCO_BASE)/build/rules/global
1010

1111
objects = AbstractBinder AbstractBinding AbstractExtraction AbstractExtractor \
1212
AbstractPreparation AbstractPreparator ArchiveStrategy Transaction \
13-
Bulk Connector DataException Date DynamicLOB Limit JSONFormatter \
13+
Bulk Connector DataException Date DynamicLOB Limit JSONRowFormatter \
1414
MetaColumn PooledSessionHolder PooledSessionImpl Position \
1515
Range RecordSet Row RowFilter RowFormatter RowIterator \
1616
SimpleRowFormatter Session SessionFactory SessionImpl \

‎Data/include/Poco/Data/JSONRowFormatter.h‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,51 @@ namespace Data {
2929

3030
class Data_API JSONRowFormatter: public Poco::Data::RowFormatter
3131
/// Class for JSON formatting of data rows.
32+
///
33+
/// Formatter can be configured to operate in four modes (and
34+
/// certain combinations thereof) :
35+
///
36+
/// - small (condensed mode, only array of values)
37+
///
38+
/// Example:
39+
/// {
40+
/// [["Simpson", "Bart", "Springfield", 12],
41+
/// ["Simpson", "Lisa", "Springfield", 10]]
42+
/// }
43+
///
44+
/// - row count (total row count provided)
45+
///
46+
/// Example:
47+
/// {
48+
/// "count":2,
49+
/// [["Simpson", "Bart", "Springfield", 12],
50+
/// ["Simpson", "Lisa", "Springfield", 10]]
51+
/// }
52+
///
53+
/// - column names (column names provided as a string array)
54+
///
55+
/// Example:
56+
/// {
57+
/// "names":["LastName", "FirstName", "Address", "Age"],
58+
/// [["Simpson", "Bart", "Springfield", 12],
59+
/// ["Simpson", "Lisa", "Springfield", 10]]
60+
/// }
61+
///
62+
/// - full (total row count, column names provided in every row of data)
63+
///
64+
/// Example:
65+
/// {
66+
/// "count":2,
67+
/// [
68+
/// {"LastName": "Simpson", "FirstName": "Bart", "Address": "Springfield", "Age": 12},
69+
/// {"LastName": "Simpson", "FirstName": "Lisa", "Address": "Springfield", "Age": 10}
70+
/// ]
71+
/// }
72+
///
73+
/// Total row count will be specified by the Poco::DataRecordSet. Note, however, that this is
74+
/// not possible to do accurately in case of result set paging. For those cases, there is
75+
/// setTotalRowCount() member function, which allows to explicitly set the total row count.
76+
/// If the total row count is preset on the formatter, the Data framework shall not interfere.
3277
{
3378
public:
3479
static const int JSON_FMT_MODE_SMALL = 1;

‎Data/include/Poco/Data/SimpleRowFormatter.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ class Data_API SimpleRowFormatter: public RowFormatter
3232
/// A simple row formatting class.
3333
{
3434
public:
35-
//typedef RowFormatter::NameVec NameVec;
36-
//typedef RowFormatter::NameVecPtr NameVecPtr;
37-
//typedef RowFormatter::ValueVec ValueVec;
3835

3936
static const int DEFAULT_COLUMN_WIDTH = 16;
4037
static const int DEFAULT_SPACING = 1;

‎Data/src/JSONRowFormatter.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ namespace Poco {
2929
namespace Data {
3030

3131

32+
const int JSONRowFormatter::JSON_FMT_MODE_SMALL;
33+
const int JSONRowFormatter::JSON_FMT_MODE_ROW_COUNT;
34+
const int JSONRowFormatter::JSON_FMT_MODE_COLUMN_NAMES;
35+
const int JSONRowFormatter::JSON_FMT_MODE_FULL;
36+
37+
3238
JSONRowFormatter::JSONRowFormatter(int mode) : RowFormatter("{", "]}"),
3339
_firstTime(true)
3440
{

‎Data/src/RecordSet.cpp‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,18 @@ bool RecordSet::moveLast()
301301

302302
void RecordSet::setRowFormatter(RowFormatter::Ptr pRowFormatter)
303303
{
304-
pRowFormatter->setTotalRowCount(static_cast<int>(getTotalRowCount()));
305-
Statement::setRowFormatter(pRowFormatter);
306-
RowMap::iterator it = _rowMap.begin();
307-
RowMap::iterator end = _rowMap.end();
308-
for (; it != end; ++it) it->second->setFormatter(getRowFormatter());
304+
if (pRowFormatter)
305+
{
306+
if (pRowFormatter->getTotalRowCount() == RowFormatter::INVALID_ROW_COUNT)
307+
pRowFormatter->setTotalRowCount(static_cast<int>(getTotalRowCount()));
308+
309+
Statement::setRowFormatter(pRowFormatter);
310+
RowMap::iterator it = _rowMap.begin();
311+
RowMap::iterator end = _rowMap.end();
312+
for (; it != end; ++it) it->second->setFormatter(getRowFormatter());
313+
}
314+
else
315+
throw NullPointerException("Null RowFormatter in RecordSet.");
309316
}
310317

311318

‎Data/testsuite/src/DataTest.cpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,15 +1232,13 @@ void DataTest::testJSONRowFormatter()
12321232
row1.setFormatter(new JSONRowFormatter(JSONRowFormatter::JSON_FMT_MODE_SMALL));
12331233
assert(row1.getFormatter().getMode() == RowFormatter::FORMAT_PROGRESSIVE);
12341234
assert(row1.namesToString() == "");
1235-
//std::cout << row1.valuesToString() << std::endl;
12361235
assert(row1.valuesToString() == "[[0,\"1\",\"2007-03-13T08:12:15Z\",null,4]");
12371236
assert(row1.valuesToString() == ",[0,\"1\",\"2007-03-13T08:12:15Z\",null,4]");
12381237

12391238
row1.setFormatter(new JSONRowFormatter(JSONRowFormatter::JSON_FMT_MODE_FULL));
12401239
assert(row1.getFormatter().prefix() == "{\"count\":0,[");
12411240
assert(row1.getFormatter().postfix() == "]}");
12421241
assert(row1.getFormatter().getMode() == RowFormatter::FORMAT_PROGRESSIVE);
1243-
std::cout << row1.namesToString() << std::endl;
12441242
assert(row1.namesToString() == "");
12451243
assert(row1.valuesToString() == "{\"field0\":0,\"field1\":\"1\",\"field2\":\"2007-03-13T08:12:15Z\",\"field3\":null,\"field4\":4}");
12461244
assert(row1.valuesToString() == ",{\"field0\":0,\"field1\":\"1\",\"field2\":\"2007-03-13T08:12:15Z\",\"field3\":null,\"field4\":4}");

0 commit comments

Comments
 (0)