mirror of
https://github.com/allankoechke/soci.git
synced 2026-11-30 10:58:24 +00:00
Remove postgresql_soci_error::cat_ field
Don't precompute it in the ctor, it seems better to do it only when it's really needed: the code doing it can't throw, so it's safe, and we might not need to run it at all. No real changes.
This commit is contained in:
@@ -36,11 +36,10 @@ public:
|
||||
|
||||
std::string sqlstate() const;
|
||||
|
||||
error_category get_error_category() const override { return cat_; }
|
||||
error_category get_error_category() const override;
|
||||
|
||||
private:
|
||||
char sqlstate_[ 5 ]; // not std::string to keep copy-constructor no-throw
|
||||
error_category cat_;
|
||||
};
|
||||
|
||||
struct postgresql_session_backend;
|
||||
|
||||
@@ -19,37 +19,42 @@ using namespace soci::details;
|
||||
|
||||
postgresql_soci_error::postgresql_soci_error(
|
||||
std::string const & msg, char const *sqlst)
|
||||
: soci_error(msg), cat_(unknown)
|
||||
: soci_error(msg)
|
||||
{
|
||||
std::memcpy(sqlstate_, sqlst, 5);
|
||||
}
|
||||
|
||||
if (std::memcmp(sqlst, "08", 2) == 0)
|
||||
soci_error::error_category postgresql_soci_error::get_error_category() const
|
||||
{
|
||||
if (std::memcmp(sqlstate_, "08", 2) == 0)
|
||||
{
|
||||
cat_ = connection_error;
|
||||
return connection_error;
|
||||
}
|
||||
else if (std::memcmp(sqlst, "42501", 5) == 0)
|
||||
else if (std::memcmp(sqlstate_, "42501", 5) == 0)
|
||||
{
|
||||
cat_ = no_privilege;
|
||||
return no_privilege;
|
||||
}
|
||||
else if (std::memcmp(sqlst, "42", 2) == 0)
|
||||
else if (std::memcmp(sqlstate_, "42", 2) == 0)
|
||||
{
|
||||
cat_ = invalid_statement;
|
||||
return invalid_statement;
|
||||
}
|
||||
else if (std::memcmp(sqlst, "02", 2) == 0)
|
||||
else if (std::memcmp(sqlstate_, "02", 2) == 0)
|
||||
{
|
||||
cat_ = no_data;
|
||||
return no_data;
|
||||
}
|
||||
else if (std::memcmp(sqlst, "23", 2) == 0)
|
||||
else if (std::memcmp(sqlstate_, "23", 2) == 0)
|
||||
{
|
||||
cat_ = constraint_violation;
|
||||
return constraint_violation;
|
||||
}
|
||||
else if ((std::memcmp(sqlst, "53", 2) == 0) ||
|
||||
(std::memcmp(sqlst, "54", 2) == 0) ||
|
||||
(std::memcmp(sqlst, "58", 2) == 0) ||
|
||||
(std::memcmp(sqlst, "XX", 2) == 0))
|
||||
else if ((std::memcmp(sqlstate_, "53", 2) == 0) ||
|
||||
(std::memcmp(sqlstate_, "54", 2) == 0) ||
|
||||
(std::memcmp(sqlstate_, "58", 2) == 0) ||
|
||||
(std::memcmp(sqlstate_, "XX", 2) == 0))
|
||||
{
|
||||
cat_ = system_error;
|
||||
return system_error;
|
||||
}
|
||||
|
||||
return unknown;
|
||||
}
|
||||
|
||||
std::string postgresql_soci_error::sqlstate() const
|
||||
|
||||
Reference in New Issue
Block a user