00001 #ifndef MYSQLPP_EXCEPTIONS_H
00002 #define MYSQLPP_EXCEPTIONS_H
00003
00010
00011 #include <exception>
00012 #include <string>
00013
00014 namespace mysqlpp {
00015
00022
00023 class BadQuery : public std::exception {
00024 public:
00025 BadQuery(const std::string &er = "") : error(er) {}
00026 ~BadQuery() throw () {}
00027 const std::string error;
00028 virtual const char* what( void ) const throw () { return error.c_str(); }
00029 };
00030
00031
00033
00034 class BadConversion : public std::exception {
00035 const std::string _what;
00036 public:
00037 const char* type_name;
00038 const std::string data;
00039 size_t retrieved;
00040 size_t actual_size;
00041 BadConversion(const char* tn, const char* d, size_t r, size_t a)
00042 : _what(std::string("Tried to convert \"") + std::string(d ? d : "") + "\" to a \"" + std::string(tn ? tn : "")),
00043 type_name(tn), data(d), retrieved(r), actual_size(a) {};
00044
00045 BadConversion(const std::string &wt, const char* tn, const char* d, size_t r, size_t a)
00046 : _what(wt), type_name(tn), data(d), retrieved(r), actual_size(a) {};
00047
00048 BadConversion(const std::string& wt = "")
00049 : _what(wt), type_name("unknown"), data(""), retrieved(0), actual_size(0) {};
00050 ~BadConversion() throw () {}
00051
00052 virtual const char* what( void ) const throw () { return _what.c_str(); }
00053 };
00054
00055
00058
00059 class BadNullConversion : public std::exception {
00060 const std::string _what;
00061 public:
00062 BadNullConversion(const std::string &wt = "") : _what(wt) {}
00063 ~BadNullConversion() throw () {}
00064 virtual const char* what( void ) const throw () { return _what.c_str(); }
00065 };
00066
00067
00072
00073 class SQLQueryNEParms : public std::exception {
00074 const std::string _what;
00075 public:
00076 SQLQueryNEParms(const char *c) : _what(std::string(c ? c : "")), error(c) {}
00077 ~SQLQueryNEParms() throw () {}
00078 const char* error;
00079 virtual const char* what( void ) const throw () { return _what.c_str(); }
00080 };
00081
00082
00087
00088 class BadFieldName : public std::exception {
00089 std::string _what;
00090 public:
00091 BadFieldName(const char *bad_field)
00092 {
00093 _what = "Unknown field name: ";
00094 _what += bad_field;
00095 }
00096 ~BadFieldName() throw() {}
00097 virtual const char* what( void ) const throw () { return _what.c_str(); }
00098 };
00099
00100 }
00101
00102 #endif
00103