LCOV - code coverage report
Current view: top level - libgnucash/backend/dbi - gnc-dbisqlresult.hpp (source / functions) Hit Total Coverage
Test: gnucash.info Lines: 0 10 0.0 %
Date: 2024-10-31 11:06:40 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /********************************************************************
       2                 :            :  * gnc-dbisqlresult.hpp: Iterable wrapper for dbi_result.           *
       3                 :            :  *                                                                  *
       4                 :            :  * Copyright 2016 John Ralls <jralls@ceridwen.us                    *
       5                 :            :  *                                                                  *
       6                 :            :  * This program is free software; you can redistribute it and/or    *
       7                 :            :  * modify it under the terms of the GNU General Public License as   *
       8                 :            :  * published by the Free Software Foundation; either version 2 of   *
       9                 :            :  * the License, or (at your option) any later version.              *
      10                 :            :  *                                                                  *
      11                 :            :  * This program is distributed in the hope that it will be useful,  *
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
      14                 :            :  * GNU General Public License for more details.                     *
      15                 :            :  *                                                                  *
      16                 :            :  * You should have received a copy of the GNU General Public License*
      17                 :            :  * along with this program; if not, contact:                        *
      18                 :            :  *                                                                  *
      19                 :            :  * Free Software Foundation           Voice:  +1-617-542-5942       *
      20                 :            :  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
      21                 :            :  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
      22                 :            : \********************************************************************/
      23                 :            : 
      24                 :            : /* Private structures and variables for gnc-backend-dbi.c and its unit tests */
      25                 :            : #ifndef __GNC_DBISQLBACKEND_HPP__
      26                 :            : #define __GNC_DBISQLBACKEND_HPP__
      27                 :            : 
      28                 :            : #include <optional>
      29                 :            : 
      30                 :            : #include "gnc-backend-dbi.h"
      31                 :            : #include <gnc-sql-result.hpp>
      32                 :            : 
      33                 :            : class GncDbiSqlConnection;
      34                 :            : 
      35                 :            : /**
      36                 :            :  * An iterable wrapper for dbi_result; allows using C++11 range for.
      37                 :            :  */
      38                 :            : class GncDbiSqlResult : public GncSqlResult
      39                 :            : {
      40                 :            : public:
      41                 :          0 :     GncDbiSqlResult(const GncDbiSqlConnection* conn, dbi_result result) :
      42                 :          0 :         m_conn{conn}, m_dbi_result{result}, m_iter{this}, m_row{&m_iter},
      43                 :          0 :         m_sentinel{nullptr} {}
      44                 :            :     ~GncDbiSqlResult();
      45                 :            :     uint64_t size() const noexcept;
      46                 :            :     int dberror() const noexcept;
      47                 :            :     GncSqlRow& begin();
      48                 :          0 :     GncSqlRow& end() { return m_sentinel; }
      49                 :            : protected:
      50                 :            :     class IteratorImpl : public GncSqlResult::IteratorImpl
      51                 :            :     {
      52                 :            :     public:
      53                 :          0 :         ~IteratorImpl() = default;
      54                 :          0 :         IteratorImpl(GncDbiSqlResult* inst) : m_inst{inst} {}
      55                 :            :         virtual GncSqlRow& operator++();
      56                 :          0 :         virtual GncSqlRow& operator++(int) { return ++(*this); };
      57                 :          0 :         virtual GncSqlResult* operator*() { return m_inst; }
      58                 :            :         virtual std::optional<int64_t> get_int_at_col (const char* col) const;
      59                 :            :         virtual std::optional<double> get_float_at_col (const char* col) const;
      60                 :            :         virtual std::optional<double> get_double_at_col (const char* col) const;
      61                 :            :         virtual std::optional<std::string> get_string_at_col (const char* col)const;
      62                 :            :         virtual std::optional<time64> get_time64_at_col (const char* col) const;
      63                 :          0 :         virtual bool is_col_null(const char* col) const noexcept
      64                 :            :         {
      65                 :          0 :             return dbi_result_field_is_null(m_inst->m_dbi_result, col);
      66                 :            :         }
      67                 :            :     private:
      68                 :            :         GncDbiSqlResult* m_inst = nullptr;
      69                 :            :     };
      70                 :            : 
      71                 :            : private:
      72                 :            :     const GncDbiSqlConnection* m_conn = nullptr;
      73                 :            :     dbi_result m_dbi_result;
      74                 :            :     IteratorImpl m_iter;
      75                 :            :     GncSqlRow m_row;
      76                 :            :     GncSqlRow m_sentinel;
      77                 :            : 
      78                 :            : };
      79                 :            : 
      80                 :            : #endif //__GNC_DBISQLRESULT_HPP__

Generated by: LCOV version 1.14