Lightweight 0.20261105.1
Loading...
Searching...
No Matches
Diagnostics.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include "../../Api.hpp"
6#include "../../SqlError.hpp"
7
8#include <string_view>
9
10/// @file
11/// The diagnostics of the SQLite3 driver: how a SQLite result code becomes a @ref Lightweight::SqlErrorInfo.
12///
13/// SQLite reports a result code and a message, no SQLSTATE. The driver derives one from a descriptor table, so
14/// the library's error classification (@c SqlErrorDetection.hpp, the retry policies) answers for the native
15/// driver as it does for an ODBC driver: constraint violations land in class 23, a busy or locked database in
16/// the retryable @c 40001, a failed open in @c HY000.
17
18namespace Lightweight::Driver::Sqlite3
19{
20
21/// @brief The SQLSTATE of a SQLite failure.
22///
23/// Looked up in a table ordered most specific first: a row matches the full extended result code, or only
24/// its primary code (the low 8 bits) where the row says so; the rows for @c SQLITE_ERROR also look for a
25/// fragment of SQLite's message (@c "no such table", @c "no such column", @c "already exists",
26/// @c "syntax error"), since SQLite reports those with no more specific code.
27///
28/// @param extendedResultCode The extended result code of the failure.
29/// @param message SQLite's message for it.
30/// @return The SQLSTATE of the first matching row; @c "HY000" when no row matches.
31[[nodiscard]] LIGHTWEIGHT_API std::string_view SqlStateFromResultCode(int extendedResultCode,
32 std::string_view message) noexcept;
33
34/// @brief The diagnostics of a SQLite failure.
35/// @param extendedResultCode The extended result code of the failure; it becomes the native error code.
36/// @param message SQLite's message for it, verbatim.
37/// @return The diagnostics, with the SQLSTATE of @c SqlStateFromResultCode.
38[[nodiscard]] LIGHTWEIGHT_API SqlErrorInfo MakeErrorInfo(int extendedResultCode, std::string_view message);
39
40} // namespace Lightweight::Driver::Sqlite3
LIGHTWEIGHT_API SqlErrorInfo MakeErrorInfo(int extendedResultCode, std::string_view message)
The diagnostics of a SQLite failure.
LIGHTWEIGHT_API std::string_view SqlStateFromResultCode(int extendedResultCode, std::string_view message) noexcept
The SQLSTATE of a SQLite failure.
Represents a SQL error as reported by the database driver.
Definition SqlError.hpp:29