32using namespace fbcpp::impl;
35void StatusWrapper::checkException(StatusWrapper* status)
37 if (status->dirty && (status->getState() & fb::IStatus::STATE_ERRORS))
41void StatusWrapper::catchException(fb::IStatus* status)
noexcept
47std::string DatabaseException::buildMessage(
Client& client,
const std::intptr_t* statusVector)
49 constexpr char DEFAULT_MESSAGE[] =
"Unknown database error";
52 return DEFAULT_MESSAGE;
54 const auto util = client.
getUtil();
57 status->setErrors(statusVector);
59 constexpr unsigned MAX_BUFFER_SIZE = 32u * 1024u;
60 unsigned bufferSize = 256u;
63 while (bufferSize <= MAX_BUFFER_SIZE)
65 std::string buffer(bufferSize,
'\0');
66 const auto written = util->formatStatus(buffer.data(), bufferSize, status.get());
68 if (written < bufferSize && buffer[0] !=
'\0')
70 message = written == 0 ? std::string{buffer.c_str()} : std::string{buffer.data(), written};
74 if (bufferSize == MAX_BUFFER_SIZE)
76 message = buffer.c_str();
80 bufferSize = (bufferSize > MAX_BUFFER_SIZE / 2u) ? MAX_BUFFER_SIZE : bufferSize * 2u;
84 message = DEFAULT_MESSAGE;
89void DatabaseException::copyErrorVector(
const std::intptr_t* statusVector)
94 const auto* p = statusVector;
96 while (*p != isc_arg_end)
98 const auto argType = *p++;
104 errorVector.push_back(argType);
105 errorVector.push_back(*p++);
109 case isc_arg_interpreted:
110 case isc_arg_sql_state:
111 errorVector.push_back(argType);
112 errorStrings.emplace_back(
reinterpret_cast<const char*
>(*p++));
113 errorVector.push_back(0);
116 case isc_arg_cstring:
118 const auto len =
static_cast<size_t>(*p++);
119 const auto str =
reinterpret_cast<const char*
>(*p++);
120 errorVector.push_back(isc_arg_string);
121 errorStrings.emplace_back(str, len);
122 errorVector.push_back(0);
127 errorVector.push_back(argType);
128 errorVector.push_back(*p++);
133 errorVector.push_back(isc_arg_end);
135 fixupStringPointers();
138void DatabaseException::fixupStringPointers()
143 while (i < errorVector.size() && errorVector[i] != isc_arg_end)
145 const auto argType = errorVector[i];
147 if (argType == isc_arg_string || argType == isc_arg_interpreted || argType == isc_arg_sql_state)
148 errorVector[i + 1] =
reinterpret_cast<std::intptr_t
>(errorStrings[strIdx++].c_str());
154std::string DatabaseException::extractSqlState(
const std::intptr_t* statusVector)
159 const auto* p = statusVector;
161 while (*p != isc_arg_end)
163 const auto argType = *p++;
165 if (argType == isc_arg_sql_state)
166 return reinterpret_cast<const char*
>(*p);
168 if (argType == isc_arg_cstring)
Represents a Firebird client library instance.
fb::IUtil * getUtil()
Returns a Firebird IUtil interface.
FbUniquePtr< fb::IStatus > newStatus()
Creates and returns a Firebird IStatus instance.
Exception thrown when a Firebird database operation fails.
const std::vector< std::intptr_t > & getErrors() const noexcept
Returns the Firebird error vector.