feat(Data): Add JSONRowFormatter #3602

This commit is contained in:
Alex Fabijanic
2022-05-22 12:41:34 -07:00
parent 78558f868d
commit ebeef47a8c
11 changed files with 439 additions and 16 deletions

View File

@@ -17,6 +17,7 @@
#include "Poco/Data/Statement.h"
#include "Poco/Data/RecordSet.h"
#include "Poco/Data/RowFormatter.h"
#include "Poco/Data/JSONRowFormatter.h"
#include "Poco/Data/SQLite/Connector.h"
#include <iostream>
@@ -27,6 +28,7 @@ using Poco::Data::Session;
using Poco::Data::Statement;
using Poco::Data::RecordSet;
using Poco::Data::RowFormatter;
using Poco::Data::JSONRowFormatter;
class HTMLTableFormatter : public RowFormatter
@@ -117,5 +119,11 @@ int main(int argc, char** argv)
std::cout << std::endl << "Simple formatting:" << std::endl << std::endl;
std::cout << RecordSet(session, "SELECT * FROM Simpsons");
// JSON formatting example (uses the JSONRowFormatter provided by framework)
std::cout << std::endl << "JSON formatting:" << std::endl << std::endl;
JSONRowFormatter jsonRowFormatter;
jsonRowFormatter.setJSONMode((RowFormatter::Mode)(JSONRowFormatter::JSON_FMT_MODE_ROW_COUNT | JSONRowFormatter::JSON_FMT_MODE_COLUMN_NAMES));
std::cout << RecordSet(session, "SELECT * FROM Simpsons", jsonRowFormatter);
return 0;
}