Author: wyoung
Date: Thu Feb  7 05:14:01 2008
New Revision: 2165

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2165&view=rev
Log:
Replaced the assert() on failing to look up MySQL C API type information
from C++ type info in mysql_type_info::types[] with a new non-optional
exception, TypeLookupFailed.

Modified:
    trunk/doc/userman/breakages.dbx
    trunk/doc/userman/tutorial.dbx
    trunk/lib/exceptions.h
    trunk/lib/type_info.h

Modified: trunk/doc/userman/breakages.dbx
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/doc/userman/breakages.dbx?rev=2165&r1=2164&r2=2165&view=diff
==============================================================================
--- trunk/doc/userman/breakages.dbx (original)
+++ trunk/doc/userman/breakages.dbx Thu Feb  7 05:14:01 2008
@@ -841,25 +841,30 @@
         this affects you, see <xref linkend="ssqls-vc2003"/> for
         suggestions on ways to cope.</para>
 
-        <para>If you aren&rsquo;t using the <type>sql_*</type> data
-        types in your SSQLSes there&rsquo;s a chance your program may
-        crash when using that SSQLS. <footnote><para>These typedefs
+        <para>If you are using types other than MySQL++&rsquo;s
+        <type>sql_*</type> ones <footnote><para>These typedefs
         have been available since MySQL++ v2.1.</para></footnote>
-        This version of MySQL++ is stricter about mapping SQL to C++
-        type information, and vice versa. You know you&rsquo;ve
-        run across this if you get a run-time assertion about
-        <computeroutput>it != map_.end()</computeroutput> in
-        <filename>lib/type_info.h</filename>, on or around line
-        121. It means MySQL++ fell off the end of its internal SQL
-        to C++ data type map<footnote><para>This map is built from
+        in your SSQLSes, code that previously worked may now see
+        <classname>TypeLookupFailed</classname> exceptions. (This
+        can be thrown even if exceptions are otherwise disabled in
+        MySQL++.) This version of MySQL++ is stricter about mapping
+        SQL to C++ type information, and vice versa. If the library
+        can&rsquo;t find a suitable mapping from one type system
+        to the other, it throws this exception, because its only
+        other option would be to crash or raise an assertion. This
+        typically happens when building SQL queries, so you can
+        probably handle it the same way as if the subsequent
+        query excecution failed. If you&rsquo;re catching the
+        generic <classname>mysqlpp::Exception</classname>, your
+        error handling code might not need to change. If you see
+        this exception, it does mean you need to look into your
+        use of data types, though. The table that controls this is
         <varname>mysql_type_info::types</varname>, defined at the top
-        of <filename>lib/type_info.cpp</filename>.</para></footnote>
-        when looking for appropriate conversion information.
-        Every data type in <filename>lib/sql_types.h</filename>
-        has a corresponding record in the type map, so if you stick
-        to those types, you&rsquo;ll be fine. It's also okay to
-        use types your C++ compiler can convert directly to these
-        predefined types.</para>
+        of <filename>lib/type_info.cpp</filename>. Every data type in
+        <filename>lib/sql_types.h</filename> has a corresponding record
+        in this table, so if you stick to those types, you&rsquo;ll
+        be fine. It&rsquo;s also okay to use types your C++ compiler
+        can convert directly to these predefined types.</para>
       </sect4>
 
 

Modified: trunk/doc/userman/tutorial.dbx
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/doc/userman/tutorial.dbx?rev=2165&r1=2164&r2=2165&view=diff
==============================================================================
--- trunk/doc/userman/tutorial.dbx (original)
+++ trunk/doc/userman/tutorial.dbx Thu Feb  7 05:14:01 2008
@@ -232,48 +232,48 @@
   <sect2 id="exceptions" xreflabel="exceptions">
     <title>Exceptions</title>
 
-    <para>By default, MySQL++ uses exceptions to signal errors. Most of
-    the examples have a full set of exception handlers. This is worthy
-    of emulation.</para>
-
-    <para>All of MySQL++&rsquo;s custom exceptions derive from a common
-    base class, <ulink type="classref" url="Exception"/>. That in turn
-    derives from Standard C++&rsquo;s
-    <classname>std::exception</classname> class. Since the library can
-    indirectly cause exceptions to come from the Standard C++ Library,
-    it&rsquo;s possible to catch all exceptions from MySQL++ by just
-    catching <classname>std::exception</classname>.  However, it&rsquo;s
-    better to have individual catch blocks for each of the concrete
-    exception types that you expect, and add a handler for either
-    <classname>Exception</classname> or
-    <classname>std::exception</classname> to act as a
+    <para>By default, MySQL++ uses exceptions to signal errors. Most
+    of the examples have a full set of exception handlers. This is
+    worthy of emulation.</para>
+
+    <para>All of MySQL++&rsquo;s custom exceptions
+    derive from a common base class, <ulink type="classref"
+    url="Exception"/>. That in turn derives from Standard C++&rsquo;s
+    <classname>std::exception</classname> class. Since the library
+    can indirectly cause exceptions to come from the Standard
+    C++ Library, it&rsquo;s possible to catch all exceptions from
+    MySQL++ by just catching <classname>std::exception</classname>.
+    However, it&rsquo;s better to have individual catch blocks
+    for each of the concrete exception types that you expect, and
+    add a handler for either <classname>Exception</classname>
+    or <classname>std::exception</classname> to act as a
     &ldquo;catch-all&rdquo; for unexpected exceptions.</para>
 
-    <para>Some of these exceptions are optional. When exceptions are
-    disabled on a MySQL++ object, it signals errors in some other way,
-    typically by returning an error code or setting an error flag.
-    Classes that support this feature derive from <ulink type="classref"
-    url="OptionalExceptions"/>.  Moreover, when such an object creates
-    another object that also derives from this interface, it passes on
-    its exception flag. Since everything flows from the <ulink
-    type="classref" url="Connection"/> object, disabling exceptions on
-    it at the start of the program disables all optional exceptions. You
-    can see this technique at work in the
-    <filename>simple[1-3]</filename> examples, which keeps them, well,
-    simple.</para>
-
-    <para>Real-world code typically can&rsquo;t afford to lose out on
-    the additional information and control offered by exceptions. But at
-    the same time, it is still sometimes useful to disable exceptions
-    temporarily. To do this, put the section of code that you want to
-    not throw exceptions inside a block, and create a <ulink
-    type="classref" url="NoExceptions"/> object at the top of that
-    block. When created, it saves the exception flag of the
-    <classname>OptionalExceptions</classname> derivative you pass to it,
-    and then disables exceptions on it. When the
-    <classname>NoExceptions</classname> object goes out of scope at the
-    end of the block, it restores the exceptions flag to its previous
-    state:</para>
+    <para>Most of these exceptions are optional. When exceptions
+    are disabled on a MySQL++ object, it signals errors in some
+    other way, typically by returning an error code or setting
+    an error flag. Classes that support this feature derive from
+    <ulink type="classref" url="OptionalExceptions"/>. Moreover,
+    when such an object creates another object that also derives from
+    this interface, it passes on its exception flag. Since everything
+    flows from the <ulink type="classref" url="Connection"/> object,
+    disabling exceptions on it at the start of the program disables
+    all optional exceptions. You can see this technique at work in
+    the <filename>simple[1-3]</filename> examples, which keeps them,
+    well, simple.</para>
+
+    <para>Real-world code typically can&rsquo;t afford to lose
+    out on the additional information and control offered by
+    exceptions. But at the same time, it is still sometimes useful
+    to disable exceptions temporarily. To do this, put the section
+    of code that you want to not throw exceptions inside a block,
+    and create a <ulink type="classref" url="NoExceptions"/> object
+    at the top of that block. When created, it saves the exception
+    flag of the <classname>OptionalExceptions</classname> derivative
+    you pass to it, and then disables exceptions on it. When the
+    <classname>NoExceptions</classname> object goes out of scope
+    at the end of the block, it restores the exceptions flag to its
+    previous state:</para>
 
     <programlisting>mysqlpp::Connection con(...); // exceptions enabled
 
@@ -290,14 +290,14 @@
     passing a copy; the two objects&rsquo; flags operate independently.
     There&rsquo;s no way to globally enable or disable this flag on
     existing objects in a single call. If you&rsquo;re using the
-    <classname>NoExceptions</classname> feature and you&rsquo;re still
-    seeing optional exceptions thrown, you disabled exceptions on the
-    wrong object. The exception thrower could be unrelated to the object
-    you disabled exceptions on, it could be its parent, or it could be a
-    child created before you disabled optional exceptions.</para>
-
-    <para>Some of the exceptions MySQL++ can throw are not
-    optional:</para>
+    <classname>NoExceptions</classname> feature and you&rsquo;re
+    still seeing optional exceptions thrown, you disabled exceptions
+    on the wrong object. The exception thrower could be unrelated to
+    the object you disabled exceptions on, it could be its parent,
+    or it could be a child created before you disabled optional
+    exceptions.</para>
+
+    <para>MySQL++ throws some exceptions unconditionally:</para>
 
     <itemizedlist>
       <listitem><para>The largest set of non-optional exceptions are
@@ -322,6 +322,13 @@
       enough parameters when instantiating the template,
       <classname>Query</classname> will throw a <ulink type="classref"
       url="BadParamCount"/> exception.</para></listitem>
+
+      <listitem><para>If you use a C++ data type in a query
+      that MySQL++ doesn&rsquo;t know to convert to SQL, MySQL++
+      will throw a <ulink type="classref" url="TypeLookupFailed"/>
+      exception. It typically happens with <xref linkend="ssqls"/>,
+      especially when using data types other than the ones defined
+      in <filename>lib/sql_types.h</filename>.</para></listitem>
     </itemizedlist>
 
     <para>It&rsquo;s educational to modify the examples to force
@@ -365,7 +372,7 @@
     <programlisting>
 SELECT * FROM stock WHERE item = 'Frank's Brand Hotdog Buns' </programlisting>
 
-    <para>That's not valid SQL syntax. The correct syntax is:</para>
+    <para>That&rsquo;s not valid SQL syntax. The correct syntax is:</para>
 
     <programlisting>
 SELECT * FROM stock WHERE item = 'Frank''s Brand Hotdog Buns' </programlisting>

Modified: trunk/lib/exceptions.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/exceptions.h?rev=2165&r1=2164&r2=2165&view=diff
==============================================================================
--- trunk/lib/exceptions.h (original)
+++ trunk/lib/exceptions.h Thu Feb  7 05:14:01 2008
@@ -411,6 +411,28 @@
 };
 
 
+/// \brief Thrown from the C++ to SQL data type conversion routine when
+/// it can't figure out how to map the type.
+///
+/// This exception is not optional.  The only alternatives when this
+/// happens are equally drastic: basically, either iterate past the
+/// end of an array (crashing the program) or call assert() to crash
+/// the program nicely.  At least this way you have some control over
+/// how your program ends.  You can even ignore the error and keep on
+/// going: this typically happens when building a SQL query, so you can
+/// handle it just the same as if the subsequent query execution failed.
+
+class MYSQLPP_EXPORT TypeLookupFailed : public Exception
+{
+public:
+       /// \brief Create exception object
+       explicit TypeLookupFailed(const std::string& w) :
+       Exception(w)
+       {
+       }
+};
+
+
 } // end namespace mysqlpp
 
 #endif // !defined(MYSQLPP_EXCEPTIONS_H)

Modified: trunk/lib/type_info.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/type_info.h?rev=2165&r1=2164&r2=2165&view=diff
==============================================================================
--- trunk/lib/type_info.h (original)
+++ trunk/lib/type_info.h Thu Feb  7 05:14:01 2008
@@ -6,7 +6,7 @@
 
 /***********************************************************************
  Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
- (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
+ (c) 2004-2008 by Educational Technology Resources, Inc.  Others may
  also hold copyrights on code in this file.  See the CREDITS file in
  the top directory of the distribution for details.
 
@@ -28,15 +28,16 @@
  USA
 ***********************************************************************/
 
-#ifndef MYSQLPP_TYPE_INFO_H
+#if !defined(MYSQLPP_TYPE_INFO_H)
 #define MYSQLPP_TYPE_INFO_H
 
 #include "common.h"
 
+#include "exceptions.h"
+
 #include <map>
+#include <sstream>
 #include <typeinfo>
-
-#include <assert.h>
 
 namespace mysqlpp {
 
@@ -118,8 +119,14 @@
                        const std::type_info& ti) const
        {
                map_type::const_iterator it = map_.find(&ti);
-               assert(it != map_.end());
-               return it->second;
+               if (it != map_.end()) {
+                       return it->second;
+               }
+               else {
+                       std::ostringstream outs;
+                       outs << "Failed to find MySQL C API type ID for " << 
ti.name();
+                       throw TypeLookupFailed(outs.str());
+               }
        }
 
        map_type map_;
@@ -336,5 +343,5 @@
 
 }                                                              // end 
namespace mysqlpp
 
-#endif
-
+#endif // !defined(MYSQLPP_TYPE_INFO_H)
+


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to