Date: Friday, March 3, 2006 @ 10:57:49
  Author: csaba
    Path: /cvsroot/carob/libmysequoia

Modified: autogen.sh (1.5 -> 1.6) include/CarobCommon.hpp (1.2 -> 1.3)
          include/CarobMySQL.hpp (1.27 -> 1.28) include/CarobStmt.hpp (1.9
          -> 1.10) include/Utils.hpp (1.18 -> 1.19) src/CarobCommon.cpp
          (1.6 -> 1.7) src/CarobMySQL.cpp (1.57 -> 1.58) src/CarobStmt.cpp
          (1.27 -> 1.28) src/Utils.cpp (1.34 -> 1.35)

Initial character set support.


-------------------------+
 autogen.sh              |    2 -
 include/CarobCommon.hpp |   33 +++++++++++++++++++++++++++----
 include/CarobMySQL.hpp  |   21 ++++++++++++++++++--
 include/CarobStmt.hpp   |   16 ++++++++++++++-
 include/Utils.hpp       |    8 -------
 src/CarobCommon.cpp     |    7 ++++++
 src/CarobMySQL.cpp      |   48 +++++++++++++++++++++++++++++++---------------
 src/CarobStmt.cpp       |   34 ++++++++++++++++++++++----------
 src/Utils.cpp           |    6 -----
 9 files changed, 127 insertions(+), 48 deletions(-)


Index: libmysequoia/autogen.sh
diff -u libmysequoia/autogen.sh:1.5 libmysequoia/autogen.sh:1.6
--- libmysequoia/autogen.sh:1.5 Mon Feb 13 11:23:07 2006
+++ libmysequoia/autogen.sh     Fri Mar  3 10:57:48 2006
@@ -14,4 +14,4 @@
 autoheader
 automake --add-missing --copy
 autoconf
-CXXFLAGS="-Wall -O0 -g3" ./configure --enable-gcov --enable-cppunit
+CXXFLAGS="-Wall -Werror -O0 -g3" ./configure --prefix=/usr 
--sysconfdir=/etc/mysequoia --enable-gcov --enable-cppunit
Index: libmysequoia/include/CarobCommon.hpp
diff -u libmysequoia/include/CarobCommon.hpp:1.2 
libmysequoia/include/CarobCommon.hpp:1.3
--- libmysequoia/include/CarobCommon.hpp:1.2    Thu Mar  2 17:23:24 2006
+++ libmysequoia/include/CarobCommon.hpp        Fri Mar  3 10:57:48 2006
@@ -27,7 +27,6 @@
 
 // carob includes
 #include <ResultSetMetaData.hpp>
-#include <Converter.hpp>
 
 // include log4cxx header files.
 #include <log4cxx/logger.h>
@@ -41,6 +40,11 @@
   CarobCommon() {}
 
   /**
+   * Destructor
+   */
+  virtual ~CarobCommon() {}
+  
+  /**
    * Allocates the field info for a query
    * @param result the resulting MYSQL_FIELD structure
    * @param rsmPtr a pointer containing the metadata of resultset from sequoia
@@ -54,11 +58,32 @@
    */
   static void delete_query_fields (MYSQL_FIELD * &fields, unsigned int 
field_count);
 
+  /**
+   * Convert from wstring to string.
+   * @param w the wstring.
+   * @return a string.
+   */
+  virtual std::string from_wstring(const std::wstring &w) = 0;
+
+  /**
+   * Convert from string to wstring.
+   * @param s the string.
+   * @return a wstring.
+   */
+  virtual std::wstring to_wstring(const std::string &s) = 0;
+
+private:
+  /**
+   * Converts a wstring to a char *.
+   * @param src the wide character string to be converted
+   * @param result reference to a pchar *, which will contain the result. The 
memory for it will be allocated
+   * @param length the length of the resulting string
+   */
+  void convert_to_pchar(const std::wstring &src, char * &result, unsigned int 
&length);
+
+protected:
   // logger
   static log4cxx::LoggerPtr logger;
-  
-  // conversion between character sets
-  Converter conv;
 };
 
 #endif /*_CAROBCOMMON_HPP*/
Index: libmysequoia/include/CarobMySQL.hpp
diff -u libmysequoia/include/CarobMySQL.hpp:1.27 
libmysequoia/include/CarobMySQL.hpp:1.28
--- libmysequoia/include/CarobMySQL.hpp:1.27    Tue Feb 28 11:53:33 2006
+++ libmysequoia/include/CarobMySQL.hpp Fri Mar  3 10:57:48 2006
@@ -25,6 +25,7 @@
 #include <config.h>
 
 #include <CarobCommon.hpp>
+#include <Converter.hpp>
 
 /* MySQL includes */
 #include <mysql_wrapper.h>
@@ -52,7 +53,7 @@
 
 public:
   CarobMYSQL (MYSQL * mysql, my_bool free_me);
-  ~CarobMYSQL ();
+  virtual ~CarobMYSQL ();
 
     /**
      * Connect to sequoia through Carob. Initialize the corresponding fields 
in the
@@ -218,6 +219,20 @@
    */
   MYSQL *getMYSQL ();
 
+  /**
+   * Convert from wstring to string.
+   * @param w the wstring.
+   * @return a string.
+   */
+  virtual std::string from_wstring(const std::wstring &w);
+
+  /**
+   * Convert from string to wstring.
+   * @param s the string.
+   * @return a wstring.
+   */
+  virtual std::wstring to_wstring(const std::string &s);
+
 private:
   //pointer to a MYSQL structure which is connected to this class
   MYSQL * mysqlPtr;
@@ -235,7 +250,9 @@
   std::vector<CarobStmt *> carobStmts;
   //critical section for accessing the carobStmts list
   log4cxx::helpers::CriticalSection cs_carobStmts;
-
+  // character conversions
+  Converter conv;
+  
   /**
    * Private default constructor.
    */
Index: libmysequoia/include/CarobStmt.hpp
diff -u libmysequoia/include/CarobStmt.hpp:1.9 
libmysequoia/include/CarobStmt.hpp:1.10
--- libmysequoia/include/CarobStmt.hpp:1.9      Wed Feb 22 15:23:57 2006
+++ libmysequoia/include/CarobStmt.hpp  Fri Mar  3 10:57:48 2006
@@ -39,7 +39,7 @@
   /**
    * Free the allocated statement and resources used by it. Also delete Carob 
statement
    */
-       ~CarobStmt();
+       virtual ~CarobStmt();
   
   /**
    * Executes the prepared statement. The parameter should be already bind to 
the statement, and
@@ -161,6 +161,20 @@
    */
   MYSQL_STMT *getMYSQL_STMT() {return m_stmt;}
 
+  /**
+   * Convert from wstring to string.
+   * @param w the wstring.
+   * @return a string.
+   */
+  virtual std::string from_wstring(const std::wstring &w);
+
+  /**
+   * Convert from string to wstring.
+   * @param s the string.
+   * @return a wstring.
+   */
+  virtual std::wstring to_wstring(const std::string &s);
+
 protected:
   /**
    * Initialize and constructs the class. Allocate a MYSQL_STMT and initialize 
a Carob::ParameterStatement.
Index: libmysequoia/include/Utils.hpp
diff -u libmysequoia/include/Utils.hpp:1.18 libmysequoia/include/Utils.hpp:1.19
--- libmysequoia/include/Utils.hpp:1.18 Tue Jan 31 13:14:45 2006
+++ libmysequoia/include/Utils.hpp      Fri Mar  3 10:57:48 2006
@@ -73,14 +73,6 @@
 char *cstrdupcond(char * &dest, const char *src, int len);
 
 /**
- * Converts a wstring to a char *.
- * @param src the wide character string to be converted
- * @param result reference to a pchar *, which will contain the result. The 
memory for it will be allocated
- * @param length the length of the resulting string
- */
-void convert_to_pchar(const std::wstring &src, char * &result, unsigned int 
&length);
-
-/**
  * Returns a client error message associated with the error code.
  * @param code MySQL client error code
  * @return a the detailed error message or null if the error code was not a 
client error
Index: libmysequoia/src/CarobCommon.cpp
diff -u libmysequoia/src/CarobCommon.cpp:1.6 
libmysequoia/src/CarobCommon.cpp:1.7
--- libmysequoia/src/CarobCommon.cpp:1.6        Fri Mar  3 10:43:13 2006
+++ libmysequoia/src/CarobCommon.cpp    Fri Mar  3 10:57:48 2006
@@ -29,6 +29,13 @@
 
 LoggerPtr CarobCommon::logger(Logger::getLogger("MySQLAPI.Carob"));
 
+void
+CarobCommon::convert_to_pchar(const std::wstring &src, char * &result, 
unsigned int &length)
+{
+  length = src.length();
+  result = cstrdup(from_wstring(src).data(), length);
+}
+
 int
 CarobCommon::get_query_fields (MYSQL_FIELD * &result, ResultSetMetaData 
*rsmPtr)
 {
Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.57 
libmysequoia/src/CarobMySQL.cpp:1.58
--- libmysequoia/src/CarobMySQL.cpp:1.57        Fri Mar  3 10:43:13 2006
+++ libmysequoia/src/CarobMySQL.cpp     Fri Mar  3 10:57:48 2006
@@ -57,7 +57,10 @@
 
   // force reading the my.cnf file
   mysql->options.my_cnf_group = cstrdup("client");
-  
+
+  // set the conversion to default "latin1"
+  conv.set_code("latin1");
+    
   mysqlPtr = mysql;
 
   LOG4CXX_DEBUG(logger, "Leaving constructor.");
@@ -171,7 +174,10 @@
   
   /* set the default character set if not set */
   if (!mysqlPtr->options.charset_name || !*mysqlPtr->options.charset_name)
+  {
     mysqlPtr->options.charset_name = cstrdup("latin1");
+    conv.set_code(mysqlPtr->options.charset_name);
+  }
   
   /* Check for delayed connection. If db name not given, the connection can't 
happen, because sequoia doesn't support it.
    * The real connection will happen after the user call the command 
mysql_select_db or mysql_real_connect */
@@ -190,8 +196,8 @@
   
   try 
   {
-    ConnectionParameters connectionParameters(fromString(host), port, 
-      fromString(db), fromString(user), fromString(passwd), DEBUG_LEVEL_OFF, 
DEFAULT_POLICY, DEFAULT_RETRY_INTERVAL, true);
+    ConnectionParameters connectionParameters(to_wstring(host), port, 
+      to_wstring(db), to_wstring(user), to_wstring(passwd), DEBUG_LEVEL_OFF, 
DEFAULT_POLICY, DEFAULT_RETRY_INTERVAL, true);
     
     Connection *newConnectionPtr;
     
@@ -204,8 +210,8 @@
       //failed we try the 3306 port
       if (defaultport && (port == 25322))
       {
-        ConnectionParameters connectionParameters2(fromString(host), 3306,
-          fromString(db), fromString(user), fromString(passwd), 
DEBUG_LEVEL_OFF, DEFAULT_POLICY, DEFAULT_RETRY_INTERVAL, true);
+        ConnectionParameters connectionParameters2(to_wstring(host), 3306,
+          to_wstring(db), to_wstring(user), to_wstring(passwd), 
DEBUG_LEVEL_OFF, DEFAULT_POLICY, DEFAULT_RETRY_INTERVAL, true);
         newConnectionPtr = new Connection(connectionParameters2);
       }
       else
@@ -235,7 +241,7 @@
   } 
   catch (CarobException &e)
   {
-    set_error(e.getErrorCode(), toString(e.description()).c_str(), 
toString(e.getSQLState()).c_str());
+    set_error(e.getErrorCode(), from_wstring(e.description()).c_str(), 
from_wstring(e.getSQLState()).c_str());
     //TODO error handling
     LOG4CXX_DEBUG(logger, "Leaving connect.");
     return false;
@@ -299,7 +305,7 @@
 
     FREE_AND_NULL_ARRAY(mysqlPtr->info);
 
-    if (stmtPtr->execute(fromString(std::string(query,length))))
+    if (stmtPtr->execute(to_wstring(std::string(query,length))))
     {
       mysqlPtr->affected_rows = 0;
       drsPtr = stmtPtr->getResultSet();
@@ -327,7 +333,7 @@
   }
   catch (CarobException &e)
   {
-    set_error(e.getErrorCode(), toString(e.description()).c_str(), 
toString(e.getSQLState()).c_str());
+    set_error(e.getErrorCode(), from_wstring(e.description()).c_str(), 
from_wstring(e.getSQLState()).c_str());
     LOG4CXX_DEBUG(logger, "Leaving real_query: result=0");
     return false;
   }
@@ -420,7 +426,7 @@
   }
   catch (CarobException &e)
   {
-    set_error(e.getErrorCode(), toString(e.description()).c_str(), 
toString(e.getSQLState()).c_str());
+    set_error(e.getErrorCode(), from_wstring(e.description()).c_str(), 
from_wstring(e.getSQLState()).c_str());
     LOG4CXX_DEBUG(logger, "Leaving get_results: result=0");
     return 0;
   }
@@ -498,7 +504,7 @@
     }
     catch (CarobException &e)
     {
-      set_error(e.getErrorCode(), toString(e.description()).c_str(), 
toString(e.getSQLState()).c_str());
+      set_error(e.getErrorCode(), from_wstring(e.description()).c_str(), 
from_wstring(e.getSQLState()).c_str());
       result = 1;
     }
   }
@@ -600,7 +606,7 @@
   }
   catch (CarobException &e)
   {
-    set_error(e.getErrorCode(), toString(e.description()).c_str(), 
toString(e.getSQLState()).c_str());
+    set_error(e.getErrorCode(), from_wstring(e.description()).c_str(), 
from_wstring(e.getSQLState()).c_str());
     LOG4CXX_DEBUG(logger, "Leaving set_autocommit: result=0");
     return 0;
   }
@@ -629,7 +635,7 @@
   }
   catch (CarobException &e)
   {
-    set_error(e.getErrorCode(), toString(e.description()).c_str(), 
toString(e.getSQLState()).c_str());
+    set_error(e.getErrorCode(), from_wstring(e.description()).c_str(), 
from_wstring(e.getSQLState()).c_str());
     LOG4CXX_DEBUG(logger, "Leaving commit: result=0");
     return 0;
   }
@@ -658,7 +664,7 @@
   }
   catch (CarobException &e)
   {
-    set_error(e.getErrorCode(), toString(e.description()).c_str(), 
toString(e.getSQLState()).c_str());
+    set_error(e.getErrorCode(), from_wstring(e.description()).c_str(), 
from_wstring(e.getSQLState()).c_str());
     LOG4CXX_DEBUG(logger, "Leaving rollback: result=0");
     return false;
   }
@@ -740,7 +746,7 @@
   char buff[254];
   
   snprintf(buff, sizeof(buff), "SET NAMES %s", name);
-  if ((result=real_query(buff, strlen(buff))) == true)
+  if ((result=real_query(buff, strlen(buff))) && conv.set_code(name))
   {
     cstrdupcond(mysqlPtr->options.charset_name, name);
   }
@@ -910,7 +916,7 @@
             tmp = string((char *)d.data, d.length);
           }
           else
-            tmp = toString(drsPtr->getAsString(i+1));
+            tmp = from_wstring(drsPtr->getAsString(i+1));
             
           field_len = tmp.length();
           result += tmp;
@@ -1061,3 +1067,15 @@
   cs_carobStmts.unlock();
   LOG4CXX_DEBUG(logger, "Leaving resetPreparedStatment");
 }
+
+std::string
+CarobMYSQL::from_wstring(const wstring &w)
+{
+  return conv.from_wstring(w);
+}
+
+std::wstring
+CarobMYSQL::to_wstring(const string &s)
+{
+  return conv.to_wstring(s);
+}
Index: libmysequoia/src/CarobStmt.cpp
diff -u libmysequoia/src/CarobStmt.cpp:1.27 libmysequoia/src/CarobStmt.cpp:1.28
--- libmysequoia/src/CarobStmt.cpp:1.27 Fri Mar  3 10:43:13 2006
+++ libmysequoia/src/CarobStmt.cpp      Fri Mar  3 10:57:48 2006
@@ -55,7 +55,7 @@
   m_stmt->prefetch_rows = 1;
 #endif
   m_stmt->state = MYSQL_STMT_INIT_DONE;
-  
+
   cmysql = c;
   
   LOG4CXX_DEBUG(logger, "Leaving constructor.");
@@ -100,7 +100,7 @@
    
   try
   {
-    c_stmt = 
cmysql->connectionPtr->createParameterStatement(fromString(string(query, 
length)));
+    c_stmt = 
cmysql->connectionPtr->createParameterStatement(to_wstring(string(query, 
length)));
     m_stmt->param_count = c_stmt->getParameterCount();
     m_stmt->state = MYSQL_STMT_PREPARE_DONE;
     m_stmt->params = new MYSQL_BIND[m_stmt->param_count];
@@ -116,12 +116,12 @@
       }
     } catch (BackendException &e)
     {
-      LOG4CXX_DEBUG(logger, "Prepare: errno=" << e.getErrorCode() << " error=" 
<< toString(e.description()));
+      LOG4CXX_DEBUG(logger, "Prepare: errno=" << e.getErrorCode() << " error=" 
<< from_wstring(e.description()));
     }
   }
   catch (CarobException &e)
   {
-    set_error(e.getErrorCode(), toString(e.description()).c_str(), 
toString(e.getSQLState()).c_str());
+    set_error(e.getErrorCode(), from_wstring(e.description()).c_str(), 
from_wstring(e.getSQLState()).c_str());
     result = 1;
   }
   
@@ -322,9 +322,9 @@
               case MYSQL_TYPE_VAR_STRING:
               case MYSQL_TYPE_STRING:
                 if (p->long_data_used && LONGDATAFIELD(p))
-                  c_stmt->setString(no, fromString(*(string 
*)LONGDATAFIELD(p)));
+                  c_stmt->setString(no, to_wstring(*(string 
*)LONGDATAFIELD(p)));
                 else
-                  c_stmt->setString(no, fromString(string((char *)p->buffer, 
p->buffer_length)));
+                  c_stmt->setString(no, to_wstring(string((char *)p->buffer, 
p->buffer_length)));
                 break;
               case MYSQL_TYPE_TIME:
               case MYSQL_TYPE_DATE:
@@ -332,7 +332,7 @@
               case MYSQL_TYPE_TIMESTAMP:
                 char buffer[20];
                 MYSQL_TIME_to_str((MYSQL_TIME *)p->buffer, buffer, 
sizeof(buffer));
-                c_stmt->setString(no, 
fromString(string(buffer,strlen(buffer))));
+                c_stmt->setString(no, 
to_wstring(string(buffer,strlen(buffer))));
                 break;
               case MYSQL_TYPE_NULL:
                 break;
@@ -351,7 +351,7 @@
       }
       catch (CarobException &e)
       {
-        set_error(e.getErrorCode(), toString(e.description()).c_str(), 
toString(e.getSQLState()).c_str());
+        set_error(e.getErrorCode(), from_wstring(e.description()).c_str(), 
from_wstring(e.getSQLState()).c_str());
       }
     }
   
@@ -805,7 +805,7 @@
           result = new string((char *)d.data, d.length);
         }
         else
-          result = new string(toString(liveResultSet->getAsString(colNo)));
+          result = new string(from_wstring(liveResultSet->getAsString(colNo)));
         break;
       case MYSQL_TYPE_TIME:
         result = new int(liveResultSet->getAsInt(colNo));
@@ -828,7 +828,7 @@
   }
   catch (CarobException &e)
   {
-    set_error(e.getErrorCode(), toString(e.description()).c_str(), 
toString(e.getSQLState()).c_str());
+    set_error(e.getErrorCode(), from_wstring(e.description()).c_str(), 
from_wstring(e.getSQLState()).c_str());
   }
         
   LOG4CXX_DEBUG(logger, "Leaving alloc_fetch_field: result=" << result);
@@ -971,7 +971,7 @@
 {
   LOG4CXX_DEBUG(logger, "Entering clear.");
 
-  if (c_stmt)
+  if (cmysql && c_stmt)
   {
     cmysql->connectionPtr->deleteStatement(c_stmt);
     c_stmt = NULL;
@@ -997,3 +997,15 @@
 
   LOG4CXX_DEBUG(logger, "Leaving clear.");
 }
+
+std::string
+CarobStmt::from_wstring(const wstring &w)
+{
+  return cmysql ? cmysql->from_wstring(w) : string();
+}
+
+std::wstring
+CarobStmt::to_wstring(const string &s)
+{
+  return cmysql ? cmysql->to_wstring(s) : wstring();
+}
Index: libmysequoia/src/Utils.cpp
diff -u libmysequoia/src/Utils.cpp:1.34 libmysequoia/src/Utils.cpp:1.35
--- libmysequoia/src/Utils.cpp:1.34     Tue Feb 14 14:43:43 2006
+++ libmysequoia/src/Utils.cpp  Fri Mar  3 10:57:48 2006
@@ -149,12 +149,6 @@
   return dest;
 }
 
-void convert_to_pchar(const std::wstring &src, char * &result, unsigned int 
&length)
-{
-  length = src.length();
-  result = cstrdup(toString(src).data(), length);
-}
-
 const char *get_error_msg(const int code)
 {
   if (code >= CR_MIN_ERROR && code <= CR_MAX_ERROR)

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

Reply via email to