1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 //  Copyright (C) 2010-2011  Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
4 //
5 //  Distributed under:
6 //
7 //                   the Boost Software License, Version 1.0.
8 //              (See accompanying file LICENSE_1_0.txt or copy at
9 //                     http://www.boost.org/LICENSE_1_0.txt)
10 //
11 //  or (at your opinion) under:
12 //
13 //                               The MIT License
14 //                 (See accompanying file MIT.txt or a copy at
15 //              http://www.opensource.org/licenses/mit-license.php)
16 //
17 ///////////////////////////////////////////////////////////////////////////////
18 #ifndef CPPDB_ERRORS_H
19 #define CPPDB_ERRORS_H
20 #include <stdexcept>
21 #include <string>
22 
23 namespace cppdb {
24 	///
25 	/// \brief This is the base error of all errors thrown by cppdb.
26 	///
27 	class cppdb_error : public std::runtime_error {
28 	public:
29 		///
30 		/// Create a cppdb_error with error message \a v
31 		///
cppdb_error(std::string const & v)32 		cppdb_error(std::string const &v) : std::runtime_error(v) {}
33 	};
34 
35 	///
36 	/// \brief invalid data conversions
37 	///
38 	/// It may be thrown if the data can't be converted to required format, for example trying to fetch
39 	/// a negative value with unsigned type or parsing invalid string as datatime.
40 	///
41 	class bad_value_cast : public cppdb_error {
42 	public:
bad_value_cast()43 		bad_value_cast() : cppdb_error("cppdb::bad_value_cast can't convert data")
44 		{
45 		}
46 	};
47 
48 	///
49 	/// \brief attempt to fetch a null value.
50 	///
51 	/// Thrown by cppdb::result::get functions.
52 	///
53 	class null_value_fetch : public cppdb_error {
54 	public:
null_value_fetch()55 		null_value_fetch() : cppdb_error("cppdb::null_value_fetch attempt fetch null column")
56 		{
57 		}
58 	};
59 	///
60 	/// \brief attempt to fetch a value from the row without calling next() first time or when next() returned false.
61 	///
62 	class empty_row_access : public cppdb_error {
63 	public:
empty_row_access()64 		empty_row_access() : cppdb_error("cppdb::empty_row_access attempt to fetch from empty column")
65 		{
66 		}
67 	};
68 
69 	///
70 	/// \brief trying to fetch a value using invalid column index
71 	///
72 	class invalid_column : public cppdb_error {
73 	public:
invalid_column()74 		invalid_column() : cppdb_error("cppdb::invalid_column attempt access to invalid column")
75 		{
76 		}
77 	};
78 	///
79 	/// \brief trying to fetch a value using invalid placeholder
80 	///
81 	class invalid_placeholder : public cppdb_error {
82 	public:
invalid_placeholder()83 		invalid_placeholder() : cppdb_error("cppdb::invalid_placeholder attempt bind to invalid placeholder")
84 		{
85 		}
86 	};
87 	///
88 	/// \brief trying to fetch a single row for a query that returned multiple ones.
89 	///
90 	class multiple_rows_query : public cppdb_error {
91 	public:
multiple_rows_query()92 		multiple_rows_query() : cppdb_error(	"cppdb::multiple_rows_query "
93 							"multiple rows result for a single row request")
94 		{
95 		}
96 	};
97 
98 	///
99 	/// \brief This operation is not supported by the backend
100 	///
101 	class not_supported_by_backend : public cppdb_error {
102 	public:
103 		///
104 		/// Create a not_supported_by_backend with error message \a e
105 		///
not_supported_by_backend(std::string const & e)106 		not_supported_by_backend(std::string const &e) :
107 			cppdb_error(e)
108 		{
109 		}
110 	};
111 
112 }
113 
114 #endif
115