32using namespace fbcpp::impl;
35fb::IStatus* StatusWrapper::getStatus()
const
39 status = client->newStatus().release();
46void StatusWrapper::checkException(StatusWrapper* status)
48 if (status->dirty && (status->getState() & fb::IStatus::STATE_ERRORS))
52void StatusWrapper::catchException(fb::IStatus* status)
noexcept
58std::string DatabaseException::buildMessage(
Client& client,
const std::intptr_t* statusVector)
60 constexpr char DEFAULT_MESSAGE[] =
"Unknown database error";
63 return DEFAULT_MESSAGE;
65 const auto util = client.
getUtil();
68 status->setErrors(statusVector);
70 constexpr unsigned MAX_BUFFER_SIZE = 32u * 1024u;
71 unsigned bufferSize = 256u;
74 while (bufferSize <= MAX_BUFFER_SIZE)
76 std::string buffer(bufferSize,
'\0');
77 const auto written = util->formatStatus(buffer.data(), bufferSize, status.get());
79 if (written < bufferSize && buffer[0] !=
'\0')
81 message = written == 0 ? std::string{buffer.c_str()} : std::string{buffer.data(), written};
85 if (bufferSize == MAX_BUFFER_SIZE)
87 message = buffer.c_str();
91 bufferSize = (bufferSize > MAX_BUFFER_SIZE / 2u) ? MAX_BUFFER_SIZE : bufferSize * 2u;
95 message = DEFAULT_MESSAGE;
100void DatabaseException::copyErrorVector(
const std::intptr_t* statusVector)
105 const auto* p = statusVector;
107 while (*p != isc_arg_end)
109 const auto argType = *p++;
115 errorVector.push_back(argType);
116 errorVector.push_back(*p++);
120 case isc_arg_interpreted:
121 case isc_arg_sql_state:
122 errorVector.push_back(argType);
123 errorStrings.emplace_back(
reinterpret_cast<const char*
>(*p++));
124 errorVector.push_back(0);
127 case isc_arg_cstring:
129 const auto len =
static_cast<size_t>(*p++);
130 const auto str =
reinterpret_cast<const char*
>(*p++);
131 errorVector.push_back(isc_arg_string);
132 errorStrings.emplace_back(str, len);
133 errorVector.push_back(0);
138 errorVector.push_back(argType);
139 errorVector.push_back(*p++);
144 errorVector.push_back(isc_arg_end);
146 fixupStringPointers();
149void DatabaseException::fixupStringPointers()
154 while (i < errorVector.size() && errorVector[i] != isc_arg_end)
156 const auto argType = errorVector[i];
158 if (argType == isc_arg_string || argType == isc_arg_interpreted || argType == isc_arg_sql_state)
159 errorVector[i + 1] =
reinterpret_cast<std::intptr_t
>(errorStrings[strIdx++].c_str());
165std::string DatabaseException::extractSqlState(
const std::intptr_t* statusVector)
170 const auto* p = statusVector;
172 while (*p != isc_arg_end)
174 const auto argType = *p++;
176 if (argType == isc_arg_sql_state)
177 return reinterpret_cast<const char*
>(*p);
179 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.