Date: Tuesday, April 18, 2006 @ 11:50:34
Author: csaba
Path: /cvsroot/carob/libmysequoia
Modified: include/CarobCommon.hpp (1.4 -> 1.5) src/CarobCommon.cpp (1.10
-> 1.11) src/CarobMySQL.cpp (1.71 -> 1.72) src/CarobStmt.cpp
(1.33 -> 1.34)
Extract the real MySQL exception from the chained BackendException. Fix for
LMS-4
-------------------------+
include/CarobCommon.hpp | 9 ++++++-
src/CarobCommon.cpp | 59 +++++++++++++++++++++-------------------------
src/CarobMySQL.cpp | 55 +++++++++++++++++++++++++++++++++++++-----
src/CarobStmt.cpp | 26 +++++++++++++++++---
4 files changed, 106 insertions(+), 43 deletions(-)
Index: libmysequoia/include/CarobCommon.hpp
diff -u libmysequoia/include/CarobCommon.hpp:1.4
libmysequoia/include/CarobCommon.hpp:1.5
--- libmysequoia/include/CarobCommon.hpp:1.4 Tue Mar 28 14:25:11 2006
+++ libmysequoia/include/CarobCommon.hpp Tue Apr 18 11:50:34 2006
@@ -27,6 +27,7 @@
// carob includes
#include <ResultSetMetaData.hpp>
+#include <CarobException.hpp>
// include log4cxx header files.
#include <log4cxx/logger.h>
@@ -74,6 +75,12 @@
/**
* Set the current mysql error to the specified one. The mysql error message
will be filled from the error list.
+ * @param e backend exception
+ */
+ void set_error (CarobNS::BackendException &e);
+
+ /**
+ * Set the current mysql error to the specified one. The mysql error message
will be filled from the error list.
* @param errcode mysql error code
* @param sqlstate ansi sql specific error code
*/
@@ -86,7 +93,7 @@
* @param sqlstate ansi sql specific error message
* @param chop indicate to extract a MySQL specific message from the verbose
cluster error.
*/
- void set_error (int errcode, const char *errmsg, const char *sqlstate, const
bool chop = false);
+ void set_error (int errcode, const char *errmsg, const char *sqlstate);
/**
* Return a pointer to the last_error number in the mysql structure
Index: libmysequoia/src/CarobCommon.cpp
diff -u libmysequoia/src/CarobCommon.cpp:1.10
libmysequoia/src/CarobCommon.cpp:1.11
--- libmysequoia/src/CarobCommon.cpp:1.10 Thu Mar 30 11:53:42 2006
+++ libmysequoia/src/CarobCommon.cpp Tue Apr 18 11:50:34 2006
@@ -122,53 +122,50 @@
}
void
+CarobCommon::set_error(BackendException &e)
+{
+ LOG4CXX_ERROR(logger, "errcode=" << e.getErrorCode() << " errmsg=" <<
from_wstring(e.description()).c_str() << " sqlstate=" <<
from_wstring(e.getSQLState()).c_str());
+
+ const CarobException *be = 0, *ce = e.getNext();
+ /* go to the tail of the chain to get the real MySQL error */
+ while (ce)
+ {
+ be = ce;
+ ce = ce->getNext();
+ }
+
+ if (be)
+ {
+ set_error(be->getErrorCode(), from_wstring(be->description()).c_str(),
from_wstring(be->getSQLState()).c_str());
+ }
+ else
+ {
+ LOG4CXX_ERROR(logger, "No chained exception in this BackendException");
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ }
+}
+
+void
CarobCommon::set_error(int errcode, int sqlstate)
{
//Commented out because of too much debug info
// LOG4CXX_DEBUG(logger, "Entering set_error: errcode=" << errcode << "
sqlstate=" << sqlstate);
- set_error(errcode, client_errors[errcode-CR_MIN_ERROR],
error_sqlstate[sqlstate], false);
+ set_error(errcode, client_errors[errcode-CR_MIN_ERROR],
error_sqlstate[sqlstate]);
// LOG4CXX_DEBUG(logger, "Leaving set_error.");
}
void
-CarobCommon::set_error(int errcode, const char *errmsg, const char *sqlstate,
const bool chop)
+CarobCommon::set_error(int errcode, const char *errmsg, const char *sqlstate)
{
LOG4CXX_DEBUG(logger, "Entering set_error");
- LOG4CXX_ERROR(logger, "errcode=" << errcode << " errmsg=" << errmsg << "
sqlstate=" << sqlstate);
-
*get_errno_ptr() = convert_errcode(errcode);
if (errmsg)
{
char *p = get_errmsg_ptr();
- const char *sf = 0;
- int size;
-
- //need some chopping from strings like "xxxyyy (err msg)"
- if (chop)
- {
- sf = strchr(errmsg, '(');
- if (sf)
- {
- sf++;
- const char *sl = strrchr(sf, ')');
- if (!sl)
- sf = 0;
- else
- size = sl - sf;
- }
- }
- if (!sf)
- {
- sf = errmsg;
- size = strlen(errmsg);
- }
-
- //buffer overflow protection
- size = std::min(size, MYSQL_ERRMSG_SIZE-1);
- strncpy(p, sf, size);
- p[size] = 0;
+ strncpy(p, errmsg, MYSQL_ERRMSG_SIZE);
+ p[MYSQL_ERRMSG_SIZE] = 0;
}
else
*get_errmsg_ptr() = 0;
Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.71
libmysequoia/src/CarobMySQL.cpp:1.72
--- libmysequoia/src/CarobMySQL.cpp:1.71 Tue Apr 11 11:06:44 2006
+++ libmysequoia/src/CarobMySQL.cpp Tue Apr 18 11:50:34 2006
@@ -227,9 +227,15 @@
LOG4CXX_DEBUG(logger, "Leaving connect.");
return true;
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ LOG4CXX_DEBUG(logger, "Leaving connect.");
+ return false;
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
//TODO error handling
LOG4CXX_DEBUG(logger, "Leaving connect.");
return false;
@@ -356,9 +362,15 @@
LOG4CXX_DEBUG(logger, "Leaving real_query: result=1");
return true;
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ LOG4CXX_DEBUG(logger, "Leaving real_query: result=0.");
+ return false;
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
LOG4CXX_DEBUG(logger, "Leaving real_query: result=0");
return false;
}
@@ -457,9 +469,15 @@
LOG4CXX_DEBUG(logger, "Leaving get_results: result=0");
return 0;
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ LOG4CXX_DEBUG(logger, "Leaving get_results: result=0.");
+ return 0;
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
LOG4CXX_DEBUG(logger, "Leaving get_results: result=0");
return 0;
}
@@ -544,9 +562,14 @@
reset_error();
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ result = 1;
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
result = 1;
}
}
@@ -654,9 +677,15 @@
return true;
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ LOG4CXX_DEBUG(logger, "Leaving set_autocommit: result=0");
+ return 0;
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
LOG4CXX_DEBUG(logger, "Leaving set_autocommit: result=0");
return 0;
}
@@ -692,9 +721,15 @@
return true;
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ LOG4CXX_DEBUG(logger, "Leaving commit: result=0");
+ return 0;
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
LOG4CXX_DEBUG(logger, "Leaving commit: result=0");
return 0;
}
@@ -730,9 +765,15 @@
return true;
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ LOG4CXX_DEBUG(logger, "Leaving rollback: result=0");
+ return false;
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
LOG4CXX_DEBUG(logger, "Leaving rollback: result=0");
return false;
}
Index: libmysequoia/src/CarobStmt.cpp
diff -u libmysequoia/src/CarobStmt.cpp:1.33 libmysequoia/src/CarobStmt.cpp:1.34
--- libmysequoia/src/CarobStmt.cpp:1.33 Mon Apr 10 09:34:50 2006
+++ libmysequoia/src/CarobStmt.cpp Tue Apr 18 11:50:34 2006
@@ -122,9 +122,14 @@
LOG4CXX_DEBUG(logger, "Prepare: errno=" << e.getErrorCode() << "
error=" << from_wstring(e.description()));
}
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ result = 1;
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
result = 1;
}
}
@@ -361,9 +366,13 @@
m_stmt->state = MYSQL_STMT_EXECUTE_DONE;
result = 0;
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
}
}
catch (ConverterException &e)
@@ -668,9 +677,14 @@
liveResultSet = 0;
}
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ result = 1;
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
result = 1;
}
}
@@ -873,9 +887,13 @@
catch (NullValueException)
{
}
+ catch (BackendException &e)
+ {
+ set_error(e);
+ }
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
}
LOG4CXX_DEBUG(logger, "Leaving alloc_fetch_field: result=" << result);
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits