List:MySQL++« Previous MessageNext Message »
From:Chris Frey Date:May 11 2005 6:57am
Subject:[PATCH] documentation and type_info fix
View as plain text  
Hi,

Below is a patch that contains a couple suggested documentation changes,
as well as an explanation of how the type system works in type_info.{h,cpp}.

The documentation describes what I was able to reverse engineer from
the code. :-)

Also in type_info.cpp, I changed part of the type lookup table, to match
what I believe is intended: for every entry marked true, there should be
a unique typeid() value.  Where there were duplicate typeid() entries,
I left the last one set as true, as that is the one used when you look
at the for loop in the mysql_ti_sql_type_info_lookup constructor.

Feedback welcome,
- Chris


Index: software/mysql++/Wishlist
diff -u software/mysql++/Wishlist:1.1.1.21 software/mysql++/Wishlist:1.3
--- software/mysql++/Wishlist:1.1.1.21	Wed May 11 01:16:59 2005
+++ software/mysql++/Wishlist	Wed May 11 01:52:30 2005
@@ -127,3 +127,8 @@
 	  reorganization in 1.7.20: if you move everything from row.cc to
 	  a new row2.h file and include it in a few strategic locations, it
 	  works.  But, this is a bogus fix.  Find the right one.
+
+	o Document the header layout, and which headers can be included alone,
+	  and which can't.  Do this to optimize compile times, and allow
+	  users to do the same.
+
Index: software/mysql++/lib/null.h
diff -u software/mysql++/lib/null.h:1.1.1.5 software/mysql++/lib/null.h:1.6
--- software/mysql++/lib/null.h:1.1.1.5	Wed May 11 01:17:05 2005
+++ software/mysql++/lib/null.h	Wed May 11 02:40:10 2005
@@ -49,7 +49,9 @@
 ///
 /// This template is necessary because there is nothing in the C++ type
 /// system with the same semantics as SQL's null.  (No, NULL from
-/// stddef.h is not the same!)
+/// stddef.h is not the same!)  This template mechanism also
+/// makes the typeid() unique for each C++-equivalent of nullable
+/// SQL field types, which are listed in type_info.cpp.
 template <class Type, class Behavior = NullisNull>
 class Null {
 public:
Index: software/mysql++/lib/type_info.cpp
diff -u software/mysql++/lib/type_info.cpp:1.1.1.3 software/mysql++/lib/type_info.cpp:1.3
--- software/mysql++/lib/type_info.cpp:1.1.1.3	Mon May  2 05:00:10 2005
+++ software/mysql++/lib/type_info.cpp	Wed May 11 02:40:10 2005
@@ -14,6 +14,32 @@
 
 typedef string Enum;
 
+//
+// This array is, somewhat, in the order of the /usr/include/mysql/mysql_com.h
+// enum_field_types list, which is why there are some duplicates.  It
+// provides a handy lookup table to translate SQL types (the index of the
+// array) into C++ types (the typeid()).
+//
+// The entire list is duplicated, to provide unique C++ types for non-null
+// and null fields.  Null fields are handled by the Null template (null.h).
+//
+// The hard coded number in this list is "base_type", which roughly
+// corresponds to the actual value of enum_field_types.  Given a
+// enum_field_type value, and a flag whether it is null and/or unsigned,
+// the mysql_type_info::type(...) function below will give you an index
+// into this array, and thereby convert enum_field_type into a C++ type.
+//
+// Types marked true (the "default" field) are added to a lookup map in
+// the mysql_type_info_lookup class in order to provide reverse lookup
+// of C++ types to SQL types.  Put another way, if you take the subset
+// of all items marked true, the typeid() of each item must be unique.
+//
+// Opinion:  This seems a very brittle way to code type info, especially
+//           considering the sheer infrastructure in these two files
+//           (type_info.{h,cpp}).  Would be nice if we used the mysql
+//           constant names so we would not be vulnerable to number
+//           changes in the main mysql C API.
+//
 const mysql_type_info::sql_type_info mysql_type_info::types[62] = {
 	sql_type_info("DECIMAL NOT NULL", typeid(double), 0),
 	sql_type_info("TINYINT NOT NULL", typeid(signed char), 1, true),
@@ -39,10 +65,10 @@
 	sql_type_info("CHAR NOT NULL", typeid(string), 21),
 	sql_type_info("TINYINT UNSIGNED NOT NULL", typeid(unsigned char), 22, true),
 	sql_type_info("SMALLINT UNSIGNED NOT NULL", typeid(unsigned short int), 23, true),
-	sql_type_info("INT UNSIGNED NOT NULL", typeid(unsigned int), 24, true),
-	sql_type_info("INT UNSIGNED NOT NULL", typeid(unsigned int), 25, true),
-	sql_type_info("INT UNSIGNED NOT NULL", typeid(unsigned int), 26, true),
-	sql_type_info("INT UNSIGNED NOT NULL", typeid(unsigned int), 27, true),
+	sql_type_info("INT UNSIGNED NOT NULL", typeid(unsigned int), 24),
+	sql_type_info("INT UNSIGNED NOT NULL", typeid(unsigned int), 25),
+	sql_type_info("INT UNSIGNED NOT NULL", typeid(unsigned int), 26),
+	sql_type_info("INT UNSIGNED NOT NULL", typeid(unsigned int), 27),
 	sql_type_info("INT UNSIGNED NOT NULL", typeid(unsigned int), 28, true),
 	sql_type_info("BIGINT UNSIGNED NOT NULL", typeid(ulonglong), 29, true),
 	sql_type_info("MEDIUMINT UNSIGNED NOT NULL", typeid(unsigned int), 30),
@@ -71,10 +97,10 @@
 	sql_type_info("CHAR NULL", typeid(Null < string >), 21),
 	sql_type_info("TINYINT UNSIGNED NULL", typeid(Null < unsigned char >), 22, true),
 	sql_type_info("SMALLINT UNSIGNED NULL", typeid(Null < unsigned short int >), 23,
true),
-	sql_type_info("INT UNSIGNED NULL", typeid(Null < unsigned int >), 24, true),
-	sql_type_info("INT UNSIGNED NULL", typeid(Null < unsigned int >), 25, true),
-	sql_type_info("INT UNSIGNED NULL", typeid(Null < unsigned int >), 26, true),
-	sql_type_info("INT UNSIGNED NULL", typeid(Null < unsigned int >), 27, true),
+	sql_type_info("INT UNSIGNED NULL", typeid(Null < unsigned int >), 24),
+	sql_type_info("INT UNSIGNED NULL", typeid(Null < unsigned int >), 25),
+	sql_type_info("INT UNSIGNED NULL", typeid(Null < unsigned int >), 26),
+	sql_type_info("INT UNSIGNED NULL", typeid(Null < unsigned int >), 27),
 	sql_type_info("INT UNSIGNED NULL", typeid(Null < unsigned int >), 28, true),
 	sql_type_info("BIGINT UNSIGNED NULL", typeid(Null < ulonglong >), 29, true),
 	sql_type_info("MEDIUMINT UNSIGNED NULL", typeid(Null < unsigned int >), 30),

Thread
[PATCH] documentation and type_info fixChris Frey11 May
  • Re: [PATCH] documentation and type_info fixWarren Young12 May
    • Re: [PATCH] documentation and type_info fixWarren Young13 May
    • Re: [PATCH] documentation and type_info fixChris Frey13 May
      • Re: [PATCH] documentation and type_info fixWarren Young13 May
        • Re: [PATCH] documentation and type_info fixChris Frey13 May
        • Re: [PATCH] documentation and type_info fixWarren Young13 May
          • Re: [PATCH] documentation and type_info fixWarren Young13 May
      • Re: [PATCH] documentation and type_info fixChris Frey18 May
        • Re: [PATCH] documentation and type_info fixWarren Young18 May
          • Re: [PATCH] documentation and type_info fixChris Frey18 May