drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drizzled/error.h
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20
21#pragma once
22
23#include <string>
24#include <unordered_map>
25
26#include <drizzled/common_fwd.h>
28#include <drizzled/error/priority_t.h>
29#include <drizzled/error_t.h>
30#include <drizzled/identifier.h>
31#include <drizzled/visibility.h>
32
33#include <boost/noncopyable.hpp>
34
35namespace std {
36template<>
37struct hash<drizzled::error_t>
38{
39 size_t operator()(drizzled::error_t v) const
40 {
41 return static_cast<size_t>(v);
42 }
43};
44} /* namespace std */
45
46namespace drizzled {
47
48/* Max width of screen (for error messages) */
49#define SC_MAXWIDTH 256
50#define ERRMSGSIZE (SC_MAXWIDTH) /* Max length of a error message */
51#define MY_FILE_ERROR ((size_t) -1)
52#define ME_FATALERROR 1024 /* Fatal statement error */
53
54/*
55 * Provides a mapping from the error enum values to std::strings.
56 */
57class ErrorMap : boost::noncopyable
58{
59public:
60 typedef std::pair<std::string, std::string> value_type;
61 typedef std::unordered_map<error_t, value_type> ErrorMessageMap;
62
63 ErrorMap();
64
65 // Insert the message for the error. If the error already has an existing
66 // mapping, an error is logged, but the function continues.
67 void add(error_t error_num, const std::string &error_name, const std::string &message);
68
69 const std::string* find(error_t error_num) const;
70
71 static const ErrorMessageMap& get_error_message_map();
72private:
73 ErrorMessageMap mapping_;
74};
75
76typedef void (*error_handler_func)(error_t my_err,
77 const char *str,
78 myf MyFlags);
79extern error_handler_func error_handler_hook;
80
81// TODO: kill this method. Too much to do with this branch.
82// This is called through the ER(x) macro.
83DRIZZLED_API const char * error_message(error_t err_index);
84
85// Adds the message to the global error dictionary.
86void add_error_message(error_t error_code, const std::string &error_name,
87 const std::string& message);
88#define DRIZZLE_ADD_ERROR_MESSAGE(code, msg) add_error_message(code, STRINGIFY_ARG(code), msg)
89
90namespace error {
91
92void access(const identifier::User&);
93void access(const identifier::User&, const identifier::Schema&);
94void access(const identifier::User&, const identifier::Table&);
95
96const std::string &verbose_string();
97error::priority_t &verbosity();
98void check_verbosity(const std::string &arg);
99
100} // namespace error
101
102
103DRIZZLED_API void my_error(const std::string &ref, error_t nr, myf MyFlags= MYF(0));
104DRIZZLED_API void my_error(error_t nr, const Identifier&, myf MyFlags= MYF(0));
105DRIZZLED_API void my_error(error_t nr);
106DRIZZLED_API void my_error(error_t nr, myf MyFlags, ...);
107void my_message(error_t my_err, const char *str, myf MyFlags);
108void my_printf_error(error_t my_err, const char *format,
109 myf MyFlags, ...)
110 __attribute__((format(printf, 2, 4)));
111
112} /* namespace drizzled */
A set of Session members describing the current authenticated user.
TODO: Rename this file - func.h is stupid.
STL namespace.
Visibility Control Macros.
#define DRIZZLED_API
Definition visibility.h:38