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

Modified: include/CarobMySQL.hpp (1.33 -> 1.34) src/CarobMySQL.cpp (1.77
          -> 1.78) test/TestMySQLAPI.cpp (1.37 -> 1.38)
          test/TestMySQLAPI.hpp (1.15 -> 1.16)

Implemented mysql_warning_count() for statements. Fixes for LMS-16


------------------------+
 include/CarobMySQL.hpp |    5 +++++
 src/CarobMySQL.cpp     |   25 ++++++++++++++++++++++++-
 test/TestMySQLAPI.cpp  |   25 +++++++++++++++++++++++++
 test/TestMySQLAPI.hpp  |    2 ++
 4 files changed, 56 insertions(+), 1 deletion(-)


Index: libmysequoia/include/CarobMySQL.hpp
diff -u libmysequoia/include/CarobMySQL.hpp:1.33 
libmysequoia/include/CarobMySQL.hpp:1.34
--- libmysequoia/include/CarobMySQL.hpp:1.33    Wed Apr 19 08:54:27 2006
+++ libmysequoia/include/CarobMySQL.hpp Thu Jul 13 16:30:51 2006
@@ -111,6 +111,11 @@
      */
   bool real_query (const char *query, ulong length, bool parse = true);
 
+  /**
+   * Returns the number of warnings
+   */
+  unsigned int get_warning_count(void);
+
     /**
      * Gets the result of the query in MYSQL_RES format, and set the 
correspondent
      * MYSQL fields. If fetch_all is specified it will fetch all rows from the
Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.77 
libmysequoia/src/CarobMySQL.cpp:1.78
--- libmysequoia/src/CarobMySQL.cpp:1.77        Tue Jul 11 16:56:07 2006
+++ libmysequoia/src/CarobMySQL.cpp     Thu Jul 13 16:30:51 2006
@@ -329,6 +329,8 @@
       }
   
       FREE_AND_NULL_ARRAY(mysqlPtr->info);
+      
+      mysqlPtr->warning_count = 0;
   
       if (stmtPtr->execute(to_wstring(std::string(query,length))))
       {
@@ -336,6 +338,8 @@
         drsPtr = stmtPtr->getResultSet();
         mysqlPtr->field_count = drsPtr ? drsPtr->getNumberOfColumns() : 0;
         mysqlPtr->status = MYSQL_STATUS_GET_RESULT;
+        mysqlPtr->warning_count = get_warning_count();
+
         LOG4CXX_INFO(logger, "Executed query with result set. Field_count=" << 
mysqlPtr->field_count);
       }
       else
@@ -343,9 +347,10 @@
         mysqlPtr->affected_rows = stmtPtr->getUpdateCount();
         mysqlPtr->status = MYSQL_STATUS_READY;
         mysqlPtr->field_count = 0;
+        mysqlPtr->warning_count = get_warning_count();
         
         char info[100];
-        snprintf(info, sizeof(info), "Records: %llu  Duplicates: 0  Warnings: 
0", mysqlPtr->affected_rows);
+        snprintf(info, sizeof(info), "Records: %llu  Duplicates: 0  Warnings: 
%u", mysqlPtr->affected_rows, mysqlPtr->warning_count);
         info[sizeof(info)-1] = 0;
         mysqlPtr->info = cstrdup(info);
         LOG4CXX_INFO(logger, "Executed query. Affected_rows=" << 
mysqlPtr->affected_rows);
@@ -389,6 +394,24 @@
   }
 }
 
+unsigned int
+CarobMYSQL::get_warning_count(void)
+{
+    unsigned int result = 0;
+
+    if (stmtPtr)
+    {
+        SQLWarning *warnings = stmtPtr->getWarnings();
+        while (warnings)
+        {
+            result++;
+            warnings = (SQLWarning *)warnings->getNext();
+        }
+    }
+    
+    return result;
+}
+
 MYSQL_RES *
 CarobMYSQL::get_results (my_bool fetch_all)
 {
Index: libmysequoia/test/TestMySQLAPI.cpp
diff -u libmysequoia/test/TestMySQLAPI.cpp:1.37 
libmysequoia/test/TestMySQLAPI.cpp:1.38
--- libmysequoia/test/TestMySQLAPI.cpp:1.37     Tue Jul 11 16:56:07 2006
+++ libmysequoia/test/TestMySQLAPI.cpp  Thu Jul 13 16:30:51 2006
@@ -925,3 +925,28 @@
   
   CPPUNIT_ASSERT(mysql_stmt_close(stmt) == 0); 
 }
+
+void TestMySQLAPI::mysql_warning_count_test(void)
+{
+  CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, PASSWD1, DB1, 0, 0, 0) 
!= 0);
+
+  mysql_query(mysql, "drop table t1, t2");
+
+  CPPUNIT_ASSERT(mysql_query(mysql, "drop table if exists t1") == 0);
+  CPPUNIT_ASSERT(mysql_warning_count(mysql) == 1);
+
+  CPPUNIT_ASSERT(mysql_query(mysql, "create table t1 (a int)") == 0);
+  CPPUNIT_ASSERT(mysql_warning_count(mysql) == 0);
+
+  CPPUNIT_ASSERT(mysql_query(mysql, "create table t2 (a int)") == 0);
+  CPPUNIT_ASSERT(mysql_warning_count(mysql) == 0);
+
+  CPPUNIT_ASSERT(mysql_query(mysql, "insert into t2 values (1),(2)") == 0);
+  CPPUNIT_ASSERT(mysql_warning_count(mysql) == 0);
+
+  CPPUNIT_ASSERT(mysql_query(mysql, "insert into t1 select * from t2") == 0);
+  CPPUNIT_ASSERT(mysql_warning_count(mysql) == 0);
+
+  CPPUNIT_ASSERT(mysql_query(mysql, "delete ignore from t1 where t1.a <> 
(select a from t2)") == 0);
+  CPPUNIT_ASSERT(mysql_warning_count(mysql) == 1);
+}
Index: libmysequoia/test/TestMySQLAPI.hpp
diff -u libmysequoia/test/TestMySQLAPI.hpp:1.15 
libmysequoia/test/TestMySQLAPI.hpp:1.16
--- libmysequoia/test/TestMySQLAPI.hpp:1.15     Mon Apr 10 09:34:50 2006
+++ libmysequoia/test/TestMySQLAPI.hpp  Thu Jul 13 16:30:51 2006
@@ -62,6 +62,7 @@
     CPPUNIT_TEST (bug_lms_6_test);
     CPPUNIT_TEST (bug_lms_9_test);
     CPPUNIT_TEST (bug_lms_10_test);
+    CPPUNIT_TEST (mysql_warning_count_test);
   CPPUNIT_TEST_SUITE_END ();
 
 public:
@@ -101,6 +102,7 @@
   void bug_lms_6_test(void);
   void bug_lms_9_test(void);
   void bug_lms_10_test(void);
+  void mysql_warning_count_test(void);
 private:
   MYSQL *mysql;
 };

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

Reply via email to