Date: Thursday, December 15, 2005 @ 13:31:25
Author: csaba
Path: /cvsroot/carob/libmysequoia
Modified: include/CarobMySQL.hpp (1.13 -> 1.14) src/CarobMySQL.cpp (1.19
-> 1.20) src/MySQLAPI.cpp (1.15 -> 1.16)
Added logging to the CarobMYSQL class also.
------------------------+
include/CarobMySQL.hpp | 20 ++++-
src/CarobMySQL.cpp | 159 +++++++++++++++++++++++++++++++++++++++++------
src/MySQLAPI.cpp | 2
3 files changed, 154 insertions(+), 27 deletions(-)
Index: libmysequoia/include/CarobMySQL.hpp
diff -u libmysequoia/include/CarobMySQL.hpp:1.13
libmysequoia/include/CarobMySQL.hpp:1.14
--- libmysequoia/include/CarobMySQL.hpp:1.13 Thu Dec 15 12:45:36 2005
+++ libmysequoia/include/CarobMySQL.hpp Thu Dec 15 13:31:25 2005
@@ -31,6 +31,9 @@
#include <DriverResultSet.hpp>
#include <Statement.hpp>
+// include log4cxx header files.
+#include <log4cxx/logger.h>
+
const unsigned long MYSEQUOIA_MAGIC = 0xC00CA10B;
#define CAROB_MYSQL_CLIENT_INFO "5.0.15";
@@ -149,7 +152,9 @@
/**
* Set the autocommit mode. If autocommit is on then all SQL statements
will
* be executed and commited as individual transactions.
- * @param mode - true set autocommit on
+ * @param mode - true set autoc CarobMYSQL(MYSQL *mysql, my_bool
free_me);
+ ~CarobMYSQL();
+ * ommit on
* false set autocommit off
* @return true on success otherwise false
*/
@@ -195,14 +200,17 @@
MYSQL *getMYSQL ();
private:
- MYSQL * mysqlPtr;
- CarobNS::Connection * connectionPtr;
- CarobNS::ConnectionPool * connectionPool;
- CarobNS::Statement * stmtPtr;
- CarobNS::DriverResultSet * drsPtr;
+ MYSQL * mysqlPtr;
+ CarobNS::Connection * connectionPtr;
+ CarobNS::ConnectionPool * connectionPool;
+ CarobNS::Statement * stmtPtr;
+ CarobNS::DriverResultSet * drsPtr;
//holds the result set for 'live' type of results
MYSQL_RES *liveResultPtr;
+ // logger
+ static log4cxx::LoggerPtr logger;
+
/**
* Private default constructor.
*/
Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.19
libmysequoia/src/CarobMySQL.cpp:1.20
--- libmysequoia/src/CarobMySQL.cpp:1.19 Thu Dec 15 12:43:30 2005
+++ libmysequoia/src/CarobMySQL.cpp Thu Dec 15 13:31:25 2005
@@ -28,10 +28,15 @@
#include <errmsg.h>
using namespace CarobNS;
+using namespace log4cxx;
+
+LoggerPtr CarobMYSQL::logger(Logger::getLogger("MySQLAPI.Carob"));
CarobMYSQL::CarobMYSQL (MYSQL *mysql, my_bool free_me) :
connectionPtr(0), stmtPtr(0), drsPtr(0), liveResultPtr(0)
{
+ LOG4CXX_DEBUG(logger, "Entering constructor.");
+
/* initialize the mysql structure */
memset(mysql, 0, sizeof(MYSQL));
@@ -45,10 +50,14 @@
mysqlPtr = mysql;
connectionPool = &ConnectionPool::getInstance();
+
+ LOG4CXX_DEBUG(logger, "Leaving constructor.");
}
CarobMYSQL::~CarobMYSQL ()
{
+ LOG4CXX_DEBUG(logger, "Entering destructor.");
+
delete_connection();
FREE_AND_NULL_ARRAY(mysqlPtr->host);
@@ -60,6 +69,8 @@
mysqlPtr->thd = 0;
mysqlPtr->extra_info = 0;
+
+ LOG4CXX_DEBUG(logger, "Leaving destructor.");
}
bool
@@ -67,15 +78,19 @@
const char *passwd, const char *db, unsigned int port,
const char *unix_socket, unsigned long clientflag)
{
+ LOG4CXX_DEBUG(logger, "Entering connect.");
+
if (mysqlPtr->status != MYSQL_STATUS_READY)
{
set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
- return 0;
+ LOG4CXX_DEBUG(logger, "Leaving connect.");
+ return false;
}
if (unix_socket)
{
set_error(CR_NOT_IMPLEMENTED, SQLT_UNKNOWN);
+ LOG4CXX_DEBUG(logger, "Leaving connect.");
return false;
}
@@ -83,6 +98,7 @@
if (!user || !*user)
{
set_error(CR_NULL_POINTER, SQLT_UNKNOWN);
+ LOG4CXX_DEBUG(logger, "Leaving connect.");
return false;
}
@@ -101,7 +117,8 @@
{
delete_connection();
set_connect_info(host, user, passwd, 0, port);
-
+
+ LOG4CXX_DEBUG(logger, "Leaving connect.");
return true;
}
@@ -122,44 +139,61 @@
// Commented out because of bug in Carob when setting fetchsize 1
// stmtPtr->setFetchSize(1);
}
-
+
+ LOG4CXX_DEBUG(logger, "Leaving connect.");
return true;
}
catch (CarobException &e)
{
set_error(e.getErrorCode(), toString(e.description()).c_str(),
toString(e.getSQLState()).c_str());
//TODO error handling
- return 0;
+ LOG4CXX_DEBUG(logger, "Leaving connect.");
+ return false;
}
}
bool
CarobMYSQL::select_db (const char *db)
{
+ bool result;
+
+ LOG4CXX_DEBUG(logger, "Entering select_db.");
/* Connect only if a user, password and host was already specified,
otherwise raise an error */
if (mysqlPtr->user && mysqlPtr->passwd && mysqlPtr->host)
- return connect(mysqlPtr->host, mysqlPtr->user, mysqlPtr->passwd, db,
mysqlPtr->port,
+ result = connect(mysqlPtr->host, mysqlPtr->user, mysqlPtr->passwd, db,
mysqlPtr->port,
0, mysqlPtr->client_flag);
else
{
set_error(CR_NULL_POINTER, SQLT_UNKNOWN);
- return false;
+ result = false;
}
+ LOG4CXX_DEBUG(logger, "Leaving select_db.");
+
+ return result;
}
bool
CarobMYSQL::change_user (const char *user, const char *passwd, const char *db)
{
- return connect(mysqlPtr->host, user, passwd, db ? db : mysqlPtr->db,
mysqlPtr->port, 0, mysqlPtr->client_flag);
+ bool result;
+
+ LOG4CXX_DEBUG(logger, "Entering change_user.");
+ result = connect(mysqlPtr->host, user, passwd, db ? db : mysqlPtr->db,
mysqlPtr->port, 0, mysqlPtr->client_flag);
+ LOG4CXX_DEBUG(logger, "Leaving change_user.");
+
+ return result;
}
bool
CarobMYSQL::real_query (const char *query, ulong length)
{
+ LOG4CXX_DEBUG(logger, "Entering real_query.");
+
if (mysqlPtr->status != MYSQL_STATUS_READY || !connectionPtr)
{
set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
- return 0;
+ LOG4CXX_DEBUG(logger, "Leaving real_query.");
+ return false;
}
try {
@@ -181,13 +215,16 @@
info[sizeof(info)-1] = 0;
mysqlPtr->info = cstrdup(info);
}
-
+
+ LOG4CXX_DEBUG(logger, "Leaving real_query.");
return true;
}
catch (CarobException &e)
{
set_error(e.getErrorCode(), toString(e.description()).c_str(),
toString(e.getSQLState()).c_str());
//TODO error handling
+
+ LOG4CXX_DEBUG(logger, "Leaving real_query.");
return false;
}
}
@@ -195,9 +232,11 @@
MYSQL_RES *
CarobMYSQL::get_results (my_bool fetch_all)
{
+ LOG4CXX_DEBUG(logger, "Entering get_results.");
if (mysqlPtr->status != MYSQL_STATUS_GET_RESULT)
{
set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
+ LOG4CXX_DEBUG(logger, "Leaving get_results.");
return 0;
}
@@ -205,6 +244,7 @@
if (drsPtr)
{
set_error(CR_FETCH_CANCELED, SQLT_UNKNOWN);
+ LOG4CXX_DEBUG(logger, "Leaving get_results.");
return 0;
}
try {
@@ -266,24 +306,30 @@
else
set_error(CR_NO_RESULT_SET, SQLT_UNKNOWN);
+ LOG4CXX_DEBUG(logger, "Leaving get_results.");
return result;
}
- return NULL;
+ LOG4CXX_DEBUG(logger, "Leaving get_results.");
+ return 0;
}
catch (CarobException &e)
{
set_error(e.getErrorCode(), toString(e.description()).c_str(),
toString(e.getSQLState()).c_str());
//TODO error handling
- return NULL;
+ LOG4CXX_DEBUG(logger, "Leaving get_results.");
+ return 0;
}
}
MYSQL_ROW
CarobMYSQL::fetch_row()
{
+ LOG4CXX_DEBUG(logger, "Entering fetch_row.");
+
if (mysqlPtr->status != MYSQL_STATUS_USE_RESULT || !drsPtr)
{
set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
+ LOG4CXX_DEBUG(logger, "Leaving fetch_row.");
return 0;
}
@@ -292,12 +338,14 @@
delete_row_data(liveResultPtr->row, liveResultPtr->field_count);
unsigned long len;
alloc_row_data(liveResultPtr->row, liveResultPtr->fields,
liveResultPtr->field_count, len, liveResultPtr->lengths);
+ LOG4CXX_DEBUG(logger, "Leaving fetch_row.");
return (liveResultPtr->current_row = liveResultPtr->row);
}
else
{
liveResultPtr->eof = 1;
liveResultPtr->current_row = 0;
+ LOG4CXX_DEBUG(logger, "Leaving fetch_row.");
return 0;
}
}
@@ -305,13 +353,20 @@
bool
CarobMYSQL::more_results ()
{
- return stmtPtr ? stmtPtr->moreResults() : 0;
+ bool result;
+
+ LOG4CXX_DEBUG(logger, "Entering more_results.");
+ result = stmtPtr ? stmtPtr->moreResults() : 0;
+ LOG4CXX_DEBUG(logger, "Leaving more_results.");
+
+ return result;
}
int
CarobMYSQL::next_result ()
{
int result = -1;
+ LOG4CXX_DEBUG(logger, "Entering next_results.");
if (stmtPtr)
{
@@ -331,12 +386,14 @@
}
}
+ LOG4CXX_DEBUG(logger, "Leaving next_results.");
return result;
}
void
CarobMYSQL::free_results (MYSQL_RES * res)
{
+ LOG4CXX_DEBUG(logger, "Entering free_results.");
if (res)
{
if (res == liveResultPtr)
@@ -375,31 +432,38 @@
delete res;
}
mysqlPtr->status = MYSQL_STATUS_READY;
+ LOG4CXX_DEBUG(logger, "Leaving free_results.");
}
bool
CarobMYSQL::eof ()
{
+ LOG4CXX_DEBUG(logger, "Entering eof.");
+ LOG4CXX_DEBUG(logger, "Leaving eof.");
return 0;
}
bool
CarobMYSQL::set_autocommit (const my_bool mode)
{
+ LOG4CXX_DEBUG(logger, "Entering set_autocommit.");
if (mysqlPtr->status != MYSQL_STATUS_READY || !connectionPtr)
{
set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
+ LOG4CXX_DEBUG(logger, "Leaving set_autocommit.");
return 0;
}
try
{
connectionPtr->setAutoCommit(mode);
+ LOG4CXX_DEBUG(logger, "Leaving set_autocommit.");
return true;
}
catch (CarobException &e)
{
set_error(e.getErrorCode(), toString(e.description()).c_str(),
toString(e.getSQLState()).c_str());
+ LOG4CXX_DEBUG(logger, "Leaving set_autocommit.");
return 0;
}
}
@@ -407,20 +471,24 @@
bool
CarobMYSQL::commit ()
{
+ LOG4CXX_DEBUG(logger, "Entering commit.");
if (mysqlPtr->status != MYSQL_STATUS_READY || !connectionPtr)
{
set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
+ LOG4CXX_DEBUG(logger, "Leaving commit.");
return 0;
}
try
{
connectionPtr->commit();
+ LOG4CXX_DEBUG(logger, "Leaving commit.");
return true;
}
catch (CarobException &e)
{
set_error(e.getErrorCode(), toString(e.description()).c_str(),
toString(e.getSQLState()).c_str());
+ LOG4CXX_DEBUG(logger, "Leaving commit.");
return 0;
}
}
@@ -428,63 +496,91 @@
bool
CarobMYSQL::rollback ()
{
+ LOG4CXX_DEBUG(logger, "Entering rollback.");
if (mysqlPtr->status != MYSQL_STATUS_READY || !connectionPtr)
{
set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
- return 0;
+ LOG4CXX_DEBUG(logger, "Leaving rollback.");
+ return false;
}
try
{
connectionPtr->rollback();
+ LOG4CXX_DEBUG(logger, "Leaving rollback.");
return true;
}
catch (CarobException &e)
{
set_error(e.getErrorCode(), toString(e.description()).c_str(),
toString(e.getSQLState()).c_str());
- return 0;
+ LOG4CXX_DEBUG(logger, "Leaving rollback.");
+ return false;
}
}
MYSQL_RES *
CarobMYSQL::list_table_fields (const char *table, const char *wild)
{
+ MYSQL_RES *result;
+
+ LOG4CXX_DEBUG(logger, "Entering list_table_fields.");
+
std::string query=std::string("SHOW FIELDS FROM ")+table;
+
if (wild)
query = query + " LIKE '"+wild+"'";
if (real_query(query.c_str(),query.length()))
- return get_results(true);
+ result = get_results(true);
else
- return 0;
+ result = 0;
+
+ LOG4CXX_DEBUG(logger, "Leaving list_table_fields.");
+ return result;
}
MYSQL_RES *
CarobMYSQL::list_databases (const char *wild)
{
+ MYSQL_RES *result;
+
+ LOG4CXX_DEBUG(logger, "Entering list_databases.");
+
std::string query="SHOW DATABASES";
if (wild)
query = query + " LIKE '"+wild+"'";
if (real_query(query.c_str(),query.length()))
- return get_results(true);
+ result = get_results(true);
else
- return 0;
+ result = 0;
+
+ LOG4CXX_DEBUG(logger, "Leaving list_databases.");
+ return result;
}
MYSQL_RES *
CarobMYSQL::list_tables (const char *wild)
{
+ MYSQL_RES *result;
+
+ LOG4CXX_DEBUG(logger, "Entering list_tables.");
+
std::string query="SHOW TABLES";
if (wild)
query = query + "LIKE '"+wild+"'";
if (real_query(query.c_str(),query.length()))
- return get_results(true);
+ result = get_results(true);
else
- return 0;
+ result = 0;
+
+ LOG4CXX_DEBUG(logger, "Leaving list_tables.");
+ return result;
}
MYSQL *
CarobMYSQL::getMYSQL ()
{
+ LOG4CXX_DEBUG(logger, "Entering getMYSQL.");
+ LOG4CXX_DEBUG(logger, "Leaving getMYSQL.");
return mysqlPtr;
}
@@ -492,6 +588,8 @@
CarobMYSQL::set_connect_info(const char *host, const char *user,
const char *passwd, const char *db, unsigned int port)
{
+ LOG4CXX_DEBUG(logger, "Entering set_connect_info.");
+
cstrdupcond(mysqlPtr->host, host);
cstrdupcond(mysqlPtr->user, user);
cstrdupcond(mysqlPtr->passwd, passwd);
@@ -501,27 +599,34 @@
char buf[100];
snprintf(buf, sizeof(buf), "%s via TCP/IP", host); buf[sizeof(buf)-1]='\0';
cstrdupcond(mysqlPtr->host_info, buf);
+
+ LOG4CXX_DEBUG(logger, "Leaving set_connect_info.");
}
void
CarobMYSQL::delete_connection()
{
+ LOG4CXX_DEBUG(logger, "Entering delete_connection.");
if (liveResultPtr)
free_results(liveResultPtr);
FREE_AND_NULL(connectionPtr);
FREE_AND_NULL(stmtPtr);
FREE_AND_NULL(liveResultPtr);
+ LOG4CXX_DEBUG(logger, "Leaving delete_connection.");
}
void
CarobMYSQL::set_error(int errcode, int sqlstate)
{
+ LOG4CXX_DEBUG(logger, "Entering set_error.");
set_error(errcode, error_messages[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.");
mysqlPtr->net.last_errno = convert_errcode(errcode);
if (errmsg)
strcpy(mysqlPtr->net.last_error, errmsg);
@@ -531,11 +636,14 @@
strcpy(mysqlPtr->net.sqlstate, sqlstate);
else
*mysqlPtr->net.sqlstate = 0;
+ LOG4CXX_DEBUG(logger, "Leaving set_error.");
}
int
CarobMYSQL::get_query_fields(MYSQL_FIELD * &result, DriverResultSet *rsPtr)
{
+ LOG4CXX_DEBUG(logger, "Entering get_query_fields.");
+
ResultSetMetaData rsmd(rsPtr);
int colNum = (int)rsmd.getColumnCount(), colNo;
@@ -570,12 +678,15 @@
NO_DEFAULT_VALUE_FLAG;
}
+ LOG4CXX_DEBUG(logger, "Leaving get_query_fields.");
return colNum;
}
void
CarobMYSQL::delete_query_fields(MYSQL_FIELD * &fields, unsigned int
field_count)
{
+ LOG4CXX_DEBUG(logger, "Entering delete_query_fields.");
+
if (fields)
{
for (MYSQL_FIELD *colPtr=fields; field_count; colPtr++, field_count--)
@@ -589,6 +700,8 @@
FREE_AND_NULL_ARRAY(fields);
}
+
+ LOG4CXX_DEBUG(logger, "Leaving delete_query_fields.");
}
typedef char *PCHAR;
@@ -596,6 +709,7 @@
void
CarobMYSQL::alloc_row_data(MYSQL_ROW &row, MYSQL_FIELD *fields, const unsigned
int field_count, unsigned long &length, unsigned long *lengths)
{
+ LOG4CXX_DEBUG(logger, "Entering alloc_row_data.");
/* TODO implement better
* The main idea is to allocate a big enough row to hold all data as strings
* separated by \0, and allocate an array of field_count+1 pointers, which
@@ -636,11 +750,14 @@
row[i] = presult + ((unsigned long) row[i] - 1);
row[field_count] = presult + result.size();
}
+ LOG4CXX_DEBUG(logger, "Leaving alloc_row_data.");
}
void
CarobMYSQL::delete_row_data(MYSQL_ROW &row, const unsigned int field_count)
{
+ LOG4CXX_DEBUG(logger, "Entering delete_row_data.");
+
if (row)
{
for (unsigned int i=0; i<field_count; i++)
@@ -653,4 +770,6 @@
delete [] row;
row = 0;
}
+
+ LOG4CXX_DEBUG(logger, "Leaving delete_row_data.");
}
Index: libmysequoia/src/MySQLAPI.cpp
diff -u libmysequoia/src/MySQLAPI.cpp:1.15 libmysequoia/src/MySQLAPI.cpp:1.16
--- libmysequoia/src/MySQLAPI.cpp:1.15 Thu Dec 15 11:33:47 2005
+++ libmysequoia/src/MySQLAPI.cpp Thu Dec 15 13:31:25 2005
@@ -29,7 +29,7 @@
/* MySQL include */
#include <errmsg.h>
-// include log4cxx header files.
+/* log4cxx include */
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/propertyconfigurator.h>
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits