Date: Wednesday, January 25, 2006 @ 09:46:24
  Author: zsolt
    Path: /cvsroot/carob/libmysequoia

Modified: include/CarobMySQL.hpp (1.21 -> 1.22) src/CarobMySQL.cpp (1.33
          -> 1.34) src/CarobStmt.cpp (1.13 -> 1.14) src/MySQLAPI.cpp (1.31
          -> 1.32)

introduced init_cmd_list which contain a list of mysql command which will be 
executed at the begining of every connection
implemented mysql_options (MYSQL_INIT_COMMAND, MYSQL_SET_CHARSET_NAME, 
MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, MYSQL_OPT_READ_TIMEOUT, 
MYSQL_OPT_WRITE_TIMEOUT, MYSQL_REPORT_DATA_TRUNCATION)
data truncation is reported only if option is set


------------------------+
 include/CarobMySQL.hpp |    9 +++++
 src/CarobMySQL.cpp     |   13 ++++++++
 src/CarobStmt.cpp      |   15 +++++++--
 src/MySQLAPI.cpp       |   71 +++++++++++++++++++++++++++++++++++++++++++----
 4 files changed, 100 insertions(+), 8 deletions(-)


Index: libmysequoia/include/CarobMySQL.hpp
diff -u libmysequoia/include/CarobMySQL.hpp:1.21 
libmysequoia/include/CarobMySQL.hpp:1.22
--- libmysequoia/include/CarobMySQL.hpp:1.21    Tue Jan 24 15:47:47 2006
+++ libmysequoia/include/CarobMySQL.hpp Wed Jan 25 09:46:24 2006
@@ -33,6 +33,9 @@
 #include <DriverResultSet.hpp>
 #include <Statement.hpp>
 
+#include <string>
+#include <vector>
+
 const unsigned long MYSEQUOIA_MAGIC = 0xC00CA10B;
 
 #define CAROB_MYSQL_CLIENT_INFO "5.0.15";
@@ -193,6 +196,11 @@
      */
   MYSQL_RES *list_tables (const char *wild);
 
+  /**
+   * Adds a command to the init command queue
+   */
+  void push_init_command(const char *cmd);
+  
        /**
         * Returns a pointer to the MYSQL structure
    */
@@ -207,6 +215,7 @@
   CarobNS::DriverResultSet * drsPtr;
   //holds the result set for 'live' type of results
   MYSQL_RES *liveResultPtr;
+  std::vector<std::string> init_cmd_list;
 
   /**
    * Private default constructor.
Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.33 
libmysequoia/src/CarobMySQL.cpp:1.34
--- libmysequoia/src/CarobMySQL.cpp:1.33        Tue Jan 24 15:47:47 2006
+++ libmysequoia/src/CarobMySQL.cpp     Wed Jan 25 09:46:23 2006
@@ -165,6 +165,11 @@
       set_connect_info(host, user, passwd, db, port);
 
       connectionPtr = newConnectionPtr;
+      
+      //try to execute the initial commands after each connection
+      std::vector<std::string>::const_iterator iter;
+      for (iter=init_cmd_list.begin(); iter != init_cmd_list.end(); iter++)
+        real_query(iter->data(), iter->length());
     }
 
     LOG4CXX_DEBUG(logger, "Leaving connect.");
@@ -229,6 +234,7 @@
     if (!stmtPtr)
     {
       stmtPtr = connectionPtr->createStatement();
+      stmtPtr->setQueryTimeout(mysqlPtr->options.read_timeout);
       stmtPtr->setFetchSize(1);
     }
   
@@ -629,6 +635,13 @@
   return result;
 }
 
+void
+CarobMYSQL::push_init_command(const char *cmd)
+{
+  LOG4CXX_DEBUG(logger, "Entering push_init_command: cmd=" << cmd);
+  LOG4CXX_DEBUG(logger, "Leaving push_init_command.");
+}
+
 MYSQL *
 CarobMYSQL::getMYSQL ()
 {
Index: libmysequoia/src/CarobStmt.cpp
diff -u libmysequoia/src/CarobStmt.cpp:1.13 libmysequoia/src/CarobStmt.cpp:1.14
--- libmysequoia/src/CarobStmt.cpp:1.13 Wed Jan 18 13:13:59 2006
+++ libmysequoia/src/CarobStmt.cpp      Wed Jan 25 09:46:23 2006
@@ -36,6 +36,9 @@
 using namespace CarobNS;
 using namespace std;
 
+#define DATA_NORMAL 1
+#define DATA_TRUNCATED 2
+
 CarobStmt::CarobStmt(MYSQL *mysql): c_stmt(0), liveResultSet(0)
 {
   LOG4CXX_DEBUG(logger, "Entering constructor.");
@@ -366,7 +369,10 @@
     }
 
     if (!result)
-      m_stmt->bind_result_done= true;
+      if (m_stmt->mysql->options.report_data_truncation)
+        m_stmt->bind_result_done = DATA_TRUNCATED;
+      else
+        m_stmt->bind_result_done = DATA_NORMAL;
   }
   
   LOG4CXX_DEBUG(logger, "Leaving bind_result.");
@@ -378,6 +384,7 @@
 {
   LOG4CXX_DEBUG(logger, "Entering fetch.");
   int result = 0;
+  bool truncation = false;
   
   if (!m_stmt->bind_result_done || (m_stmt->state < MYSQL_STMT_EXECUTE_DONE))
   {
@@ -395,8 +402,7 @@
       {
         fetch_field(fPtr, bPtr, colNo);
 
-        if (*bPtr->error)
-          result = MYSQL_DATA_TRUNCATED;
+        truncation |= *bPtr->error;
       }
       
       if (m_stmt->result.data)
@@ -407,6 +413,9 @@
         m_stmt->affected_rows = m_stmt->result.rows;
       }
       
+      if (truncation && (m_stmt->bind_result_done == DATA_TRUNCATED))
+        result = MYSQL_DATA_TRUNCATED;
+
       m_stmt->state = MYSQL_STMT_FETCH_DONE;
     }
     else
Index: libmysequoia/src/MySQLAPI.cpp
diff -u libmysequoia/src/MySQLAPI.cpp:1.31 libmysequoia/src/MySQLAPI.cpp:1.32
--- libmysequoia/src/MySQLAPI.cpp:1.31  Tue Jan 24 12:23:10 2006
+++ libmysequoia/src/MySQLAPI.cpp       Wed Jan 25 09:46:23 2006
@@ -251,9 +251,71 @@
 int STDCALL
 mysql_options (MYSQL * mysql, enum mysql_option option, const char *arg)
 {
-  LOG4CXX_DEBUG(logger, "Entering mysql_options: mysql=" << mysql);
+  LOG4CXX_DEBUG(logger, "Entering mysql_options: mysql=" << mysql << " 
option=" << option);
+
+  int result = 0;
+  
+  if (mysql && isCarobObject(mysql))
+    switch (option) {
+    //Supported options
+    case MYSQL_INIT_COMMAND:
+      getCarob(mysql)->push_init_command(arg);
+      break;
+    case MYSQL_SET_CHARSET_NAME:
+      FREE_AND_NULL_ARRAY(mysql->options.charset_name);
+      mysql->options.charset_name = cstrdup(arg);
+      break;
+    case MYSQL_READ_DEFAULT_FILE:
+      FREE_AND_NULL_ARRAY(mysql->options.my_cnf_file);
+      mysql->options.my_cnf_file = cstrdup(arg);
+      break;
+    case MYSQL_READ_DEFAULT_GROUP:
+      FREE_AND_NULL_ARRAY(mysql->options.my_cnf_group);
+      mysql->options.my_cnf_group = cstrdup(arg);
+      break;
+    case MYSQL_OPT_READ_TIMEOUT:
+    case MYSQL_OPT_WRITE_TIMEOUT:
+      //Because sequoia has only one timeout we set this two together
+      mysql->options.read_timeout = mysql->options.write_timeout = *(unsigned 
int *) arg;
+      break;
+    case MYSQL_REPORT_DATA_TRUNCATION:
+      mysql->options.report_data_truncation = *(my_bool *) arg;
+    //Unsupported options ... they are set, but not used in any way
+    case MYSQL_OPT_CONNECT_TIMEOUT:
+      mysql->options.connect_timeout = *(unsigned int *) arg;
+      break;
+    case MYSQL_OPT_COMPRESS:
+      mysql->options.client_flag |= CLIENT_COMPRESS;
+      mysql->options.compress = 1;
+      break;
+    case MYSQL_SECURE_AUTH:
+      mysql->options.secure_auth = *(my_bool *) arg;
+    case MYSQL_OPT_LOCAL_INFILE:      
+      if (!arg || *(unsigned int *)arg)
+        mysql->options.client_flag |= CLIENT_LOCAL_FILES;
+      else
+        mysql->options.client_flag &= ~CLIENT_LOCAL_FILES;
+      break;
+    case MYSQL_OPT_RECONNECT:
+      mysql->reconnect = *(my_bool *) arg;
+      break;
+    //Options that are never will be supported
+    case MYSQL_OPT_NAMED_PIPE:
+    case MYSQL_SET_CHARSET_DIR:
+    case MYSQL_OPT_PROTOCOL:
+    case MYSQL_SHARED_MEMORY_BASE_NAME:
+    case MYSQL_OPT_USE_REMOTE_CONNECTION:
+    case MYSQL_OPT_USE_EMBEDDED_CONNECTION:
+    case MYSQL_OPT_GUESS_CONNECTION:
+    case MYSQL_SET_CLIENT_IP:
+      break;
+    default:
+      result = 1;
+    }
+
   LOG4CXX_DEBUG(logger, "Leaving mysql_options.");
-  return 0;
+  
+  return result;
 }
 
 int STDCALL
@@ -379,10 +441,9 @@
 mysql_eof (MYSQL_RES * res)
 {
   LOG4CXX_DEBUG(logger, "Entering mysql_eof: res=" << res);
-
-  my_bool result = res->eof;
-
+  my_bool result = res ? res->eof : 0;
   LOG4CXX_DEBUG(logger, "Leaving mysql_eof: result=" << (bool) result);
+  
   return result;
 }
 

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

Reply via email to