GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/zserio/SqliteException.h Lines: 8 8 100.0 %
Date: 2023-12-13 14:51:09 Branches: 1 2 50.0 %

Line Branch Exec Source
1
#ifndef ZSERIO_SQLITE_EXCEPTION_H_INC
2
#define ZSERIO_SQLITE_EXCEPTION_H_INC
3
4
#include "sqlite3.h"
5
6
#include "zserio/CppRuntimeException.h"
7
8
namespace zserio
9
{
10
11
/** Wrapper class to work with SQLite error code. */
12
class SqliteErrorCode
13
{
14
public:
15
    /**
16
     * Constructor.
17
     *
18
     * \param sqliteCode SQLite error code.
19
     */
20
9
    explicit SqliteErrorCode(int sqliteCode) : m_code(sqliteCode)
21
9
    {}
22
23
    /**
24
     * Gets SQLite error string appropriate to the error code.
25
     *
26
     * \return English language text that describes the error code. Memory to hold the error message string is
27
     *         managed by SQLite.
28
     */
29
9
    const char* getErrorString() const
30
    {
31
9
        return sqlite3_errstr(m_code);
32
    }
33
34
private:
35
    int m_code;
36
};
37
38
/** Exception thrown when an error in an SQLite operation occurs. */
39
27
class SqliteException : public CppRuntimeException
40
{
41
public:
42
9
    using CppRuntimeException::CppRuntimeException;
43
};
44
45
/**
46
 * Allow to append SqliteErrorCode to CppRuntimeException.
47
 *
48
 * \param exception Exception to modify.
49
 * \param code SQLite error code.
50
 */
51
9
inline CppRuntimeException& operator<<(CppRuntimeException& exception, SqliteErrorCode code)
52
{
53
9
    return exception << code.getErrorString();
54
}
55
56
} // namespace zserio
57
58
#endif // ifndef ZSERIO_SQLITE_EXCEPTION_H_INC