From 6b6a7af32bb951bfb0d76772501bd7fa35bbc247 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Fri, 29 Nov 2024 08:39:02 +0100 Subject: [PATCH] Cleanup --- include/tao/pq/result.hpp | 20 +++++++++++++++++--- src/lib/pq/result.cpp | 20 +------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/include/tao/pq/result.hpp b/include/tao/pq/result.hpp index c3a7cda..0485609 100644 --- a/include/tao/pq/result.hpp +++ b/include/tao/pq/result.hpp @@ -46,7 +46,13 @@ namespace tao::pq const std::size_t m_columns; const std::size_t m_rows; - void check_has_result_set() const; + void check_has_result_set() const + { + if( m_columns == 0 ) { + throw std::logic_error( "statement does not yield a result set" ); + } + } + void check_row( const std::size_t row ) const; explicit result( PGresult* pgresult ); @@ -63,8 +69,16 @@ namespace tao::pq [[nodiscard]] auto name( const std::size_t column ) const -> std::string; [[nodiscard]] auto index( const internal::zsv in_name ) const -> std::size_t; - [[nodiscard]] auto empty() const -> bool; - [[nodiscard]] auto size() const -> std::size_t; + [[nodiscard]] auto size() const -> std::size_t + { + check_has_result_set(); + return m_rows; + } + + [[nodiscard]] auto empty() const -> bool + { + return size() == 0; + } private: class const_iterator diff --git a/src/lib/pq/result.cpp b/src/lib/pq/result.cpp index 3c9868d..1a92a96 100644 --- a/src/lib/pq/result.cpp +++ b/src/lib/pq/result.cpp @@ -19,13 +19,6 @@ namespace tao::pq { - void result::check_has_result_set() const - { - if( m_columns == 0 ) { - throw std::logic_error( "statement does not yield a result set" ); - } - } - void result::check_row( const std::size_t row ) const { check_has_result_set(); @@ -92,22 +85,11 @@ namespace tao::pq if( column < 0 ) { assert( column == -1 ); check_has_result_set(); - throw std::out_of_range( "column '" + std::string( in_name ) + "' not found" ); + throw std::out_of_range( std::format( "column '{}' not found", in_name.value ) ); } return column; } - auto result::empty() const -> bool - { - return size() == 0; - } - - auto result::size() const -> std::size_t - { - check_has_result_set(); - return m_rows; - } - auto result::begin() const -> result::const_iterator { check_has_result_set();