Skip to content

Commit

Permalink
clang build
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-f committed Feb 13, 2015
1 parent 07a2529 commit edafbf9
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Data/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include $(POCO_BASE)/build/rules/global

objects = AbstractBinder AbstractBinding AbstractExtraction AbstractExtractor \
AbstractPreparation AbstractPreparator ArchiveStrategy Transaction \
Bulk Connector DataException Date DynamicLOB Limit JSONFormatter \
Bulk Connector DataException Date DynamicLOB Limit JSONRowFormatter \
MetaColumn PooledSessionHolder PooledSessionImpl Position \
Range RecordSet Row RowFilter RowFormatter RowIterator \
SimpleRowFormatter Session SessionFactory SessionImpl \
Expand Down
45 changes: 45 additions & 0 deletions Data/include/Poco/Data/JSONRowFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,51 @@ namespace Data {

class Data_API JSONRowFormatter: public Poco::Data::RowFormatter
/// Class for JSON formatting of data rows.
///
/// Formatter can be configured to operate in four modes (and
/// certain combinations thereof) :
///
/// - small (condensed mode, only array of values)
///
/// Example:
/// {
/// [["Simpson", "Bart", "Springfield", 12],
/// ["Simpson", "Lisa", "Springfield", 10]]
/// }
///
/// - row count (total row count provided)
///
/// Example:
/// {
/// "count":2,
/// [["Simpson", "Bart", "Springfield", 12],
/// ["Simpson", "Lisa", "Springfield", 10]]
/// }
///
/// - column names (column names provided as a string array)
///
/// Example:
/// {
/// "names":["LastName", "FirstName", "Address", "Age"],
/// [["Simpson", "Bart", "Springfield", 12],
/// ["Simpson", "Lisa", "Springfield", 10]]
/// }
///
/// - full (total row count, column names provided in every row of data)
///
/// Example:
/// {
/// "count":2,
/// [
/// {"LastName": "Simpson", "FirstName": "Bart", "Address": "Springfield", "Age": 12},
/// {"LastName": "Simpson", "FirstName": "Lisa", "Address": "Springfield", "Age": 10}
/// ]
/// }
///
/// Total row count will be specified by the Poco::DataRecordSet. Note, however, that this is
/// not possible to do accurately in case of result set paging. For those cases, there is
/// setTotalRowCount() member function, which allows to explicitly set the total row count.
/// If the total row count is preset on the formatter, the Data framework shall not interfere.
{
public:
static const int JSON_FMT_MODE_SMALL = 1;
Expand Down
3 changes: 0 additions & 3 deletions Data/include/Poco/Data/SimpleRowFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class Data_API SimpleRowFormatter: public RowFormatter
/// A simple row formatting class.
{
public:
//typedef RowFormatter::NameVec NameVec;
//typedef RowFormatter::NameVecPtr NameVecPtr;
//typedef RowFormatter::ValueVec ValueVec;

static const int DEFAULT_COLUMN_WIDTH = 16;
static const int DEFAULT_SPACING = 1;
Expand Down
6 changes: 6 additions & 0 deletions Data/src/JSONRowFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ namespace Poco {
namespace Data {


const int JSONRowFormatter::JSON_FMT_MODE_SMALL;
const int JSONRowFormatter::JSON_FMT_MODE_ROW_COUNT;
const int JSONRowFormatter::JSON_FMT_MODE_COLUMN_NAMES;
const int JSONRowFormatter::JSON_FMT_MODE_FULL;


JSONRowFormatter::JSONRowFormatter(int mode) : RowFormatter("{", "]}"),
_firstTime(true)
{
Expand Down
17 changes: 12 additions & 5 deletions Data/src/RecordSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,18 @@ bool RecordSet::moveLast()

void RecordSet::setRowFormatter(RowFormatter::Ptr pRowFormatter)
{
pRowFormatter->setTotalRowCount(static_cast<int>(getTotalRowCount()));
Statement::setRowFormatter(pRowFormatter);
RowMap::iterator it = _rowMap.begin();
RowMap::iterator end = _rowMap.end();
for (; it != end; ++it) it->second->setFormatter(getRowFormatter());
if (pRowFormatter)
{
if (pRowFormatter->getTotalRowCount() == RowFormatter::INVALID_ROW_COUNT)
pRowFormatter->setTotalRowCount(static_cast<int>(getTotalRowCount()));

Statement::setRowFormatter(pRowFormatter);
RowMap::iterator it = _rowMap.begin();
RowMap::iterator end = _rowMap.end();
for (; it != end; ++it) it->second->setFormatter(getRowFormatter());
}
else
throw NullPointerException("Null RowFormatter in RecordSet.");
}


Expand Down
2 changes: 0 additions & 2 deletions Data/testsuite/src/DataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,15 +1232,13 @@ void DataTest::testJSONRowFormatter()
row1.setFormatter(new JSONRowFormatter(JSONRowFormatter::JSON_FMT_MODE_SMALL));
assert(row1.getFormatter().getMode() == RowFormatter::FORMAT_PROGRESSIVE);
assert(row1.namesToString() == "");
//std::cout << row1.valuesToString() << std::endl;
assert(row1.valuesToString() == "[[0,\"1\",\"2007-03-13T08:12:15Z\",null,4]");
assert(row1.valuesToString() == ",[0,\"1\",\"2007-03-13T08:12:15Z\",null,4]");

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

0 comments on commit edafbf9

Please sign in to comment.