Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Dec 9, 2024
1 parent 34566c1 commit 6e82b57
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
3 changes: 1 addition & 2 deletions include/tao/pq/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ namespace tao::pq
[[nodiscard]] auto attempt_rollback() const noexcept -> bool;

static void check_prepared_name( const std::string_view name );
[[nodiscard]] auto is_prepared( const std::string_view name ) const noexcept -> bool;

void send_params( const char* statement,
const int n_params,
Expand Down Expand Up @@ -147,7 +146,7 @@ namespace tao::pq
[[nodiscard]] auto transaction( const access_mode am, const isolation_level il = isolation_level::default_isolation_level ) -> std::shared_ptr< pq::transaction >;
[[nodiscard]] auto transaction( const isolation_level il, const access_mode am = access_mode::default_access_mode ) -> std::shared_ptr< pq::transaction >;

void prepare( const std::string& name, const std::string& statement );
void prepare( std::string name, const internal::zsv statement );
void deallocate( const std::string_view name );

template< parameter_type... As >
Expand Down
13 changes: 4 additions & 9 deletions src/lib/pq/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,14 @@ namespace tao::pq
}
}

auto connection::is_prepared( const std::string_view name ) const noexcept -> bool
{
return m_prepared_statements.contains( name );
}

void connection::send_params( const char* statement,
const int n_params,
const Oid types[],
const char* const values[],
const int lengths[],
const int formats[] )
{
const auto result = is_prepared( statement ) ?
const auto result = m_prepared_statements.contains( statement ) ?
PQsendQueryPrepared( m_pgconn.get(), statement, n_params, values, lengths, formats, 0 ) :
PQsendQueryParams( m_pgconn.get(), statement, n_params, types, values, lengths, formats, 0 );
if( result == 0 ) {
Expand Down Expand Up @@ -507,11 +502,11 @@ namespace tao::pq
return std::make_shared< internal::top_level_transaction >( shared_from_this(), il, am );
}

void connection::prepare( const std::string& name, const std::string& statement )
void connection::prepare( std::string name, const internal::zsv statement )
{
connection::check_prepared_name( name );
const auto end = timeout_end();
if( PQsendPrepare( m_pgconn.get(), name.c_str(), statement.c_str(), 0, nullptr ) == 0 ) {
if( PQsendPrepare( m_pgconn.get(), name.c_str(), statement, 0, nullptr ) == 0 ) {
throw pq::connection_error( PQerrorMessage( m_pgconn.get() ) ); // LCOV_EXCL_LINE
}
auto result = connection::get_result( end );
Expand All @@ -530,7 +525,7 @@ namespace tao::pq
connection::clear_results( end );
internal::throw_sqlstate( result.get() );
}
m_prepared_statements.insert( name );
m_prepared_statements.insert( std::move( name ) );
}

void connection::deallocate( const std::string_view name )
Expand Down

0 comments on commit 6e82b57

Please sign in to comment.