VSQLite++
0.3
Toggle main menu visibility
Loading...
Searching...
No Matches
include
sqlite
database_exception.hpp
Go to the documentation of this file.
1
/*##############################################################################
2
VSQLite++ - virtuosic bytes SQLite3 C++ wrapper
3
4
Copyright (c) 2006-2014 Vinzenz Feenstra vinzenz.feenstra@gmail.com
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without modification,
8
are permitted provided that the following conditions are met:
9
10
* Redistributions of source code must retain the above copyright notice,
11
this list of conditions and the following disclaimer.
12
* Redistributions in binary form must reproduce the above copyright notice,
13
this list of conditions and the following disclaimer in the documentation
14
and/or other materials provided with the distribution.
15
* Neither the name of virtuosic bytes nor the names of its contributors may
16
be used to endorse or promote products derived from this software without
17
specific prior written permission.
18
19
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
POSSIBILITY OF SUCH DAMAGE.
30
31
##############################################################################*/
32
#ifndef GUARD_SQLITE_DATABASE_EXCEPTION_HPP_INCLUDED
33
#define GUARD_SQLITE_DATABASE_EXCEPTION_HPP_INCLUDED
34
35
#include <stdexcept>
36
#include <string>
37
#include <utility>
38
46
namespace
sqlite
{
47
inline
namespace
v2
{
49
struct
database_exception
:
public
std::runtime_error {
50
database_exception
(std::string
const
&msg) : std::runtime_error(msg.c_str()) {}
51
};
52
54
inline
std::string
append_sql_context
(std::string message, std::string
const
&sql) {
55
if
(sql.empty()) {
56
return
message;
57
}
58
message.append(
" [SQL: "
);
59
message.append(sql);
60
message.push_back(
']'
);
61
return
message;
62
}
63
65
struct
database_exception_code
:
database_exception
{
66
database_exception_code
(std::string
const
&error_message,
int
sqlite_error_code,
67
std::string sql_context = std::string()) :
68
database_exception
(
append_sql_context
(error_message, sql_context)),
69
sqlite_error_code_
(sqlite_error_code),
sql_
(std::move(sql_context)) {}
70
71
int
error_code
()
const
{
72
return
sqlite_error_code_
;
73
}
74
75
std::string
const
&
sql
()
const
{
76
return
sql_
;
77
}
78
79
protected
:
80
int
const
sqlite_error_code_
;
81
std::string
sql_
;
82
};
83
85
struct
buffer_too_small_exception
:
public
std::runtime_error {
86
buffer_too_small_exception
(std::string
const
&msg) : std::runtime_error(msg.c_str()) {}
87
};
88
90
struct
database_misuse_exception
:
public
std::logic_error {
91
database_misuse_exception
(std::string
const
&msg) : std::logic_error(msg) {}
92
};
93
95
struct
database_misuse_exception_code
:
database_misuse_exception
{
96
database_misuse_exception_code
(std::string
const
&msg,
int
sqlite_error_code,
97
std::string sql_context = std::string()) :
98
database_misuse_exception
(
append_sql_context
(msg, sql_context)),
99
sqlite_error_code_
(sqlite_error_code),
sql_
(std::move(sql_context)) {}
100
101
int
error_code
()
const
{
102
return
sqlite_error_code_
;
103
}
104
105
std::string
const
&
sql
()
const
{
106
return
sql_
;
107
}
108
109
protected
:
110
int
const
sqlite_error_code_
;
111
std::string
sql_
;
112
};
113
115
struct
database_system_error
:
database_exception
{
116
database_system_error
(std::string
const
&msg,
int
error_code
) :
117
database_exception
(msg),
error_code_
(
error_code
) {}
118
119
int
error_code
()
const
{
120
return
error_code_
;
121
}
122
123
protected
:
124
int
error_code_
;
125
};
126
}
// namespace v2
127
}
// namespace sqlite
128
129
#endif
// GUARD_SQLITE_DATABASE_EXCEPTION_HPP_INCLUDED
sqlite::v2
Definition
backup.hpp:18
sqlite::v2::append_sql_context
std::string append_sql_context(std::string message, std::string const &sql)
Helper that appends [SQL: ...] context to an existing message.
Definition
database_exception.hpp:54
sqlite
Definition
backup.hpp:17
sqlite::buffer_too_small_exception
Raised when a caller-provided buffer is too small to hold a blob/text payload.
Definition
database_exception.hpp:85
sqlite::v2::buffer_too_small_exception::buffer_too_small_exception
buffer_too_small_exception(std::string const &msg)
Definition
database_exception.hpp:86
sqlite::database_exception_code
Exception that carries the original SQLite error code and optional SQL snippet.
Definition
database_exception.hpp:65
sqlite::v2::database_exception_code::sql
std::string const & sql() const
Definition
database_exception.hpp:75
sqlite::v2::database_exception_code::sqlite_error_code_
int const sqlite_error_code_
Definition
database_exception.hpp:80
sqlite::v2::database_exception_code::sql_
std::string sql_
Definition
database_exception.hpp:81
sqlite::v2::database_exception_code::database_exception_code
database_exception_code(std::string const &error_message, int sqlite_error_code, std::string sql_context=std::string())
Definition
database_exception.hpp:66
sqlite::v2::database_exception_code::error_code
int error_code() const
Definition
database_exception.hpp:71
sqlite::database_exception
Generic runtime failure raised for most SQLite errors.
Definition
database_exception.hpp:49
sqlite::v2::database_exception::database_exception
database_exception(std::string const &msg)
Definition
database_exception.hpp:50
sqlite::database_misuse_exception_code
Logic-error flavour that also exposes the SQLite status code and SQL string.
Definition
database_exception.hpp:95
sqlite::v2::database_misuse_exception_code::sqlite_error_code_
int const sqlite_error_code_
Definition
database_exception.hpp:110
sqlite::v2::database_misuse_exception_code::database_misuse_exception_code
database_misuse_exception_code(std::string const &msg, int sqlite_error_code, std::string sql_context=std::string())
Definition
database_exception.hpp:96
sqlite::v2::database_misuse_exception_code::sql_
std::string sql_
Definition
database_exception.hpp:111
sqlite::v2::database_misuse_exception_code::error_code
int error_code() const
Definition
database_exception.hpp:101
sqlite::v2::database_misuse_exception_code::sql
std::string const & sql() const
Definition
database_exception.hpp:105
sqlite::database_misuse_exception
Used for programming errors such as double-closing or using invalidated resources.
Definition
database_exception.hpp:90
sqlite::v2::database_misuse_exception::database_misuse_exception
database_misuse_exception(std::string const &msg)
Definition
database_exception.hpp:91
sqlite::database_system_error
Wraps system-level failures (e.g., file I/O) that bubble up from SQLite APIs.
Definition
database_exception.hpp:115
sqlite::v2::database_system_error::error_code
int error_code() const
Definition
database_exception.hpp:119
sqlite::v2::database_system_error::database_system_error
database_system_error(std::string const &msg, int error_code)
Definition
database_exception.hpp:116
sqlite::v2::database_system_error::error_code_
int error_code_
Definition
database_exception.hpp:124
Generated by
1.17.0