From: Date: October 24 2007 8:42pm Subject: BadQuery w/Errnum patch part 4 List-Archive: http://lists.mysql.com/plusplus/7123 Message-Id: <5AA52B773286DA4E83B1F2D034FFED3763BDE2@mailexchange.klausatlanta.local> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Part 4 of broken up new version of BadQuery update patches after review by Warren. This is the mother lode. This is the new BadQuery exception with the new errnum parameter. See http://lists.mysql.com/plusplus/7060 for reference Diffs are from the current svn Index: exceptions.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- exceptions.h (revision 1779) +++ exceptions.h (working copy) @@ -245,17 +258,40 @@ class MYSQLPP_EXPORT BadQuery : public Exception { public: - /// \brief Create exception object, taking C string - explicit BadQuery(const char* w =3D "") : - Exception(w) + /// \brief Create exception object + /// + /// \param w the "what" error string + /// \param err the MySQL error number, usually Query::errnum() or Connection::errnum() + /// All internal set this in case the caller is using a CTransaction + /// object, in which case when the rollback() called in its destructor the=20 + /// Query or Connection errnum() value is set to zero, hiding the + /// errnum of the exception. + explicit BadQuery(const char* w =3D "", int err =3D 0) : + Exception(w),=20 + errnum_(err) { } =20 - /// \brief Create exception object, taking C++ string - explicit BadQuery(const std::string& w) : - Exception(w) + /// \brief Create exception object + /// + /// \param w the "what" error string + /// \param err the MySQL error number, usually Query::errnum() or Connection::errnum() + explicit BadQuery(const std::string& w, int err =3D 0) : + Exception(w),=20 + errnum_(err) { } + + /// \brief Return the error number for the exception when it was thrown + /// + /// This is the errnum at the time of the exception. If + /// using a CTransaction, the rollback() called in its destructor will + /// reset the Query or Connection errnum() value to zero, hiding the + /// errnum of the exception. + int what_errnum() const { return errnum_; } +=09 +private:=09 + int errnum_; ///< error number associated with execption }; =20 =20 Index: query.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- query.cpp (revision 1779) +++ query.cpp (working copy) @@ -90,7 +90,7 @@ copacetic_ =3D !mysql_real_query(&conn_->mysql_, str.data(), static_cast(str.length())); if (!copacetic_ && throw_exceptions()) { - throw BadQuery(error()); + throw BadQuery(error(), errnum()); } else { return copacetic_; @@ -131,7 +131,7 @@ return ResNSel(conn_); } else if (throw_exceptions()) { - throw BadQuery(error()); + throw BadQuery(error(), errnum()); } else { return ResNSel(); @@ -414,7 +414,7 @@ return Result(); } else { - throw BadQuery(error()); + throw BadQuery(error(), errnum()); } } } @@ -437,7 +437,7 @@ // result set, which is harmless. We return an empty result // set if exceptions are disabled, as well. if (conn_->errnum() && throw_exceptions()) { - throw BadQuery(error()); + throw BadQuery(error(), errnum()); }=20 else { return Result(); @@ -446,7 +446,7 @@ } else if (throw_exceptions()) { if (ret > 0) { - throw BadQuery(error()); + throw BadQuery(error(), errnum()); } else { throw EndOfResultSets(); @@ -520,7 +520,7 @@ return ResUse(); } else { - throw BadQuery(error()); + throw BadQuery(error(), errnum()); } } } Index: connection.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- connection.cpp (revision 1779) +++ connection.cpp (working copy) @@ -324,7 +324,7 @@ // query, but it's acceptable to signal errors with BadQuery // because the new mechanism is the FLUSH PRIVILEGES query. // A program won't have to change when doing it the new way. - throw BadQuery(error()); + throw BadQuery(error(), errnum()); } else { return suc; @@ -332,7 +332,7 @@ } else { if (throw_exceptions()) { - throw BadQuery("MySQL++ connection not established"); + throw BadQuery("MySQL++ connection not established", errnum()); } else { build_error_message("reload grant tables");