Date: Thursday, July 20, 2006 @ 13:51:07
  Author: csaba
    Path: /cvsroot/carob/libmysequoia

Modified: include/CarobMySQL.hpp (1.34 -> 1.35) src/CarobMySQL.cpp (1.78
          -> 1.79)

Do not send the "set names ..." query to the server. Insteed trap it and set in 
the library the character set. Fixes for LMS-8


------------------------+
 include/CarobMySQL.hpp |    2 -
 src/CarobMySQL.cpp     |   66 +++++++++++++++++++++++------------------------
 2 files changed, 34 insertions(+), 34 deletions(-)


Index: libmysequoia/include/CarobMySQL.hpp
diff -u libmysequoia/include/CarobMySQL.hpp:1.34 
libmysequoia/include/CarobMySQL.hpp:1.35
--- libmysequoia/include/CarobMySQL.hpp:1.34    Thu Jul 13 16:30:51 2006
+++ libmysequoia/include/CarobMySQL.hpp Thu Jul 20 13:51:07 2006
@@ -216,7 +216,7 @@
   /**
    * Set the character set for the connection
    */
-  int set_character_set(const char *name, bool runquery = true);
+  int set_character_set(const char *name);
   
   /**
    * Creates a prepared statement
Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.78 
libmysequoia/src/CarobMySQL.cpp:1.79
--- libmysequoia/src/CarobMySQL.cpp:1.78        Thu Jul 13 16:30:51 2006
+++ libmysequoia/src/CarobMySQL.cpp     Thu Jul 20 13:51:07 2006
@@ -317,6 +317,27 @@
     return false;
   }
 
+  // catch the "set names ..." queries and set the client encodings
+  // do not send the query to the server
+  if (parse)
+  {
+    const char *p = query, *q = 0;
+    bool result = false;
+    if (string_match(p, "set") && string_match(p, "names") && (q = 
get_next_string(p)) && (p - q < MAX_CHARSET_LEN))
+    {
+      char charset[MAX_CHARSET_LEN+1];
+      strncpy(charset,q,p-q); charset[p-q]=0;
+      result = set_character_set(charset) == 0 ? true : false;
+
+      mysqlPtr->affected_rows = 0;
+      mysqlPtr->field_count = 0;
+      mysqlPtr->warning_count = 0;
+
+      LOG4CXX_DEBUG(logger, "Leaving real_query: result=" << result);
+      return result;
+    }
+  }
+
   try {  
     try {
       drsPtr = NULL;
@@ -354,18 +375,6 @@
         info[sizeof(info)-1] = 0;
         mysqlPtr->info = cstrdup(info);
         LOG4CXX_INFO(logger, "Executed query. Affected_rows=" << 
mysqlPtr->affected_rows);
-        
-        //if there are no affected rows, the query need to be parsed, to see 
if not a "set names ..." type
-        if (parse && mysqlPtr->affected_rows == 0)
-        {
-          const char *p = query, *q = 0;
-          if (string_match(p, "set") && string_match(p, "names") && (q = 
get_next_string(p)) && (p - q < MAX_CHARSET_LEN))
-          {
-            char charset[MAX_CHARSET_LEN+1];
-            strncpy(charset,q,p-q); charset[p-q]=0;
-            set_character_set(charset, false);
-          }
-        }
       }
   
       reset_error();
@@ -883,32 +892,23 @@
 }
 
 int
-CarobMYSQL::set_character_set(const char *name, bool runquery)
+CarobMYSQL::set_character_set(const char *name)
 {
   LOG4CXX_DEBUG(logger, "Entering set_character_set: name=" << name);
   
-  bool result = true;
-  
-  if (runquery)
+  bool result = false;
+
+  try
   {
-    char buff[254];
-  
-    snprintf(buff, sizeof(buff), "SET NAMES %s", name);
-    result=real_query(buff, strlen(buff), false);
+    result = conv.set_code(name);
+    
+    FREE_AND_NULL_ARRAY(mysqlPtr->options.charset_name);
+    mysqlPtr->options.charset_name = cstrdup(name);
+  }
+  catch (ConverterException &ex)
+  {
+    result=false;
   }
-  
-  if (result)
-    try
-    {
-      result = conv.set_code(name);
-
-      FREE_AND_NULL_ARRAY(mysqlPtr->options.charset_name);
-      mysqlPtr->options.charset_name = cstrdup(name);
-    }
-    catch (ConverterException &ex)
-    {
-      result=false;
-    }
 
   if (!result)
     set_error(CR_CANT_READ_CHARSET, SQLT_UNKNOWN);

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to