Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Nov 29, 2024
1 parent a9f25ac commit 6b6a7af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
20 changes: 17 additions & 3 deletions include/tao/pq/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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
Expand Down
20 changes: 1 addition & 19 deletions src/lib/pq/result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6b6a7af

Please sign in to comment.