szaszm commented on a change in pull request #1073: URL: https://github.com/apache/nifi-minifi-cpp/pull/1073#discussion_r668063753
########## File path: libminifi/test/sql-tests/mocks/MockODBCService.h ########## @@ -0,0 +1,66 @@ +/** + * + * 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. + */ + +#pragma once + +#include <memory> +#include <string> + +#include "MockConnectors.h" +#include "services/DatabaseService.h" +#include "core/Resource.h" +#include "data/DatabaseConnectors.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { +namespace controllers { + +class MockODBCService : public DatabaseService { + public: + explicit MockODBCService(const std::string &name, utils::Identifier uuid = utils::Identifier()) + : DatabaseService(name, uuid), + logger_(logging::LoggerFactory<MockODBCService>::getLogger()) { + initialize(); + } + + explicit MockODBCService(const std::string &name, const std::shared_ptr<Configure> &configuration) + : DatabaseService(name), + logger_(logging::LoggerFactory<MockODBCService>::getLogger()) { + setConfiguration(configuration); + initialize(); + } + + std::unique_ptr<sql::Connection> getConnection() const { + return std::unique_ptr<sql::Connection>(new MockODBCConnection(connection_string_)); Review comment: You can use utils::make_unique here, there an implicit converting move constructor from `std::unique_ptr<Derived>&&` to `std::unique_ptr<Base>` ########## File path: extensions/sql/data/SociConnectors.cpp ########## @@ -0,0 +1,181 @@ +/** + * + * 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 "SociConnectors.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace sql { + +void SociRow::setIterator(const soci::rowset<soci::row>::iterator& iter) { + current_ = iter; +} + +soci::rowset<soci::row>::iterator SociRow::getIterator() const { + return current_; +} + +void SociRow::next() { + ++current_; +} + +std::size_t SociRow::size() const { + return current_->size(); +} + +std::string SociRow::getColumnName(std::size_t index) const { + return current_->get_properties(index).get_name(); +} + +bool SociRow::isNull(std::size_t index) const { + return current_->get_indicator(index) == soci::i_null; +} + +DataType SociRow::getDataType(std::size_t index) const { + switch (const auto dataType = current_->get_properties(index).get_data_type()) { + case soci::data_type::dt_string: { + return DataType::STRING; + } + case soci::data_type::dt_double: { + return DataType::DOUBLE; + } + case soci::data_type::dt_integer: { + return DataType::INTEGER; + } + case soci::data_type::dt_long_long: { + return DataType::LONG_LONG; + } + case soci::data_type::dt_unsigned_long_long: { + return DataType::UNSIGNED_LONG_LONG; + } + case soci::data_type::dt_date: { + return DataType::DATE; + } + default: { + throw minifi::Exception(PROCESSOR_EXCEPTION, "SQLRowsetProcessor: Unsupported data type " + std::to_string(dataType)); + } + } +} + +std::string SociRow::getString(std::size_t index) const { + return current_->get<std::string>(index); +} + +double SociRow::getDouble(std::size_t index) const { + return current_->get<double>(index); +} + +int SociRow::getInteger(std::size_t index) const { + return current_->get<int>(index); +} + +long long SociRow::getLongLong(std::size_t index) const { + return current_->get<long long>(index); +} + +unsigned long long SociRow::getUnsignedLongLong(std::size_t index) const { + return current_->get<unsigned long long>(index); +} + +std::tm SociRow::getDate(std::size_t index) const { + return current_->get<std::tm>(index); +} Review comment: Did you consider making a `get<T>` member function template with no generic implementation and 6 full specializations? I fancy `get<int>` better than `getInt`, but this is really minor, so feel free to ignore if you don't like the idea. ```suggestion template<> std::string SociRow::get<std::string>(std::size_t index) const { return current_->get<std::string>(index); } template<> double SociRow::get<double>(std::size_t index) const { return current_->get<double>(index); } template<> int SociRow::get<int>(std::size_t index) const { return current_->get<int>(index); } template<> long long SociRow::get<long long>(std::size_t index) const { return current_->get<long long>(index); } template<> unsigned long long SociRow::get<unsigned long long>(std::size_t index) const { return current_->get<unsigned long long>(index); } template<> std::tm SociRow::get<std::tm>(std::size_t index) const { return current_->get<std::tm>(index); } ``` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
