blob: 03ce923a3b560bd6600b2a0a27d8a74c6c257126 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/** Definition of the pqxx::errorhandler class.
*
* pqxx::errorhandler handlers errors and warnings in a database session.
*
* DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/connection_base instead.
*
* Copyright (c) 2000-2019, Jeroen T. Vermeulen.
*
* See COPYING for copyright license. If you did not receive a file called
* COPYING with this source code, please notify the distributor of this mistake,
* or contact the author.
*/
#ifndef PQXX_H_ERRORHANDLER
#define PQXX_H_ERRORHANDLER
#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"
#include "pqxx/types.hxx"
namespace pqxx
{
namespace internal
{
namespace gate
{
class errorhandler_connection_base;
}
}
/**
* @addtogroup errorhandler
* @{
*/
/// Base class for error-handler callbacks.
/** To receive errors and warnings from a connection, subclass this with your
* own error-handler functor, and instantiate it for the connection. Destroying
* the handler un-registers it.
*
* A connection can have multiple error handlers at the same time. When the
* database connection emits an error or warning message, it passes the message
* to each error handler, starting with the most recently registered one and
* progressing towards the oldest one. However an error handler may also
* instruct the connection not to pass the message to further handlers by
* returning "false."
*
* @warning Strange things happen when a result object outlives its parent
* connection. If you register an error handler on a connection, then you must
* not access the result after destroying the connection. This applies even if
* you destroy the error handler first!
*/
class PQXX_LIBEXPORT errorhandler
{
public:
explicit errorhandler(connection_base &);
virtual ~errorhandler();
/// Define in subclass: receive an error or warning message from the database.
/**
* @return Whether the same error message should also be passed to the
* remaining, older errorhandlers.
*/
virtual bool operator()(const char msg[]) noexcept =0;
private:
connection_base *m_home;
friend class internal::gate::errorhandler_connection_base;
void unregister() noexcept;
errorhandler() =delete;
errorhandler(const errorhandler &) =delete;
errorhandler &operator=(const errorhandler &) =delete;
};
/// An error handler that suppresses any previously registered error handlers.
class quiet_errorhandler : public errorhandler
{
public:
quiet_errorhandler(connection_base &conn) : errorhandler{conn} {}
virtual bool operator()(const char[]) noexcept override { return false; }
};
/**
* @}
*/
} // namespace pqxx
#include "pqxx/compiler-internal-post.hxx"
#endif
|