iODBC icon indicating copy to clipboard operation
iODBC copied to clipboard

Optimization: Do not convert from UTF-8 to UTF-8

Open pali opened this issue 5 years ago • 0 comments

It is possible that both ANSI and Unicode functions operates with UTF-8 encoding. This happens when conv->drv_cp (or conv->dm_cp -- depends on direction) is set to CP_UTF8 and current locale is set to UTF-8 too (nl_langinfo(CODESET) returns "UTF-8").

iODBC in this case is doing useless conversion from UTF-8 to wchar_t and then from wchar_t to UTF-8. This conversion can be avoided.

Simple patch which can avoid this conversion for SQLExecDirect is below:

diff --git a/iodbc/execute.c b/iodbc/execute.c
index d4c3fc0..1676528 100644
--- a/iodbc/execute.c
+++ b/iodbc/execute.c
@@ -93,6 +93,8 @@
 
 #include <itrace.h>
 
+#include <langinfo.h>
+
 void
 _iodbcdm_do_cursoropen (STMT_t * pstmt)
 {
@@ -1236,9 +1238,9 @@ SQLExecDirect_Internal (SQLHSTMT hstmt,
       return SQL_ERROR;
     }
 
-  if (penv->unicode_driver && waMode != 'W')
+  if (penv->unicode_driver && waMode != 'W' && (conv->drv_cp != CP_UTF8 || strcmp(nl_langinfo(CODESET), "UTF-8")))
     conv_direct = CD_A2W;
-  else if (!penv->unicode_driver && waMode == 'W')
+  else if (!penv->unicode_driver && waMode == 'W' && (conv->dm_cp != CP_UTF8 || strcmp(nl_langinfo(CODESET), "UTF-8")))
     conv_direct = CD_W2A;
   else if (waMode == 'W' && conv->dm_cp != conv->drv_cp)
     conv_direct = CD_W2W;

pali avatar Jan 17 '20 17:01 pali