Skip to content

Commit

Permalink
Version 2.1.2
Browse files Browse the repository at this point in the history
- add method Server_exception::error_ptr();
- add methods of the class Problem: query_position_num(),
internal_query_position_num(), source_line_num();
- fix the bug of the class Connection.
  • Loading branch information
dmitigr committed Dec 13, 2022
1 parent 19b650e commit 868e363
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmake/dmitigr_pgfe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Info
# ------------------------------------------------------------------------------

dmitigr_libs_set_library_info(pgfe 2 1 1 "PostgreSQL client API")
dmitigr_libs_set_library_info(pgfe 2 1 2 "PostgreSQL client API")

# ------------------------------------------------------------------------------
# Sources
Expand Down
3 changes: 2 additions & 1 deletion src/pgfe/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ Connection::handle_input(const bool wait_response)
response_status_ = Response_status::ready_not_preprocessed;
else
response_status_ = Response_status::empty;
}
} else
response_status_ = Response_status::unready;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/pgfe/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ DMITIGR_PGFE_INLINE const Error& Server_exception::error() const noexcept
return *error_;
}

DMITIGR_PGFE_INLINE std::shared_ptr<Error> Server_exception::error_ptr() const noexcept
{
return error_;
}

} // namespace dmitigr::pgfe
3 changes: 3 additions & 0 deletions src/pgfe/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class Server_exception final : public Exception {
/// @returns The error response (aka error report).
DMITIGR_PGFE_API const Error& error() const noexcept;

/// @returns The error response as the underlying shared pointer.
DMITIGR_PGFE_API std::shared_ptr<Error> error_ptr() const noexcept;

private:
std::shared_ptr<Error> error_;
};
Expand Down
2 changes: 1 addition & 1 deletion src/pgfe/pq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Result final {
/// The constructor.
explicit Result(PGresult* const pgresult) noexcept
: status_{pgresult ? PQresultStatus(pgresult) : static_cast<Status>(-1)}
, pgresult_(pgresult)
, pgresult_{pgresult}
{}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/pgfe/problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,25 @@ DMITIGR_PGFE_INLINE const char* Problem::query_position() const noexcept
return pq_result_.er_query_position();
}

DMITIGR_PGFE_INLINE std::string::size_type
Problem::query_position_num() const noexcept
{
const char* const pos{query_position()};
return pos ? std::strtoul(pos, nullptr, 10) : 0;
}

DMITIGR_PGFE_INLINE const char* Problem::internal_query_position() const noexcept
{
return pq_result_.er_internal_query_position();
}

DMITIGR_PGFE_INLINE std::string::size_type
Problem::internal_query_position_num() const noexcept
{
const char* const pos{internal_query_position()};
return pos ? std::strtoul(pos, nullptr, 10) : 0;
}

DMITIGR_PGFE_INLINE const char* Problem::internal_query() const noexcept
{
return pq_result_.er_internal_query();
Expand Down Expand Up @@ -122,6 +136,12 @@ DMITIGR_PGFE_INLINE const char* Problem::source_line() const noexcept
return pq_result_.er_source_line();
}

DMITIGR_PGFE_INLINE std::string::size_type Problem::source_line_num() const noexcept
{
const char* const pos{source_line()};
return pos ? std::strtoul(pos, nullptr, 10) : 0;
}

DMITIGR_PGFE_INLINE const char* Problem::source_function() const noexcept
{
return pq_result_.er_source_function();
Expand Down
18 changes: 18 additions & 0 deletions src/pgfe/problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,24 @@ class Problem {
*/
DMITIGR_PGFE_API const char* query_position() const noexcept;

/**
* @returns The the numeric representation of `query_position()`, or
* `0` if `!query_position()`.
*/
DMITIGR_PGFE_API std::string::size_type query_position_num() const noexcept;

/**
* @returns: Similar to query_position(), but it is used when the position
* refers to an internally-generated query rather than the one submitted.
*/
DMITIGR_PGFE_API const char* internal_query_position() const noexcept;

/**
* @returns The the numeric representation of `internal_query_position()`, or
* `0` if `!internal_query_position()`.
*/
DMITIGR_PGFE_API std::string::size_type internal_query_position_num() const noexcept;

/**
* @returns The text of the failed internally-generated query.
*
Expand Down Expand Up @@ -156,6 +168,12 @@ class Problem {
/// @returns The line number of the source-code location reporting the problem.
DMITIGR_PGFE_API const char* source_line() const noexcept;

/**
* @returns The the numeric representation of `source_line()`, or
* `0` if `!source_line()`.
*/
DMITIGR_PGFE_API std::string::size_type source_line_num() const noexcept;

/// @returns The name of the source-code function reporting the problem.
DMITIGR_PGFE_API const char* source_function() const noexcept;

Expand Down
2 changes: 1 addition & 1 deletion src/pgfe/statement_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Statement_vector::query_absolute_position(const std::size_t index,
const auto statement_position = [this](const std::size_t idx)
{
std::string::size_type result{};
for (std::size_t i = 0; i < idx; ++i)
for (std::size_t i{}; i < idx; ++i)
result += operator[](i).to_string().size() + 1;
return result;
};
Expand Down
2 changes: 1 addition & 1 deletion src/pgfe/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ constexpr std::int_fast32_t version() noexcept
// Actual values are set in CMakeLists.txt.
constexpr std::int_least32_t major = 2;
constexpr std::int_least32_t minor = 1;
constexpr std::int_least32_t patch = 1;
constexpr std::int_least32_t patch = 2;

// 111.222.333 -> 111222333
return major*1000000 + minor*1000 + patch;
Expand Down
9 changes: 0 additions & 9 deletions src/str/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,12 @@
#include <istream>
#include <fstream>
#include <optional>
#include <ostream> // std::endl
#include <sstream>
#include <string>
#include <vector>

namespace dmitigr::str {

/// @returns New line sequence.
std::string endlstr()
{
std::stringstream ss;
ss << std::endl;
return ss.str();
}

/**
* @brief Reads the file into the vector of strings.
*
Expand Down

0 comments on commit 868e363

Please sign in to comment.