Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

CVS update of libmysequoia (6 files): msg#00162

db.carob.cvs

Subject: CVS update of libmysequoia (6 files)

Date: Tuesday, March 28, 2006 @ 14:25:11
Author: zsolt
Path: /cvsroot/carob/libmysequoia

Modified: include/CarobCommon.hpp (1.3 -> 1.4) include/CarobMySQL.hpp
(1.31 -> 1.32) include/CarobStmt.hpp (1.10 -> 1.11)
src/CarobCommon.cpp (1.7 -> 1.8) src/CarobMySQL.cpp (1.66 ->
1.67) src/CarobStmt.cpp (1.30 -> 1.31)

- truncation of verbose cluster error messages to mysql specific (fix for LMS-4)
- refactoring of set_error


-------------------------+
include/CarobCommon.hpp | 36 ++++++++++++++++++++++
include/CarobMySQL.hpp | 36 +++++++++-------------
include/CarobStmt.hpp | 30 +++++++++---------
src/CarobCommon.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++
src/CarobMySQL.cpp | 58 ++++++-----------------------------
src/CarobStmt.cpp | 38 ++---------------------
6 files changed, 156 insertions(+), 117 deletions(-)


Index: libmysequoia/include/CarobCommon.hpp
diff -u libmysequoia/include/CarobCommon.hpp:1.3
libmysequoia/include/CarobCommon.hpp:1.4
--- libmysequoia/include/CarobCommon.hpp:1.3 Fri Mar 3 10:57:48 2006
+++ libmysequoia/include/CarobCommon.hpp Tue Mar 28 14:25:11 2006
@@ -72,6 +72,42 @@
*/
virtual std::wstring to_wstring(const std::string &s) = 0;

+ /**
+ * 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
+ */
+ void set_error (int errcode, int sqlstate);
+
+ /**
+ * Set the current mysql error to the specified one
+ * @param errcode mysql error code
+ * @param errmsg detailed mysql error message
+ * @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);
+
+ /**
+ * Return a pointer to the last_error number in the mysql structure
+ */
+ virtual unsigned int *get_errno_ptr() = 0;
+
+ /**
+ * Return a pointer to the last_error buffer in the mysql structure
+ */
+ virtual char *get_errmsg_ptr() = 0;
+
+ /**
+ * Return a pointer to the sqlstate buffer in the mysql structure
+ */
+ virtual char *get_sqlstate_ptr() = 0;
+
+ /**
+ * Reset error codes.
+ */
+
+ virtual void reset_error();
private:
/**
* Converts a wstring to a char *.
Index: libmysequoia/include/CarobMySQL.hpp
diff -u libmysequoia/include/CarobMySQL.hpp:1.31
libmysequoia/include/CarobMySQL.hpp:1.32
--- libmysequoia/include/CarobMySQL.hpp:1.31 Fri Mar 24 10:02:40 2006
+++ libmysequoia/include/CarobMySQL.hpp Tue Mar 28 14:25:11 2006
@@ -247,6 +247,22 @@
*/
unsigned long real_escape_string (char *to, const char *from, unsigned long
length);

+protected:
+ /**
+ * Return a pointer to the last_error number in the mysql structure
+ */
+ virtual unsigned int *get_errno_ptr() { return &mysqlPtr->net.last_errno; }
+
+ /**
+ * Return a pointer to the last_error buffer in the mysql structure
+ */
+ virtual char *get_errmsg_ptr() { return mysqlPtr->net.last_error; }
+
+ /**
+ * Return a pointer to the sqlstate buffer in the mysql structure
+ */
+ virtual char *get_sqlstate_ptr() { return mysqlPtr->net.sqlstate; };
+
private:
//pointer to a MYSQL structure which is connected to this class
MYSQL * mysqlPtr;
@@ -293,26 +309,6 @@
void delete_connection ();

/**
- * 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
- */
- void set_error (int errcode, int sqlstate);
-
- /**
- * Set the current mysql error to the specified one
- * @param errcode mysql error code
- * @param errmsg detailed mysql error message
- * @param sqlstate ansi sql specific error message
- */
- void set_error (int errcode, const char *errmsg, const char *sqlstate);
-
- /**
- * Reset the error codes
- */
- void reset_error ();
-
- /**
* Allocates a row from the freshly fetched results
* @param row the resulting row
* @param fields pointer to the field structure to update the max column
length or null
Index: libmysequoia/include/CarobStmt.hpp
diff -u libmysequoia/include/CarobStmt.hpp:1.10
libmysequoia/include/CarobStmt.hpp:1.11
--- libmysequoia/include/CarobStmt.hpp:1.10 Fri Mar 3 10:57:48 2006
+++ libmysequoia/include/CarobStmt.hpp Tue Mar 28 14:25:11 2006
@@ -187,6 +187,21 @@
*/
void resetParent() {cmysql = 0; m_stmt->mysql = 0; liveResultSet = 0;}

+ /**
+ * Return a pointer to the last_error number in the mysql structure
+ */
+ virtual unsigned int *get_errno_ptr() { return &m_stmt->last_errno; }
+
+ /**
+ * Return a pointer to the last_error buffer in the mysql structure
+ */
+ virtual char *get_errmsg_ptr() { return m_stmt->last_error; }
+
+ /**
+ * Return a pointer to the sqlstate buffer in the mysql structure
+ */
+ virtual char *get_sqlstate_ptr() { return m_stmt->sqlstate; };
+
private:
//Internal MYSQL_STMT associated with the statement
MYSQL_STMT *m_stmt;
@@ -251,21 +266,6 @@
* @param stmt points to the statement which long data buffer should be
released
*/
static void free_long_data(MYSQL_STMT *stmt);
-
- /**
- * 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
- */
- void set_error (int errcode, int sqlstate);
-
- /**
- * Set the current mysql error to the specified one
- * @param errcode mysql error code
- * @param errmsg detailed mysql error message
- * @param sqlstate ansi sql specific error message
- */
- void set_error (int errcode, const char *errmsg, const char *sqlstate);
};

#endif /*_CAROBSTMT_HPP*/
Index: libmysequoia/src/CarobCommon.cpp
diff -u libmysequoia/src/CarobCommon.cpp:1.7
libmysequoia/src/CarobCommon.cpp:1.8
--- libmysequoia/src/CarobCommon.cpp:1.7 Fri Mar 3 10:57:48 2006
+++ libmysequoia/src/CarobCommon.cpp Tue Mar 28 14:25:11 2006
@@ -24,6 +24,9 @@

#include <TypeConstants.hpp>

+/* MySQL include */
+#include <errmsg.h>
+
using namespace CarobNS;
using namespace log4cxx;

@@ -117,3 +120,75 @@

LOG4CXX_DEBUG(logger, "Leaving delete_query_fields.");
}
+
+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);
+// LOG4CXX_DEBUG(logger, "Leaving set_error.");
+}
+
+void
+CarobCommon::set_error(int errcode, const char *errmsg, const char *sqlstate,
const bool chop)
+{
+ 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 = strrchr(errmsg, '(');
+ if (sf)
+ {
+ sf++;
+ const char *sl = strchr(sf, ')');
+ if (!sl)
+ sf = 0;
+ else
+ size = sl - sf - 1;
+ }
+ }
+ if (!sf)
+ {
+ sf = errmsg;
+ size = strlen(errmsg);
+ }
+
+ //buffer overflow protection
+ size = std::min(size, MYSQL_ERRMSG_SIZE-1);
+ strncpy(p, sf, size+1);
+ }
+ else
+ *get_errmsg_ptr() = 0;
+
+ if (sqlstate)
+ {
+ char *p = get_sqlstate_ptr();
+ strncpy(p, sqlstate, SQLSTATE_LENGTH);
+ p[SQLSTATE_LENGTH] = 0;
+ }
+ else
+ *get_sqlstate_ptr() = 0;
+
+ LOG4CXX_DEBUG(logger, "Leaving set_error.");
+}
+
+void
+CarobCommon::reset_error ()
+{
+ *get_errno_ptr() = 0;
+ *get_errmsg_ptr() = 0;
+ *get_sqlstate_ptr() = 0;
+}
+
Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.66
libmysequoia/src/CarobMySQL.cpp:1.67
--- libmysequoia/src/CarobMySQL.cpp:1.66 Fri Mar 24 14:00:37 2006
+++ libmysequoia/src/CarobMySQL.cpp Tue Mar 28 14:25:11 2006
@@ -25,13 +25,13 @@
#include <Utils.hpp>
#include <HostTokenizer.hpp>

-/* MySQL include */
-#include <errmsg.h>
-
/* Carob include */
#include <StringCodecs.hpp>
#include <ResultSetMetaData.hpp>

+/* MySQL include */
+#include <errmsg.h>
+
#include <cstdlib>
#include <string>
#include <algorithm>
@@ -229,7 +229,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
//TODO error handling
LOG4CXX_DEBUG(logger, "Leaving connect.");
return false;
@@ -348,7 +348,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
LOG4CXX_DEBUG(logger, "Leaving real_query: result=0");
return false;
}
@@ -449,7 +449,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
LOG4CXX_DEBUG(logger, "Leaving get_results: result=0");
return 0;
}
@@ -536,7 +536,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
result = 1;
}
}
@@ -646,7 +646,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
LOG4CXX_DEBUG(logger, "Leaving set_autocommit: result=0");
return 0;
}
@@ -684,7 +684,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
LOG4CXX_DEBUG(logger, "Leaving commit: result=0");
return 0;
}
@@ -722,7 +722,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
LOG4CXX_DEBUG(logger, "Leaving rollback: result=0");
return false;
}
@@ -881,44 +881,6 @@
}

void
-CarobMYSQL::set_error(int errcode, int sqlstate)
-{
- LOG4CXX_DEBUG(logger, "Entering set_error: errcode=" << errcode << "
sqlstate=" << sqlstate);
- set_error(errcode, client_errors[errcode-CR_MIN_ERROR],
error_sqlstate[sqlstate]);
- LOG4CXX_DEBUG(logger, "Leaving set_error.");
-}
-
-void
-CarobMYSQL::set_error(int errcode, const char *errmsg, const char *sqlstate)
-{
- LOG4CXX_DEBUG(logger, "Entering set_error: errcode=" << errcode << "
errmsg=" << errmsg << " sqlstate=" << sqlstate);
-
- LOG4CXX_ERROR(logger, "errcode=" << errcode << " errmsg=" << errmsg << "
sqlstate=" << sqlstate);
-
- mysqlPtr->net.last_errno = convert_errcode(errcode);
-
- if (errmsg)
- strcpy(mysqlPtr->net.last_error, errmsg);
- else
- *mysqlPtr->net.last_error = 0;
-
- if (sqlstate)
- strcpy(mysqlPtr->net.sqlstate, sqlstate);
- else
- *mysqlPtr->net.sqlstate = 0;
-
- LOG4CXX_DEBUG(logger, "Leaving set_error.");
-}
-
-void
-CarobMYSQL::reset_error ()
-{
- mysqlPtr->net.last_errno = 0;
- *mysqlPtr->net.last_error = 0;
- *mysqlPtr->net.sqlstate = 0;
-}
-
-void
CarobMYSQL::alloc_row_data(MYSQL_ROW &row, MYSQL_FIELD *fields, const unsigned
int field_count, unsigned long &length, unsigned long *lengths)
{
//Commented out because the debug info get unusable
Index: libmysequoia/src/CarobStmt.cpp
diff -u libmysequoia/src/CarobStmt.cpp:1.30 libmysequoia/src/CarobStmt.cpp:1.31
--- libmysequoia/src/CarobStmt.cpp:1.30 Fri Mar 24 14:00:37 2006
+++ libmysequoia/src/CarobStmt.cpp Tue Mar 28 14:25:11 2006
@@ -123,7 +123,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
result = 1;
}
}
@@ -362,7 +362,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
}
}
catch (ConverterException &e)
@@ -669,7 +669,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
result = 1;
}
}
@@ -874,7 +874,7 @@
}
catch (CarobException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str(), true);
}

LOG4CXX_DEBUG(logger, "Leaving alloc_fetch_field: result=" << result);
@@ -983,36 +983,6 @@
}

void
-CarobStmt::set_error(int errcode, int sqlstate)
-{
- LOG4CXX_DEBUG(logger, "Entering set_error: errcode=" << errcode << "
sqlstate=" << sqlstate);
- set_error(errcode, client_errors[errcode-CR_MIN_ERROR],
error_sqlstate[sqlstate]);
- LOG4CXX_DEBUG(logger, "Leaving set_error.");
-}
-
-void
-CarobStmt::set_error(int errcode, const char *errmsg, const char *sqlstate)
-{
- LOG4CXX_DEBUG(logger, "Entering set_error: errcode=" << errcode << "
errmsg=" << errmsg << " sqlstate" << sqlstate);
-
- LOG4CXX_ERROR(logger, "Entering set_error: errcode=" << errcode << "
errmsg=" << errmsg << " sqlstate" << sqlstate);
-
- m_stmt->last_errno = convert_errcode(errcode);
-
- if (errmsg)
- strcpy(m_stmt->last_error, errmsg);
- else
- *m_stmt->last_error = 0;
-
- if (sqlstate)
- strcpy(m_stmt->sqlstate, sqlstate);
- else
- *m_stmt->sqlstate = 0;
-
- LOG4CXX_DEBUG(logger, "Leaving set_error.");
-}
-
-void
CarobStmt::clear()
{
LOG4CXX_DEBUG(logger, "Entering clear.");


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | advertise | OSDir is an inevitable website. super tiny logo