/* * @project The CERN Tape Archive (CTA) * @copyright Copyright © 2021-2022 CERN * @license This program is free software, distributed under the terms of the GNU General Public * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". You can * redistribute it and/or modify it under the terms of the GPL Version 3, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public License for more details. * * In applying this licence, CERN does not waive the privileges and immunities * granted to it by virtue of its status as an Intergovernmental Organization or * submit itself to any jurisdiction. */ #pragma once #include "common/threading/Mutex.hpp" #include "rdbms/wrapper/ColumnNameToIdx.hpp" #include "rdbms/wrapper/RsetWrapper.hpp" #include #include namespace cta::rdbms::wrapper { /** * Forward declaration to avoid a circular dependency between OcciRset and * OcciStmt. */ class OcciStmt; /** * A convenience wrapper around an OCCI result set. */ class OcciRset: public RsetWrapper { public: /** * Constructor. * * This constructor will throw an exception if the result set is a nullptr * pointer. * * @param stmt The OCCI statement. * @param rset The OCCI result set. */ OcciRset(OcciStmt &stmt, oracle::occi::ResultSet *const rset); /** * Destructor. */ ~OcciRset() override; /** * Returns the SQL statement. * * @return The SQL statement. */ const std::string &getSql() const override; /** * Attempts to get the next row of the result set. * * @return True if a row has been retrieved else false if there are no more * rows in the result set. */ bool next() override; /** * Returns true if the specified column contains a null value. * * @param colName The name of the column. * @return True if the specified column contains a null value. */ bool columnIsNull(const std::string &colName) const override; /** * Returns the value of the specified column as a binary string (byte array). * * @param colName The name of the column. * @return The string value of the specified column. */ std::string columnBlob(const std::string &colName) const override; /** * Returns the value of the specified column as a string. * * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The string value of the specified column. */ std::optional columnOptionalString(const std::string &colName) const override; /** * Returns the value of the specified column as an integer. * * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The value of the specified column. */ std::optional columnOptionalUint8(const std::string &colName) const override; /** * Returns the value of the specified column as an integer. * * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The value of the specified column. */ std::optional columnOptionalUint16(const std::string &colName) const override; /** * Returns the value of the specified column as an integer. * * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The value of the specified column. */ std::optional columnOptionalUint32(const std::string &colName) const override; /** * Returns the value of the specified column as an integer. * * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The value of the specified column. */ std::optional columnOptionalUint64(const std::string &colName) const override; /** * Returns the value of the specified column as a double. * * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The value of the specified column. */ std::optional columnOptionalDouble(const std::string &colName) const override; private: /** * Mutex used to serialize access to this object. */ mutable threading::Mutex m_mutex; /** * The OCCI statement. */ OcciStmt &m_stmt; /** * The OCCI result set. */ oracle::occi::ResultSet *m_rset; /** * Map from column name to column index. */ ColumnNameToIdx m_colNameToIdx; /** * Idempotent close() method. The destructor calls this method. */ void close(); /** * Populates the map from column name to column index. */ void populateColNameToIdxMap(); }; // class OcciRset } // namespace cta::rdbms::wrapper