Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Subject: BadQuery w/Errnum patch part 4

Subject: BadQuery w/Errnum patch part 4

2007-10-24       - By Jim Wallace

 Back
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=mysql@(protected)