Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

BadQuery w/Errnum patch part 4

From: Jim Wallace <jwallace(at)kaneva.com>
Date: Wed Oct 24 2007 - 14:42:28 EDT


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


  • 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 = "") : - 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 + /// Query or Connection errnum() value is set to zero, hiding the + /// errnum of the exception. + explicit BadQuery(const char* w = "", int err = 0) : + Exception(w), + errnum_(err) { }
    • /// \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 = 0) : + Exception(w), + 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_; } + +private: + int errnum_; ///< error number associated with execption };

Index: query.cpp


  • query.cpp (revision 1779) +++ query.cpp (working copy)
    @@ -90,7 +90,7 @@
    copacetic_ = !mysql_real_query(&conn_->mysql_, str.data(), static_cast<unsigned long>(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()); } 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


  • 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");
-- 
MySQL++ Mailing List
For list archives: 
http://lists.mysql.com/plusplus
To unsubscribe:    
http://lists.mysql.com/plusplus?unsub=lists@pantek.com
Received on Wed Oct 24 14:42:55 2007

This archive was generated by hypermail 2.1.8 : Fri Jul 04 2008 - 00:21:40 EDT

Do you need help?X

Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library