Skip to content

Commit

Permalink
Improve test, fix clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Nov 21, 2024
1 parent 21d8c96 commit f671262
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/tao/pq/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace tao::pq

void set_single_row_mode();
#if defined( LIBPQ_HAS_CHUNK_MODE )
void set_chunk_mode( const std::size_t rows );
void set_chunk_mode( const int rows );
#endif

[[nodiscard]] auto get_result( const std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now() ) -> result;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pq/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ namespace tao::pq
}

#if defined( LIBPQ_HAS_CHUNK_MODE )
void transaction::set_chunk_mode( const std::size_t rows )
void transaction::set_chunk_mode( const int rows )
{
check_current_transaction();
if( PQsetChunkedRowsMode( m_connection->underlying_raw_ptr(), rows ) == 0 ) {
Expand Down
36 changes: 36 additions & 0 deletions src/test/pq/chunk_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@

#include <tao/pq.hpp>

#if !defined( LIBPQ_HAS_CHUNK_MODE )

auto main() -> int
{
return 0;
}

#else

namespace
{
void run()
Expand All @@ -32,6 +41,8 @@ namespace
conn->execute( "insert_user", "Bob", 19 );
conn->execute( "insert_user", "Charlie", 45 );

std::size_t count = 0;

const auto tr = conn->transaction();
tr->send( "SELECT name, age FROM tao_single_row_mode" );
tr->set_chunk_mode( 2 );
Expand All @@ -43,18 +54,41 @@ namespace
}

for( const auto& row : result ) {
++count;
std::cout << row[ "name" ].as< std::string >() << " is "
<< row[ "age" ].as< unsigned >() << " years old.\n";
}
}

TEST_ASSERT( count == 6 );

count = 0;
tr->send( "SELECT name, age FROM tao_single_row_mode" );
tr->set_chunk_mode( 4 );

while( true ) {
const auto result = tr->get_result();
if( result.empty() ) {
break;
}

for( const auto& row : result ) {
++count;
std::cout << row[ "name" ].as< std::string >() << " is "
<< row[ "age" ].as< unsigned >() << " years old.\n";
}
}

TEST_ASSERT( count == 6 );

TEST_THROWS( tr->set_single_row_mode() );
TEST_THROWS( tr->set_chunk_mode( 2 ) );

tr->send( "SELECT name, age FROM tao_single_row_mode" );
TEST_THROWS( tr->set_chunk_mode( 0 ) );
TEST_THROWS( tr->set_chunk_mode( -1 ) );
tr->set_chunk_mode( 2 );
TEST_THROWS( tr->set_single_row_mode() );
}

} // namespace
Expand All @@ -75,3 +109,5 @@ auto main() -> int // NOLINT(bugprone-exception-escape)
}
// LCOV_EXCL_STOP
}

#endif

0 comments on commit f671262

Please sign in to comment.