-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2024 Daniel Frey and Dr. Colin Hirsch | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#ifndef TAO_PQ_PIPELINE_STATUS_HPP | ||
#define TAO_PQ_PIPELINE_STATUS_HPP | ||
|
||
#include <cstdint> | ||
|
||
#include <libpq-fe.h> | ||
|
||
namespace tao::pq | ||
{ | ||
enum class pipeline_status : std::uint8_t | ||
{ | ||
on = PQ_PIPELINE_ON, | ||
off = PQ_PIPELINE_OFF, | ||
aborted = PQ_PIPELINE_ABORTED | ||
}; | ||
|
||
} // namespace tao::pq | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2024 Daniel Frey and Dr. Colin Hirsch | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#ifndef TAO_PQ_RESULT_STATUS_HPP | ||
#define TAO_PQ_RESULT_STATUS_HPP | ||
|
||
#include <cstdint> | ||
|
||
#include <libpq-fe.h> | ||
|
||
namespace tao::pq | ||
{ | ||
enum class result_status : std::uint8_t | ||
{ | ||
empty_query = PGRES_EMPTY_QUERY, | ||
command_ok = PGRES_COMMAND_OK, | ||
tuples_ok = PGRES_TUPLES_OK, | ||
copy_out = PGRES_COPY_OUT, | ||
copy_in = PGRES_COPY_IN, | ||
bad_response = PGRES_BAD_RESPONSE, | ||
nonfatal_error = PGRES_NONFATAL_ERROR, | ||
fatal_error = PGRES_FATAL_ERROR, | ||
single_tuple = PGRES_SINGLE_TUPLE, | ||
#if defined( LIBPQ_HAS_CHUNK_MODE ) | ||
tuples_chunk = PGRES_TUPLES_CHUNK, | ||
#endif | ||
pipeline_sync = PGRES_PIPELINE_SYNC, | ||
pipeline_aborted = PGRES_PIPELINE_ABORTED | ||
}; | ||
|
||
} // namespace tao::pq | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2024 Daniel Frey and Dr. Colin Hirsch | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include "../getenv.hpp" | ||
#include "../macros.hpp" | ||
|
||
#include <exception> | ||
#include <iostream> | ||
|
||
#include <tao/pq.hpp> | ||
#include <tao/pq/internal/unreachable.hpp> | ||
|
||
namespace | ||
{ | ||
void run() | ||
{ | ||
// overwrite the default with an environment variable if needed | ||
const auto connection_string = tao::pq::internal::getenv( "TAOPQ_TEST_DATABASE", "dbname=template1" ); // NOLINT(clang-analyzer-deadcode.DeadStores) | ||
|
||
// open a connection | ||
const auto connection = tao::pq::connection::create( connection_string ); | ||
TEST_ASSERT( connection->pipeline_status() == tao::pq::pipeline_status::off ); | ||
|
||
TEST_THROWS( connection->pipeline_sync() ); | ||
|
||
connection->exit_pipeline_mode(); | ||
TEST_ASSERT( connection->pipeline_status() == tao::pq::pipeline_status::off ); | ||
|
||
connection->enter_pipeline_mode(); | ||
TEST_ASSERT( connection->pipeline_status() == tao::pq::pipeline_status::on ); | ||
|
||
connection->enter_pipeline_mode(); | ||
TEST_ASSERT( connection->pipeline_status() == tao::pq::pipeline_status::on ); | ||
|
||
{ | ||
auto tr = connection->direct(); | ||
tr->send( "SELECT 42" ); | ||
tr->send( "SELECT 1234" ); | ||
connection->pipeline_sync(); | ||
|
||
TEST_ASSERT( tr->get_result().as< int >() == 42 ); | ||
|
||
tr->send( "SELECT 1701" ); | ||
connection->pipeline_sync(); | ||
|
||
TEST_ASSERT( tr->get_result().as< int >() == 1234 ); | ||
TEST_ASSERT( tr->get_result().as< int >() == 1701 ); | ||
tr->consume_pipeline_sync(); | ||
|
||
TEST_ASSERT( connection->pipeline_status() == tao::pq::pipeline_status::on ); | ||
connection->exit_pipeline_mode(); | ||
TEST_ASSERT( connection->pipeline_status() == tao::pq::pipeline_status::off ); | ||
|
||
tr->commit(); | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
auto main() -> int // NOLINT(bugprone-exception-escape) | ||
{ | ||
try { | ||
run(); | ||
} | ||
// LCOV_EXCL_START | ||
catch( const std::exception& e ) { | ||
std::cerr << "exception: " << e.what() << '\n'; | ||
throw; | ||
} | ||
catch( ... ) { | ||
std::cerr << "unknown exception\n"; | ||
throw; | ||
} | ||
// LCOV_EXCL_STOP | ||
} |