Date: Tuesday, April 4, 2006 @ 14:14:24
  Author: csaba
    Path: /cvsroot/carob/libmysequoia

Modified: include/Utils.hpp (1.20 -> 1.21) src/CarobStmt.cpp (1.31 ->
          1.32) src/Utils.cpp (1.38 -> 1.39) test/TestMySQLAPI.cpp (1.33
          -> 1.34) test/TestMySQLAPI.hpp (1.12 -> 1.13)

- display only the year part of the date when requested
- added unit tests


-----------------------+
 include/Utils.hpp     |    2 +-
 src/CarobStmt.cpp     |    2 +-
 src/Utils.cpp         |   15 ++++++++++-----
 test/TestMySQLAPI.cpp |   47 +++++++++++++++++++++++++++++++++++++++++------
 test/TestMySQLAPI.hpp |    2 ++
 5 files changed, 55 insertions(+), 13 deletions(-)


Index: libmysequoia/include/Utils.hpp
diff -u libmysequoia/include/Utils.hpp:1.20 libmysequoia/include/Utils.hpp:1.21
--- libmysequoia/include/Utils.hpp:1.20 Fri Mar 24 10:02:40 2006
+++ libmysequoia/include/Utils.hpp      Tue Apr  4 14:14:24 2006
@@ -118,7 +118,7 @@
 /**
  * Convert a MYSQL_TIME structure to a character string
  */
-bool MYSQL_TIME_to_str(MYSQL_TIME *t, char *s, int maxlen);
+bool MYSQL_TIME_to_str(MYSQL_TIME *t, char *s, int maxlen, int fieldlen);
 
 /**
  * Convert a character string to a MYSQL_TIME structure
Index: libmysequoia/src/CarobStmt.cpp
diff -u libmysequoia/src/CarobStmt.cpp:1.31 libmysequoia/src/CarobStmt.cpp:1.32
--- libmysequoia/src/CarobStmt.cpp:1.31 Tue Mar 28 14:25:11 2006
+++ libmysequoia/src/CarobStmt.cpp      Tue Apr  4 14:14:24 2006
@@ -342,7 +342,7 @@
                 case MYSQL_TYPE_DATETIME:
                 case MYSQL_TYPE_TIMESTAMP:
                   char buffer[20];
-                  MYSQL_TIME_to_str((MYSQL_TIME *)p->buffer, buffer, 
sizeof(buffer));
+                  MYSQL_TIME_to_str((MYSQL_TIME *)p->buffer, buffer, 
sizeof(buffer), sizeof(buffer));
                   c_stmt->setString(no, 
to_wstring(string(buffer,strlen(buffer))));
                   break;
                 case MYSQL_TYPE_NULL:
Index: libmysequoia/src/Utils.cpp
diff -u libmysequoia/src/Utils.cpp:1.38 libmysequoia/src/Utils.cpp:1.39
--- libmysequoia/src/Utils.cpp:1.38     Wed Mar 29 13:08:42 2006
+++ libmysequoia/src/Utils.cpp  Tue Apr  4 14:14:24 2006
@@ -953,7 +953,7 @@
     case MYSQL_TYPE_VAR_STRING:
     case MYSQL_TYPE_STRING:
       convertDateTime(&date, &time, MYSQL_TIMESTAMP_TIME, false);
-      error = MYSQL_TIME_to_str(&time, (char *)bind->buffer, 
bind->buffer_length); 
+      error = MYSQL_TIME_to_str(&time, (char *)bind->buffer, 
bind->buffer_length, field->length); 
       *bind->length = strlen((char *)bind->buffer);
       break;
 
@@ -1030,7 +1030,7 @@
     case MYSQL_TYPE_VAR_STRING:
     case MYSQL_TYPE_STRING:
       convertDateTime(data, &date, MYSQL_TIMESTAMP_DATE, false);
-      error = MYSQL_TIME_to_str(&date, (char *)bind->buffer, 
bind->buffer_length); 
+      error = MYSQL_TIME_to_str(&date, (char *)bind->buffer, 
bind->buffer_length, field->length); 
       *bind->length = strlen((char *)bind->buffer);
       break;
 
@@ -1107,7 +1107,7 @@
     case MYSQL_TYPE_VAR_STRING:
     case MYSQL_TYPE_STRING:
       convertDateTime(data, &datetime, MYSQL_TIMESTAMP_DATETIME, true);
-      error = MYSQL_TIME_to_str(&datetime, (char *)bind->buffer, 
bind->buffer_length); 
+      error = MYSQL_TIME_to_str(&datetime, (char *)bind->buffer, 
bind->buffer_length, field->length); 
       *bind->length = strlen((char *)bind->buffer);
       break;
 
@@ -1135,7 +1135,7 @@
 #endif
 }
 
-bool MYSQL_TIME_to_str(MYSQL_TIME *t, char *s, int maxlen)
+bool MYSQL_TIME_to_str(MYSQL_TIME *t, char *s, int maxlen, int fieldlen)
 {
   bool result = true;
   int len;
@@ -1148,7 +1148,12 @@
       break;
       
     case MYSQL_TIMESTAMP_DATE:
-      len = snprintf(s, maxlen, "%04d-%02d-%02d", t->year, t->month, t->day);
+      if (fieldlen == 2)
+        len = snprintf(s, maxlen, "%02d", t->year % 100);
+      else if (fieldlen == 4)  
+        len = snprintf(s, maxlen, "%04d", t->year);
+      else
+        len = snprintf(s, maxlen, "%04d-%02d-%02d", t->year, t->month, t->day);
       result = (len < 0) || (len >= maxlen);
       break;
             
Index: libmysequoia/test/TestMySQLAPI.cpp
diff -u libmysequoia/test/TestMySQLAPI.cpp:1.33 
libmysequoia/test/TestMySQLAPI.cpp:1.34
--- libmysequoia/test/TestMySQLAPI.cpp:1.33     Tue Mar 28 09:19:53 2006
+++ libmysequoia/test/TestMySQLAPI.cpp  Tue Apr  4 14:14:23 2006
@@ -258,7 +258,7 @@
   // test the result field count
   CPPUNIT_ASSERT(mysql_field_count(mysql) == 8);
   
-  CPPUNIT_ASSERT((res = mysql_store_result(mysql)) != NULL);
+  CPPUNIT_ASSERT((res = mysql_store_result(mysql)) != 0);
 
   CPPUNIT_ASSERT(mysql_field_count(mysql) == mysql_num_fields(res));
 
@@ -306,7 +306,7 @@
   CPPUNIT_ASSERT(mysql_real_query(mysql, query, strlen(query)) == 0);
   
   // fetch the results
-  CPPUNIT_ASSERT((res = mysql_store_result(mysql)) != NULL);
+  CPPUNIT_ASSERT((res = mysql_store_result(mysql)) != 0);
   CPPUNIT_ASSERT(mysql_errno(mysql) == 0);
 
   // free the result set
@@ -325,7 +325,7 @@
   CPPUNIT_ASSERT(mysql_real_query(mysql, query, strlen(query)) == 0);
   
   // fetch the result set
-  CPPUNIT_ASSERT((res = mysql_use_result(mysql)) != NULL);
+  CPPUNIT_ASSERT((res = mysql_use_result(mysql)) != 0);
   CPPUNIT_ASSERT(mysql_errno(mysql) == 0);
 
   // free the result set
@@ -349,7 +349,7 @@
   CPPUNIT_ASSERT(mysql_real_query(mysql, query, strlen(query)) == 0);
   
   // fetch the result set
-  CPPUNIT_ASSERT((res = mysql_store_result(mysql)) != NULL);
+  CPPUNIT_ASSERT((res = mysql_store_result(mysql)) != 0);
   
   CPPUNIT_ASSERT(field_count = mysql_num_fields(res));
 
@@ -402,7 +402,7 @@
   CPPUNIT_ASSERT(mysql_real_query(mysql, query, strlen(query)) == 0);
   
   // fetch the result set
-  CPPUNIT_ASSERT((res = mysql_use_result(mysql)) != NULL);
+  CPPUNIT_ASSERT((res = mysql_use_result(mysql)) != 0);
 
   while ((row = mysql_fetch_row(res)) != 0)
   {
@@ -798,7 +798,7 @@
   str1[size + strlen(query_ins2)] = 0;
   
   CPPUNIT_ASSERT(mysql_query(mysql, "select * from t1") == 0);
-  CPPUNIT_ASSERT((res = mysql_use_result(mysql)) != NULL);
+  CPPUNIT_ASSERT((res = mysql_use_result(mysql)) != 0);
   CPPUNIT_ASSERT(mysql_errno(mysql) == 0);
 
   CPPUNIT_ASSERT((row = mysql_fetch_row(res)) != 0);
@@ -850,3 +850,38 @@
   delete str1;
   delete str2;
 }
+
+void TestMySQLAPI::bug_lms_6_test(void)
+{
+  MYSQL_RES *res = 0;
+  MYSQL_ROW row = 0;
+
+  CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, PASSWD1, DB1, 0, 0, 0) 
!= 0);
+
+  mysql_query(mysql, "drop table t1");
+
+  CPPUNIT_ASSERT(mysql_query(mysql, "create table t1(a year, b year(2))") == 
0);
+  CPPUNIT_ASSERT(mysql_query(mysql, "insert into t1 values (10,10), (2000,0), 
(69,69)") == 0);
+  CPPUNIT_ASSERT(mysql_query(mysql, "select * from t1") == 0);
+  
+  // fetch the result set
+  CPPUNIT_ASSERT((res = mysql_use_result(mysql)) != 0);
+  // first row
+  CPPUNIT_ASSERT((row = mysql_fetch_row(res)) != 0);
+  CPPUNIT_ASSERT(strcmp(row[0], "2010") == 0);
+  CPPUNIT_ASSERT(strcmp(row[1], "10") == 0);
+  // second row
+  CPPUNIT_ASSERT((row = mysql_fetch_row(res)) != 0);
+  CPPUNIT_ASSERT(strcmp(row[0], "2000") == 0);
+  CPPUNIT_ASSERT(strcmp(row[1], "00") == 0);
+  // third row
+  CPPUNIT_ASSERT((row = mysql_fetch_row(res)) != 0);
+/*
+ * commented out because of year 2038 bug
+ *
+ * CPPUNIT_ASSERT(strcmp(row[0], "2069") == 0);
+ * CPPUNIT_ASSERT(strcmp(row[1], "69") == 0);
+*/  
+  // free the result set
+  mysql_free_result(res);
+}
Index: libmysequoia/test/TestMySQLAPI.hpp
diff -u libmysequoia/test/TestMySQLAPI.hpp:1.12 
libmysequoia/test/TestMySQLAPI.hpp:1.13
--- libmysequoia/test/TestMySQLAPI.hpp:1.12     Mon Mar 27 14:03:29 2006
+++ libmysequoia/test/TestMySQLAPI.hpp  Tue Apr  4 14:14:23 2006
@@ -59,6 +59,7 @@
     CPPUNIT_TEST (mysql_stmt_store_fetch_test);
     CPPUNIT_TEST (mysql_stmt_long_data_fetch_field_test);
     CPPUNIT_TEST (mysql_blob_test);
+    CPPUNIT_TEST (bug_lms_6_test);
   CPPUNIT_TEST_SUITE_END ();
 
 public:
@@ -95,6 +96,7 @@
   void mysql_stmt_store_fetch_test(void);
   void mysql_stmt_long_data_fetch_field_test(void);
   void mysql_blob_test(void);
+  void bug_lms_6_test(void);
 private:
   MYSQL *mysql;
 };

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

Reply via email to