am-c-p-p commented on a change in pull request #656: MINIFI-1013 Used soci 
library.
URL: https://github.com/apache/nifi-minifi-cpp/pull/656#discussion_r331722975
 
 

 ##########
 File path: extensions/sql/data/JSONSQLWriter.cpp
 ##########
 @@ -0,0 +1,99 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JSONSQLWriter.h"
+#include "rapidjson/writer.h"
+#include "rapidjson/stringbuffer.h"
+#include "rapidjson/prettywriter.h"
+#include "Exception.h"
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace sql {
+
+JSONSQLWriter::JSONSQLWriter(const soci::rowset<soci::row> &rowset, 
std::ostream *out)
+    : SQLWriter(rowset), json_payload(rapidjson::kArrayType), 
output_stream(out){
+}
+
+JSONSQLWriter::~JSONSQLWriter() {
+}
+
+bool JSONSQLWriter::addRow(const soci::row &row) {
+  rapidjson::Document::AllocatorType &alloc = json_payload.GetAllocator();
+  rapidjson::Value rowobj(rapidjson::kObjectType);
+  for (std::size_t i = 0; i != row.size(); ++i) {
+    const soci::column_properties & props = row.get_properties(i);
+
+    rapidjson::Value name;
+    name.SetString(props.get_name().c_str(), props.get_name().length(), alloc);
+
+    rapidjson::Value valueVal;
+    switch (const auto dataType = props.get_data_type()) {
+      case soci::data_type::dt_string: {
+        std::string str = std::string(row.get<std::string>(i));
+        valueVal.SetString(str.c_str(), str.length(), alloc);
+      }
+      break;
+      case soci::data_type::dt_double:
+        valueVal.SetDouble(row.get<double>(i));
+      break;
+      case soci::data_type::dt_integer:
+        valueVal.SetInt(row.get<int>(i));
+      break;
+      case soci::data_type::dt_long_long: {
+        int64_t i64val = row.get<long long>(i);
+        valueVal.SetInt64(i64val);
+      }
+      break;
+      case soci::data_type::dt_unsigned_long_long: {
+        uint64_t u64val = row.get<unsigned long long>(i);
+        valueVal.SetUint64(u64val);
+      }
+      break;
+      case soci::data_type::dt_date: {
+        std::tm when = row.get<std::tm>(i);
+        std::string str = std::string(asctime(&when));
 
 Review comment:
   Yes, strange, fixed it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to