Skip to content

Commit f671262

Browse files
committed
Improve test, fix clang-tidy
1 parent 21d8c96 commit f671262

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

include/tao/pq/transaction.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ namespace tao::pq
143143

144144
void set_single_row_mode();
145145
#if defined( LIBPQ_HAS_CHUNK_MODE )
146-
void set_chunk_mode( const std::size_t rows );
146+
void set_chunk_mode( const int rows );
147147
#endif
148148

149149
[[nodiscard]] auto get_result( const std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now() ) -> result;

src/lib/pq/transaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ namespace tao::pq
150150
}
151151

152152
#if defined( LIBPQ_HAS_CHUNK_MODE )
153-
void transaction::set_chunk_mode( const std::size_t rows )
153+
void transaction::set_chunk_mode( const int rows )
154154
{
155155
check_current_transaction();
156156
if( PQsetChunkedRowsMode( m_connection->underlying_raw_ptr(), rows ) == 0 ) {

src/test/pq/chunk_mode.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111

1212
#include <tao/pq.hpp>
1313

14+
#if !defined( LIBPQ_HAS_CHUNK_MODE )
15+
16+
auto main() -> int
17+
{
18+
return 0;
19+
}
20+
21+
#else
22+
1423
namespace
1524
{
1625
void run()
@@ -32,6 +41,8 @@ namespace
3241
conn->execute( "insert_user", "Bob", 19 );
3342
conn->execute( "insert_user", "Charlie", 45 );
3443

44+
std::size_t count = 0;
45+
3546
const auto tr = conn->transaction();
3647
tr->send( "SELECT name, age FROM tao_single_row_mode" );
3748
tr->set_chunk_mode( 2 );
@@ -43,18 +54,41 @@ namespace
4354
}
4455

4556
for( const auto& row : result ) {
57+
++count;
58+
std::cout << row[ "name" ].as< std::string >() << " is "
59+
<< row[ "age" ].as< unsigned >() << " years old.\n";
60+
}
61+
}
62+
63+
TEST_ASSERT( count == 6 );
64+
65+
count = 0;
66+
tr->send( "SELECT name, age FROM tao_single_row_mode" );
67+
tr->set_chunk_mode( 4 );
68+
69+
while( true ) {
70+
const auto result = tr->get_result();
71+
if( result.empty() ) {
72+
break;
73+
}
74+
75+
for( const auto& row : result ) {
76+
++count;
4677
std::cout << row[ "name" ].as< std::string >() << " is "
4778
<< row[ "age" ].as< unsigned >() << " years old.\n";
4879
}
4980
}
5081

82+
TEST_ASSERT( count == 6 );
83+
5184
TEST_THROWS( tr->set_single_row_mode() );
5285
TEST_THROWS( tr->set_chunk_mode( 2 ) );
5386

5487
tr->send( "SELECT name, age FROM tao_single_row_mode" );
5588
TEST_THROWS( tr->set_chunk_mode( 0 ) );
5689
TEST_THROWS( tr->set_chunk_mode( -1 ) );
5790
tr->set_chunk_mode( 2 );
91+
TEST_THROWS( tr->set_single_row_mode() );
5892
}
5993

6094
} // namespace
@@ -75,3 +109,5 @@ auto main() -> int // NOLINT(bugprone-exception-escape)
75109
}
76110
// LCOV_EXCL_STOP
77111
}
112+
113+
#endif

0 commit comments

Comments
 (0)