List:MySQL++« Previous MessageNext Message »
From:Jim Wallace Date:October 24 2007 6:42pm
Subject:BadQuery w/Errnum patch part 4
View as plain text  
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");

Thread
RELEASE: v2.3.2Warren Young11 Jul
  • Getting errnum() in exception?Jim Wallace20 Sep
    • Re: Getting errnum() in exception?Warren Young22 Sep
  • Building the head of SVN with MSVC?Jim Wallace25 Sep
    • Re: Building the head of SVN with MSVC?Warren Young26 Sep
  • Error num in BadQuery patchJim Wallace25 Sep
    • RE: Error num in BadQuery patchJim Wallace26 Sep
      • Re: Error num in BadQuery patchWarren Young26 Sep
    • Re: Error num in BadQuery patchWarren Young26 Sep
  • v2.3.2 and execute?Jim Wallace5 Oct
    • Re: v2.3.2 and execute?Warren Young5 Oct
  • Building svn tip on WindowsJim Wallace24 Oct
    • Re: Building svn tip on WindowsWarren Young25 Oct
  • Patch for better exception use -- BadQuery w/Errnum patch part 1Jim Wallace24 Oct
  • Better exception usage -- BadQuery w/Errnum patch part 2Jim Wallace24 Oct
  • Expose errnum() in query -- BadQuery w/Errnum patch part 3Jim Wallace24 Oct
    • Re: Expose errnum() in query -- BadQuery w/Errnum patch part 3Warren Young25 Oct
      • RE: Expose errnum() in query -- BadQuery w/Errnum patch part 3Jim Wallace25 Oct
  • BadQuery w/Errnum patch part 4Jim Wallace24 Oct
    • Re: BadQuery w/Errnum patch part 4Warren Young25 Oct
      • RE: BadQuery w/Errnum patch part 4Jim Wallace25 Oct
  • Sample files -- BadQuery w/Errnum patch part 4Jim Wallace24 Oct
    • Re: Sample files -- BadQuery w/Errnum patch part 4Warren Young25 Oct
      • RE: Sample files -- BadQuery w/Errnum patch part 4Jim Wallace25 Oct
        • Re: Sample files -- BadQuery w/Errnum patch part 4Warren Young25 Oct
          • RE: Sample files -- BadQuery w/Errnum patch part 4Jim Wallace25 Oct
          • RE: Sample files -- BadQuery w/Errnum patch part 4Jim Wallace25 Oct
            • Re: Sample files -- BadQuery w/Errnum patch part 4Warren Young25 Oct
              • RE: Sample files -- BadQuery w/Errnum patch part 4Jim Wallace25 Oct
      • RE: Sample files -- BadQuery w/Errnum patch part 4Jim Wallace25 Oct