Date: Wednesday, January 11, 2006 @ 11:25:37
  Author: csaba
    Path: /cvsroot/carob/libmysequoia

   Added: include/CarobCommon.hpp (1.1) src/CarobCommon.cpp (1.1)
Modified: include/CarobMySQL.hpp (1.19 -> 1.20) include/CarobStmt.hpp (1.3
          -> 1.4) src/CarobMySQL.cpp (1.28 -> 1.29) src/CarobStmt.cpp (1.3
          -> 1.4) src/Makefile.am (1.5 -> 1.6)

Refactored the code:
- new CarobCommon class which will hold the common code
- CarobMYSQL and CarobStmt will inherit from CarobCommon
- moved looger to CarobCommon


-------------------------+
 include/CarobCommon.hpp |   60 ++++++++++++++++++++++++++++++
 include/CarobMySQL.hpp  |   27 ++-----------
 include/CarobStmt.hpp   |    5 --
 src/CarobCommon.cpp     |   92 ++++++++++++++++++++++++++++++++++++++++++++++
 src/CarobMySQL.cpp      |   71 +----------------------------------
 src/CarobStmt.cpp       |    3 -
 src/Makefile.am         |    3 +
 7 files changed, 161 insertions(+), 100 deletions(-)


Index: libmysequoia/include/CarobCommon.hpp
diff -u /dev/null libmysequoia/include/CarobCommon.hpp:1.1
--- /dev/null   Wed Jan 11 11:25:37 2006
+++ libmysequoia/include/CarobCommon.hpp        Wed Jan 11 11:25:37 2006
@@ -0,0 +1,60 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005-2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Zsolt Simon, Csaba Simon
+ * Contributor(s): 
+ */
+
+#ifndef _CAROBCOMMON_HPP
+#define _CAROBCOMMON_HPP
+
+// mysql includes
+#include <mysql_wrapper.h>
+
+// carob includes
+#include <ResultSetMetaData.hpp>
+
+// include log4cxx header files.
+#include <log4cxx/logger.h>
+
+class CarobCommon
+{
+protected:
+  /**
+   * Protected constructor
+   */
+  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
+   * @return numer of fields in the query
+   */
+  int get_query_fields (MYSQL_FIELD * &result, CarobNS::ResultSetMetaData 
*rsmPtr);
+
+  /**
+   * Release allocated field structure from the memory
+   * @param fields a pointer to the field structure
+   */
+  static void delete_query_fields (MYSQL_FIELD * &fields, unsigned int 
field_count);
+
+  // logger
+  static log4cxx::LoggerPtr logger;
+};
+
+#endif /*_CAROBCOMMON_HPP*/
Index: libmysequoia/include/CarobMySQL.hpp
diff -u libmysequoia/include/CarobMySQL.hpp:1.19 
libmysequoia/include/CarobMySQL.hpp:1.20
--- libmysequoia/include/CarobMySQL.hpp:1.19    Tue Jan 10 12:22:44 2006
+++ libmysequoia/include/CarobMySQL.hpp Wed Jan 11 11:25:37 2006
@@ -22,6 +22,8 @@
 #ifndef _CAROBMYSQL_HPP
 #define _CAROBMYSQL_HPP
 
+#include <CarobCommon.hpp>
+
 /* MySQL includes */
 #include <mysql_wrapper.h>
 
@@ -31,9 +33,6 @@
 #include <DriverResultSet.hpp>
 #include <Statement.hpp>
 
-// include log4cxx header files.
-#include <log4cxx/logger.h>
-
 const unsigned long MYSEQUOIA_MAGIC = 0xC00CA10B;
 
 #define CAROB_MYSQL_CLIENT_INFO "5.0.15";
@@ -42,7 +41,7 @@
 
 #define LOGGER_CONFIG_FILE "logger.cfg"
 
-class CarobMYSQL
+class CarobMYSQL : public CarobCommon
 {
 friend class CarobStmt;
 
@@ -209,13 +208,10 @@
   //holds the result set for 'live' type of results
   MYSQL_RES *liveResultPtr;
 
-  // logger
-  static log4cxx::LoggerPtr logger;
-
   /**
    * Private default constructor.
    */
-    CarobMYSQL ()
+  CarobMYSQL ()
   {
   }
 
@@ -253,21 +249,6 @@
   void set_error (int errcode, const char *errmsg, const char *sqlstate);
 
   /**
-   * Allocates the field info for a query
-   * @param result the resulting MYSQL_FIELD structure
-   * @param drsPtr a pointer containing the driver resultset from sequoia
-   * @return numer of fields in the query
-   */
-  int get_query_fields (MYSQL_FIELD * &result,
-                       CarobNS::DriverResultSet * rsPtr);
-
-  /**
-   * Release allocated field structure from the memory
-   * @param fields a pointer to the field structure
-   */
-  static void delete_query_fields (MYSQL_FIELD * &fields, unsigned int 
field_count);
-
-  /**
    * Allocates a row from the freshly fetched results
    * @param row the resulting row
    * @param fields pointer to the field structure to update the max column 
length or null
Index: libmysequoia/include/CarobStmt.hpp
diff -u libmysequoia/include/CarobStmt.hpp:1.3 
libmysequoia/include/CarobStmt.hpp:1.4
--- libmysequoia/include/CarobStmt.hpp:1.3      Tue Jan 10 12:22:44 2006
+++ libmysequoia/include/CarobStmt.hpp  Wed Jan 11 11:25:37 2006
@@ -30,7 +30,7 @@
 //Carob includes
 #include <ParameterStatement.hpp>
 
-class CarobStmt
+class CarobStmt : public CarobCommon
 {
 public:
   CarobStmt(MYSQL *mysql);
@@ -54,9 +54,6 @@
   CarobNS::ParameterStatement *c_stmt;
   CarobMYSQL *cmysql;
 
-  // logger
-  static log4cxx::LoggerPtr logger;
-
   void clear();
 
   /**
Index: libmysequoia/src/CarobCommon.cpp
diff -u /dev/null libmysequoia/src/CarobCommon.cpp:1.1
--- /dev/null   Wed Jan 11 11:25:37 2006
+++ libmysequoia/src/CarobCommon.cpp    Wed Jan 11 11:25:37 2006
@@ -0,0 +1,92 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005-2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Zsolt Simon, Csaba Simon
+ * Contributor(s): 
+ */
+
+#include <CarobCommon.hpp>
+#include <Utils.hpp>
+
+using namespace CarobNS;
+using namespace log4cxx;
+
+LoggerPtr CarobCommon::logger(Logger::getLogger("MySQLAPI.Carob"));
+
+int
+CarobCommon::get_query_fields (MYSQL_FIELD * &result, 
CarobNS::ResultSetMetaData *rsmPtr)
+{
+  LOG4CXX_DEBUG(logger, "Entering get_query_fields.");
+  
+  int colNum = (int)rsmPtr->getColumnCount(), colNo;
+  
+  result = new MYSQL_FIELD[colNum];
+  memset(result, 0, sizeof(MYSQL_FIELD)*colNum);
+
+  MYSQL_FIELD *colPtr;
+  for (colNo=1, colPtr=result; colNo <= colNum; colNo++, colPtr++)
+  {
+    convert_to_pchar(rsmPtr->getColumnLabel(colNo), colPtr->name, 
colPtr->name_length);
+    convert_to_pchar(rsmPtr->getColumnName(colNo), colPtr->org_name, 
colPtr->org_name_length);
+    convert_to_pchar(rsmPtr->getTableName(colNo), colPtr->table, 
colPtr->table_length);
+    colPtr->org_table = colPtr->table;
+    colPtr->org_table_length = colPtr->table_length;
+    //TODO if possible colPtr->db;
+    convert_to_pchar(rsmPtr->getCatalogName(colNo), colPtr->catalog, 
colPtr->catalog_length);
+    //TODO if possible colPtr->def;
+
+    colPtr->length = rsmPtr->getPrecision(colNo);
+    colPtr->decimals = rsmPtr->getScale(colNo);
+
+    //TODO more compatible flags...
+    colPtr->type = sql_to_mysql_type(rsmPtr->getColumnType(colNo));
+
+    colPtr->flags = (rsmPtr->isNullable(colNo) ? 0 : NOT_NULL_FLAG) |
+                    (rsmPtr->isAutoIncrement(colNo) ? AUTO_INCREMENT_FLAG : 0) 
|
+                    (rsmPtr->isSigned(colNo) ? 0 : UNSIGNED_FLAG) |
+                    (colPtr->type == MYSQL_TYPE_BLOB ? BLOB_FLAG : 0) |
+                    (IS_NUM(colPtr->type) && colPtr->type != 
MYSQL_TYPE_TIMESTAMP && 
+                      colPtr->type != MYSQL_TYPE_NULL ? NUM_FLAG : 0) | 
+                    (colPtr->type == MYSQL_TYPE_TIMESTAMP ? TIMESTAMP_FLAG : 
0) | 
+                    NO_DEFAULT_VALUE_FLAG;
+  }
+  
+  LOG4CXX_DEBUG(logger, "Leaving get_query_fields.");
+  return colNum;
+}
+
+void
+CarobCommon::delete_query_fields(MYSQL_FIELD * &fields, unsigned int 
field_count)
+{
+  LOG4CXX_DEBUG(logger, "Entering delete_query_fields.");
+  
+  if (fields)
+  {
+    for (MYSQL_FIELD *colPtr=fields; field_count; colPtr++, field_count--)
+    {
+      delete colPtr->name;
+      delete colPtr->org_name;
+      delete colPtr->table;
+      delete colPtr->db;
+      delete colPtr->catalog;
+    }
+    
+    FREE_AND_NULL_ARRAY(fields);
+  }
+
+  LOG4CXX_DEBUG(logger, "Leaving delete_query_fields.");
+}
Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.28 
libmysequoia/src/CarobMySQL.cpp:1.29
--- libmysequoia/src/CarobMySQL.cpp:1.28        Tue Jan 10 08:56:10 2006
+++ libmysequoia/src/CarobMySQL.cpp     Wed Jan 11 11:25:37 2006
@@ -28,9 +28,6 @@
 #include <errmsg.h>
 
 using namespace CarobNS;
-using namespace log4cxx;
-
-LoggerPtr CarobMYSQL::logger(Logger::getLogger("MySQLAPI.Carob"));
 
 CarobMYSQL::CarobMYSQL (MYSQL *mysql, my_bool free_me) :
    connectionPtr(0), stmtPtr(0), drsPtr(0), liveResultPtr(0)
@@ -261,7 +258,8 @@
         memset(result, 0, sizeof(MYSQL_RES));
 
         //Fill the fields metadata        
-        result->field_count = get_query_fields(result->fields, drsPtr);
+        ResultSetMetaData rsmd(drsPtr);
+        result->field_count = get_query_fields(result->fields, &rsmd);
         result->handle = mysqlPtr;
         result->lengths = new unsigned long[result->field_count];
         
@@ -661,71 +659,6 @@
   LOG4CXX_DEBUG(logger, "Leaving set_error.");
 }
 
-int
-CarobMYSQL::get_query_fields(MYSQL_FIELD * &result, DriverResultSet *rsPtr)
-{
-  LOG4CXX_DEBUG(logger, "Entering get_query_fields.");
-  
-  ResultSetMetaData rsmd(rsPtr);
-  int colNum = (int)rsmd.getColumnCount(), colNo;
-  
-  result = new MYSQL_FIELD[colNum];
-  memset(result, 0, sizeof(MYSQL_FIELD)*colNum);
-
-  MYSQL_FIELD *colPtr;
-  for (colNo=1, colPtr=result; colNo <= colNum; colNo++, colPtr++)
-  {
-    convert_to_pchar(rsmd.getColumnLabel(colNo), colPtr->name, 
colPtr->name_length);
-    convert_to_pchar(rsmd.getColumnName(colNo), colPtr->org_name, 
colPtr->org_name_length);
-    convert_to_pchar(rsmd.getTableName(colNo), colPtr->table, 
colPtr->table_length);
-    colPtr->org_table = colPtr->table;
-    colPtr->org_table_length = colPtr->table_length;
-    //TODO if possible colPtr->db;
-    convert_to_pchar(rsmd.getCatalogName(colNo), colPtr->catalog, 
colPtr->catalog_length);
-    //TODO if possible colPtr->def;
-
-    colPtr->length = rsmd.getPrecision(colNo);
-    colPtr->decimals = rsmd.getScale(colNo);
-
-    //TODO more compatible flags...
-    colPtr->type = sql_to_mysql_type(rsmd.getColumnType(colNo));
-
-    colPtr->flags = (rsmd.isNullable(colNo) ? 0 : NOT_NULL_FLAG) |
-                    (rsmd.isAutoIncrement(colNo) ? AUTO_INCREMENT_FLAG : 0) |
-                    (rsmd.isSigned(colNo) ? 0 : UNSIGNED_FLAG) |
-                    (colPtr->type == MYSQL_TYPE_BLOB ? BLOB_FLAG : 0) |
-                    (IS_NUM(colPtr->type) && colPtr->type != 
MYSQL_TYPE_TIMESTAMP && 
-                      colPtr->type != MYSQL_TYPE_NULL ? NUM_FLAG : 0) | 
-                    (colPtr->type == MYSQL_TYPE_TIMESTAMP ? TIMESTAMP_FLAG : 
0) | 
-                    NO_DEFAULT_VALUE_FLAG;
-  }
-  
-  LOG4CXX_DEBUG(logger, "Leaving get_query_fields.");
-  return colNum;
-}
-
-void
-CarobMYSQL::delete_query_fields(MYSQL_FIELD * &fields, unsigned int 
field_count)
-{
-  LOG4CXX_DEBUG(logger, "Entering delete_query_fields.");
-  
-  if (fields)
-  {
-    for (MYSQL_FIELD *colPtr=fields; field_count; colPtr++, field_count--)
-    {
-      delete colPtr->name;
-      delete colPtr->org_name;
-      delete colPtr->table;
-      delete colPtr->db;
-      delete colPtr->catalog;
-    }
-    
-    FREE_AND_NULL_ARRAY(fields);
-  }
-
-  LOG4CXX_DEBUG(logger, "Leaving delete_query_fields.");
-}
-
 typedef char *PCHAR;
 
 void
Index: libmysequoia/src/CarobStmt.cpp
diff -u libmysequoia/src/CarobStmt.cpp:1.3 libmysequoia/src/CarobStmt.cpp:1.4
--- libmysequoia/src/CarobStmt.cpp:1.3  Tue Jan 10 12:22:44 2006
+++ libmysequoia/src/CarobStmt.cpp      Wed Jan 11 11:25:37 2006
@@ -33,12 +33,9 @@
 #include <my_alloc.h>
 #include <errmsg.h>
 
-using namespace log4cxx;
 using namespace CarobNS;
 using namespace std;
 
-LoggerPtr CarobStmt::logger(Logger::getLogger("MySQLAPI.CarobStmt"));
-
 CarobStmt::CarobStmt(MYSQL *mysql): c_stmt(0)
 {
   LOG4CXX_DEBUG(logger, "Entering constructor.");
Index: libmysequoia/src/Makefile.am
diff -u libmysequoia/src/Makefile.am:1.5 libmysequoia/src/Makefile.am:1.6
--- libmysequoia/src/Makefile.am:1.5    Tue Jan 10 08:56:10 2006
+++ libmysequoia/src/Makefile.am        Wed Jan 11 11:25:37 2006
@@ -22,7 +22,8 @@
 
 lib_LTLIBRARIES = libmysequoia.la
 
-libmysequoia_la_SOURCES  = CarobMySQL.cpp \
+libmysequoia_la_SOURCES  = CarobCommon.cpp \
+                                                                               
                         CarobMySQL.cpp \
                                                                                
                         CarobStmt.cpp \
                            MySQLAPI.cpp \
                            Utils.cpp \

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

Reply via email to