List:Commits« Previous MessageNext Message »
From:jwinstead Date:September 12 2007 10:12pm
Subject:Connector/ODBC 3.51 commit: r784 - in branches/guffert: driver util
View as plain text  
Modified:
   branches/guffert/driver/myutil.h
   branches/guffert/driver/utility.c
   branches/guffert/util/stringutil.c
   branches/guffert/util/stringutil.h
Log:
Use macros for UTF-8 charset-related constants, and expand list of charsets
recognized as UTF-8 to accomodate 4-byte UTF-8 charsets coming in 5.2.


Modified: branches/guffert/driver/myutil.h
===================================================================
--- branches/guffert/driver/myutil.h	2007-09-12 20:11:49 UTC (rev 783)
+++ branches/guffert/driver/myutil.h	2007-09-12 20:12:44 UTC (rev 784)
@@ -55,6 +55,7 @@
                query_print((A)->query_log,(char*) B);}
 
 
+/** @todo Need to make this version-aware so we get 4-byte UTF-8 in 5.2.  */
 #define UTF8_CHARSET_NUMBER 33
 
 /* Wrappers to hide differences in client library versions. */

Modified: branches/guffert/driver/utility.c
===================================================================
--- branches/guffert/driver/utility.c	2007-09-12 20:11:49 UTC (rev 783)
+++ branches/guffert/driver/utility.c	2007-09-12 20:12:44 UTC (rev 784)
@@ -295,8 +295,8 @@
   SQLCHAR *result_end;
   ulong used_bytes= 0, used_chars= 0, error_count= 0;
   CHARSET_INFO *to_cs= stmt->dbc->ansi_charset_info,
-               /* @todo 33 is utf8, hack for our internal result sets */
-               *from_cs= get_charset(field->charsetnr ? field->charsetnr : 33,
+               *from_cs= get_charset(field->charsetnr ? field->charsetnr :
+                                     UTF8_CHARSET_NUMBER,
                                      MYF(0));
 
   if (!result_bytes)
@@ -529,7 +529,8 @@
   char *src_end;
   SQLWCHAR *result_end;
   ulong used_chars= 0, error_count= 0;
-  CHARSET_INFO *from_cs= get_charset(field->charsetnr ? field->charsetnr : 33,
+  CHARSET_INFO *from_cs= get_charset(field->charsetnr ? field->charsetnr :
+                                     UTF8_CHARSET_NUMBER,
                                      MYF(0));
 
   if (!result_len)

Modified: branches/guffert/util/stringutil.c
===================================================================
--- branches/guffert/util/stringutil.c	2007-09-12 20:11:49 UTC (rev 783)
+++ branches/guffert/util/stringutil.c	2007-09-12 20:12:44 UTC (rev 784)
@@ -61,7 +61,7 @@
     return NULL;
   }
 
-  if (charset_info->number != 33) /* not utf-8 */
+  if (!is_utf8_charset(charset_info))
   {
     uint32 used_bytes, used_chars;
     size_t u8_max= (*len / charset_info->mbminlen *
@@ -133,12 +133,12 @@
   SQLWCHAR *str_end;
   SQLCHAR *out;
   SQLINTEGER i, u8_len, out_bytes;
-  UTF8 u8[7];
+  UTF8 u8[MAX_BYTES_PER_UTF8_CP + 1];
   uint32 used_bytes, used_chars;
 
   *errors= 0;
 
-  if (charset_info->number == 33)
+  if (is_utf8_charset(charset_info->number))
     return sqlwchar_as_utf8(str, len);
 
   if (*len == SQL_NTS)
@@ -206,7 +206,8 @@
     return NULL;
   }
 
-  u8= (UTF8 *)my_malloc(sizeof(UTF8) * MAX_BYTES_PER_UTF8_CP * *len + 1, MYF(0));
+  u8= (UTF8 *)my_malloc(sizeof(UTF8) * MAX_BYTES_PER_UTF8_CP * *len + 1,
+                        MYF(0));
   if (!u8)
   {
     *len= -1;
@@ -330,7 +331,7 @@
 {
   SQLWCHAR *str_end;
   SQLINTEGER i, u8_len;
-  UTF8 u8[7];
+  UTF8 u8[MAX_BYTES_PER_UTF8_CP + 1];
   uint32 used_bytes, used_chars;
 
   *errors= 0;

Modified: branches/guffert/util/stringutil.h
===================================================================
--- branches/guffert/util/stringutil.h	2007-09-12 20:11:49 UTC (rev 783)
+++ branches/guffert/util/stringutil.h	2007-09-12 20:12:44 UTC (rev 784)
@@ -47,6 +47,17 @@
 
 extern CHARSET_INFO *utf8_charset_info;
 
+
+/**
+ Determine whether a charset number represents a UTF-8 collation.
+*/
+#define is_utf8_charset(number) \
+  (number == 33 || number == 83 || \
+   (number >= 192 && number <= 211) || number == 253 || \
+   number == 45 || number == 46 || \
+   (number >= 224 && number <= 243))
+
+
 int utf16toutf32(UTF16 *i, UTF32 *u);
 int utf32toutf16(UTF32 i, UTF16 *u);
 int utf8toutf32(UTF8 *i, UTF32 *u);

Thread
Connector/ODBC 3.51 commit: r784 - in branches/guffert: driver utiljwinstead12 Sep