Overview
Features
Download
Documentation
Community
Add-Ons & Services

MySQL error codes patch

Please post support and help requests here.

MySQL error codes patch

Postby hanzz » 18 Oct 2009, 09:22

Hi,
I have written simple patch for Data::MySQL which properly sets Poco::Exception::code for MySQL statement errors. It would be really cool if it can be accepted to official Poco branch.

I also wanted to add mysql_ping support, but I don't know how this function can be called from my application (I mean we have addProperty and addFeature functions in SessionImp class, but there is no way to just call some specific backend function such as mysql_ping). Do you have some ideas where can I "put" mysql_ping code to be able to call it from my app?

Code: Select all
diff --git a/Data/MySQL/include/Poco/Data/MySQL/MySQLException.h b/Data/MySQL/include/Poco/Data/MySQL/MySQLException.h
index a0ffc7c..35de97b 100644
--- a/Data/MySQL/include/Poco/Data/MySQL/MySQLException.h
+++ b/Data/MySQL/include/Poco/Data/MySQL/MySQLException.h
@@ -59,7 +59,7 @@ class MySQL_API MySQLException: public Poco::Data::DataException
    /// Base class for all MySQL exceptions
 {
 public:
-   MySQLException(const std::string& msg);
+   MySQLException(const std::string& msg, int code = 0);
       /// Creates MySQLException.
 
    MySQLException(const MySQLException& exc);
@@ -112,7 +112,7 @@ class StatementException : public MySQLException
    /// StatementException
 {
 public:
-   StatementException(const std::string& msg);
+   StatementException(const std::string& msg, int code = 0);
       /// Creates StatementException.
 
    StatementException(const std::string& text, MYSQL_STMT* h, const std::string& stmt = "");
diff --git a/Data/MySQL/src/MySQLException.cpp b/Data/MySQL/src/MySQLException.cpp
index dd2ab13..588bbc2 100644
--- a/Data/MySQL/src/MySQLException.cpp
+++ b/Data/MySQL/src/MySQLException.cpp
@@ -44,7 +44,7 @@ namespace Data {
 namespace MySQL {
 
 
-MySQLException::MySQLException(const std::string& msg) : Poco::Data::DataException(std::string("[MySQL]: ") + msg)
+MySQLException::MySQLException(const std::string& msg, int code) : Poco::Data::DataException(std::string("[MySQL]: ") + msg, code)
 {
 }
 
@@ -69,12 +69,12 @@ ConnectionException::ConnectionException(const std::string& text, MYSQL* h) : My
 }
 
 
-StatementException::StatementException(const std::string& msg) : MySQLException(msg)
+StatementException::StatementException(const std::string& msg, int code) : MySQLException(msg, code)
 {
 }
 
 
-StatementException::StatementException(const std::string& text, MYSQL_STMT* h, const std::string& stmt) : MySQLException(compose(text, h, stmt))
+StatementException::StatementException(const std::string& text, MYSQL_STMT* h, const std::string& stmt) : MySQLException(compose(text, h, stmt), mysql_stmt_errno(h))
 {
 }
 
hanzz
 
Posts: 7
Joined: 28 Aug 2009, 21:29

Re: MySQL error codes patch

Postby alex » 18 Oct 2009, 13:59

hanzz wrote:I have written simple patch for Data::MySQL which properly sets Poco::Exception::code for MySQL statement errors. It would be really cool if it can be accepted to official Poco branch.

Thank you. Can you please specify to which release the patch applies and file it in Sourceforge tracker, under patches and we'll look into it for the next release.
hanzz wrote:Do you have some ideas where can I "put" mysql_ping code to be able to call it from my app?

Yes::
Code: Select all
bool SessionImpl::isConnected()
{
   return _connected = mysql_ping(_mysql); // _mysql has been renamed to _handle in the trunk
}

It would be a good idea to explicitly disable the MYSQL_OPT_RECONNECT option which for some versions is enabled by default. See documentation for more details.
alex
 
Posts: 1143
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: MySQL error codes patch

Postby hanzz » 18 Oct 2009, 14:37

alex wrote:
hanzz wrote:I have written simple patch for Data::MySQL which properly sets Poco::Exception::code for MySQL statement errors. It would be really cool if it can be accepted to official Poco branch.

Thank you. Can you please specify to which release the patch applies and file it in Sourceforge tracker, under patches and we'll look into it for the next release.


Thank you for response. I think I've added all informations you need to the ticket tracker (http://sourceforge.net/tracker/index.ph ... _id=132964).

I will also add mysql_ping patch there as another separate ticket when it will be ready.

Thanks for your help
hanzz
 
Posts: 7
Joined: 28 Aug 2009, 21:29


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron