Author: carnold Date: Mon Mar 10 22:39:14 2008 New Revision: 635805 URL: http://svn.apache.org/viewvc?rev=635805&view=rev Log: LOGCXX-248: ODBCAppender has Unicode issues
Modified: logging/log4cxx/trunk/src/main/cpp/exception.cpp logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp logging/log4cxx/trunk/src/main/include/log4cxx/db/odbcappender.h logging/log4cxx/trunk/src/main/include/log4cxx/helpers/exception.h Modified: logging/log4cxx/trunk/src/main/cpp/exception.cpp URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/exception.cpp?rev=635805&r1=635804&r2=635805&view=diff ============================================================================== --- logging/log4cxx/trunk/src/main/cpp/exception.cpp (original) +++ logging/log4cxx/trunk/src/main/cpp/exception.cpp Mon Mar 10 22:39:14 2008 @@ -41,17 +41,13 @@ msg[len] = 0; } -Exception::Exception(const std::string& m) { - size_t len = m.size(); - if (len > MSG_SIZE) { - len = MSG_SIZE; - } +Exception::Exception(const char* m) { #if defined(__STDC_LIB_EXT1__) || defined(__STDC_SECURE_LIB__) - memcpy_s(msg, sizeof msg, m.data(), len); + strncpy_s(msg, sizeof msg, m, MSG_SIZE); #else - memcpy(msg, m.data(), len); + strncpy(msg, m, MSG_SIZE); #endif - msg[len] = 0; + msg[MSG_SIZE] = 0; } Modified: logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp?rev=635805&r1=635804&r2=635805&view=diff ============================================================================== --- logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp (original) +++ logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp Mon Mar 10 22:39:14 2008 @@ -20,6 +20,7 @@ #include <log4cxx/helpers/stringhelper.h> #include <log4cxx/helpers/transcoder.h> #include <log4cxx/patternlayout.h> +#include <apr_strings.h> #if !defined(LOG4CXX) #define LOG4CXX 1 @@ -39,12 +40,13 @@ using namespace log4cxx::spi; SQLException::SQLException(short fHandleType, - void* hInput, const char* prolog) - : Exception(formatMessage(fHandleType, hInput, prolog)) { + void* hInput, const char* prolog, + log4cxx::helpers::Pool& p) + : Exception(formatMessage(fHandleType, hInput, prolog, p)) { } -SQLException::SQLException(const std::string& msg) +SQLException::SQLException(const char* msg) : Exception(msg) { } @@ -52,8 +54,8 @@ : Exception(src) { } -std::string SQLException::formatMessage(short fHandleType, - void* hInput, const char* prolog) { +const char* SQLException::formatMessage(short fHandleType, + void* hInput, const char* prolog, log4cxx::helpers::Pool& p) { std::string strReturn(prolog); strReturn.append(" - "); #if LOG4CXX_HAVE_ODBC @@ -76,7 +78,7 @@ strReturn.append("log4cxx built without ODBC support"); #endif - return strReturn; + return apr_pstrdup((apr_pool_t*) p.getAPRPool(), strReturn.c_str()); } @@ -162,7 +164,7 @@ ret = SQLAllocHandle( SQL_HANDLE_STMT, con, &stmt); if (ret < 0) { - throw SQLException( SQL_HANDLE_DBC, con, "Failed to allocate sql handle."); + throw SQLException( SQL_HANDLE_DBC, con, "Failed to allocate sql handle.", p); } SQLWCHAR* wsql = Transcoder::wencode(sql, p); @@ -170,7 +172,7 @@ if (ret < 0) { - throw SQLException(SQL_HANDLE_STMT, stmt, "Failed to execute sql statement."); + throw SQLException(SQL_HANDLE_STMT, stmt, "Failed to execute sql statement.", p); } } catch (SQLException& e) @@ -209,7 +211,7 @@ ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env); if (ret < 0) { - SQLException ex(SQL_HANDLE_ENV, env, "Failed to allocate SQL handle."); + SQLException ex(SQL_HANDLE_ENV, env, "Failed to allocate SQL handle.", p); env = SQL_NULL_HENV; throw ex; } @@ -217,7 +219,7 @@ ret = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER); if (ret < 0) { - SQLException ex(SQL_HANDLE_ENV, env, "Failed to set odbc version."); + SQLException ex(SQL_HANDLE_ENV, env, "Failed to set odbc version.", p); SQLFreeHandle(SQL_HANDLE_ENV, env); env = SQL_NULL_HENV; throw ex; @@ -229,7 +231,7 @@ ret = SQLAllocHandle(SQL_HANDLE_DBC, env, &connection); if (ret < 0) { - SQLException ex(SQL_HANDLE_DBC, connection, "Failed to allocate sql handle."); + SQLException ex(SQL_HANDLE_DBC, connection, "Failed to allocate sql handle.", p); connection = SQL_NULL_HDBC; throw ex; } @@ -248,7 +250,7 @@ if (ret < 0) { - SQLException ex(SQL_HANDLE_DBC, connection, "Failed to connect to database."); + SQLException ex(SQL_HANDLE_DBC, connection, "Failed to connect to database.", p); SQLFreeHandle(SQL_HANDLE_DBC, connection); connection = SQL_NULL_HDBC; throw ex; Modified: logging/log4cxx/trunk/src/main/include/log4cxx/db/odbcappender.h URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/db/odbcappender.h?rev=635805&r1=635804&r2=635805&view=diff ============================================================================== --- logging/log4cxx/trunk/src/main/include/log4cxx/db/odbcappender.h (original) +++ logging/log4cxx/trunk/src/main/include/log4cxx/db/odbcappender.h Mon Mar 10 22:39:14 2008 @@ -38,12 +38,14 @@ class LOG4CXX_EXPORT SQLException : public log4cxx::helpers::Exception { public: SQLException(short fHandleType, - void* hInput, const char* prolog); - SQLException(const std::string& msg); + void* hInput, const char* prolog, + log4cxx::helpers::Pool& p); + SQLException(const char* msg); SQLException(const SQLException& src); private: - std::string formatMessage(short fHandleType, - void* hInput, const char* prolog); + const char* formatMessage(short fHandleType, + void* hInput, const char* prolog, + log4cxx::helpers::Pool& p); }; /** Modified: logging/log4cxx/trunk/src/main/include/log4cxx/helpers/exception.h URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/helpers/exception.h?rev=635805&r1=635804&r2=635805&view=diff ============================================================================== --- logging/log4cxx/trunk/src/main/include/log4cxx/helpers/exception.h (original) +++ logging/log4cxx/trunk/src/main/include/log4cxx/helpers/exception.h Mon Mar 10 22:39:14 2008 @@ -32,7 +32,7 @@ class LOG4CXX_EXPORT Exception : public ::std::exception { public: - Exception(const std::string& msg); + Exception(const char* msg); Exception(const LogString& msg); Exception(const Exception& src); Exception& operator=(const Exception& src);