You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2008/07/16 06:41:33 UTC

svn commit: r677152 - in /logging/log4cxx/trunk/src: changes/changes.xml main/cpp/odbcappender.cpp main/include/log4cxx/db/odbcappender.h

Author: carnold
Date: Tue Jul 15 21:41:32 2008
New Revision: 677152

URL: http://svn.apache.org/viewvc?rev=677152&view=rev
Log:
LOGCXX-299: odbcappender.cpp does not compile with unixODBC on Linux

Modified:
    logging/log4cxx/trunk/src/changes/changes.xml
    logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp
    logging/log4cxx/trunk/src/main/include/log4cxx/db/odbcappender.h

Modified: logging/log4cxx/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/changes/changes.xml?rev=677152&r1=677151&r2=677152&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/changes/changes.xml (original)
+++ logging/log4cxx/trunk/src/changes/changes.xml Tue Jul 15 21:41:32 2008
@@ -47,6 +47,7 @@
 <action issue="LOGCXX-291">Tab characters are not recognized in property files.<action>
 <action issue="LOGCXX-292">Value continuation does not properly handle CRLF in property files.<action>
 <action issue="LOGCXX-293">Escape sequences not recognized in property files.<action>
+<action issue="LOGCXX-299">odbcappender.cpp does not compile with unixODBC on linux.</action>
 <action issue="LOGCXX-304">BasicConfigurator::configure results in writer not set warning.</action>
 </release>
 <release version="0.10.0" date="2008-04-03" description="First Apache release">

Modified: logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp?rev=677152&r1=677151&r2=677152&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp Tue Jul 15 21:41:32 2008
@@ -167,7 +167,8 @@
          throw SQLException( SQL_HANDLE_DBC, con, "Failed to allocate sql handle.", p);
       }
 
-      SQLWCHAR* wsql = Transcoder::wencode(sql, p); 
+      SQLWCHAR* wsql;
+      encode(&wsql, sql, p); 
       ret = SQLExecDirectW(stmt, wsql, SQL_NTS);
 
      if (ret < 0)
@@ -237,9 +238,10 @@
       }
 
 
-     SQLWCHAR* wURL = Transcoder::wencode(databaseURL, p);
+     SQLWCHAR* wURL;
+     encode(&wURL, databaseURL, p);
 
-     wchar_t szOutConnectionString[1024];
+     SQLWCHAR szOutConnectionString[1024];
      SQLSMALLINT nOutConnctionLength = 0;
 
      ret = SQLDriverConnectW( connection, NULL, 
@@ -331,3 +333,31 @@
       }
    }
 }
+
+void ODBCAppender::encode(wchar_t** dest, const LogString& src, Pool& p) {
+   *dest = Transcoder::wencode(src, p);
+}
+
+void ODBCAppender::encode(unsigned short** dest, 
+    const LogString& src, Pool& p) {
+   //  worst case double number of characters from UTF-8 or wchar_t
+   *dest = (unsigned short*) 
+        p.palloc((src.size() + 1) * 2 * sizeof(unsigned short));
+   unsigned short* current = *dest;
+   for(LogString::const_iterator i = src.begin();
+      i != src.end();) {
+      unsigned int sv = Transcoder::decode(src, i);
+      if (sv < 0x10000) {
+	 *current++ = (unsigned short) sv;
+      } else {
+        unsigned char u = (unsigned char) (sv >> 16);
+        unsigned char w = (unsigned char) (u - 1);
+        unsigned short hs = (0xD800 + ((w & 0xF) << 6) + ((sv & 0xFFFF) >> 10));
+        unsigned short ls = (0xDC00 + (sv && 0x3FF));
+	*current++ = (unsigned short) hs;
+	*current++ = (unsigned short) ls;
+      }
+  }
+  *current = 0;
+}
+

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=677152&r1=677151&r2=677152&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/db/odbcappender.h (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/db/odbcappender.h Tue Jul 15 21:41:32 2008
@@ -279,6 +279,10 @@
                 private:
                         ODBCAppender(const ODBCAppender&);
                         ODBCAppender& operator=(const ODBCAppender&);
+                        static void encode(wchar_t** dest, const LogString& src, 
+                             log4cxx::helpers::Pool& p);
+                        static void encode(unsigned short** dest, const LogString& src, 
+                             log4cxx::helpers::Pool& p);
                 }; // class ODBCAppender
                 LOG4CXX_PTR_DEF(ODBCAppender);