List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:August 11 2010 3:17am
Subject:Re: mysql_type_info::is_num_type() and sql_type() are gone in 3.1.0,
what's the alternative?
View as plain text  
On 8/10/2010 12:20 PM, Wilfred van Velzen wrote:
>
> Maybe they are usefull for addition to the library?

These functions bother me, for a couple of reasons:

First, these routines expose MySQL internals through the MySQL++ 
abstraction layer.  I'm not suggesting that MySQL++ will become 
database-independent anytime soon, but that it seems like a bad idea to 
be using an abstracting library like MySQL++ but then add features that 
expose details about the underlying library.

Second, it seems like bad design to begin with to be doing run-time type 
checks in a statically-compiled language like C++.

MySQL++ itself does such things for reasons discussed in the user manual 
(link below) but only because part of its purpose is to marry the MySQL 
and C++ type systems.  The two are somewhat incompatible and values 
don't get bound to variables until run-time, so some decisions have to 
wait until then, effectively making MySQL++ a dynamic typing layer.  For 
the most part, your code should be able to ignore this, however, leaving 
these details up to MySQL++.

Discussion:

  http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#sql-types

> is a better way of coding with the functions available in the library

Probably.  Let's say you have a field that you expect to be an integer 
type, but you aren't sure.

One way would be to use SSQLS, which gets you static type checks:

     sql_create_1(my_ssqls, 1, 0,
         mysqlpp::sql_int foo)
     my_ssqls row = res[4];
     row.foo += 5;	// prev line succeeded, so this must be legal

That is, if res[4] can be converted to type my_ssqls, you can be sure 
that the "foo" field in the query result set is of a type that can be 
converted to mysqlpp::sql_int, so we can safely do integer-like things 
with it, like add 5 to it.

If you absolutely have to defer type checks until run-time, let MySQL++ 
do the checks for you:

     try {
         int foo = row[4];
         // Do something with foo here now that we're sure it's
         // an integer type, or something convertible to int
     }
     catch (const mysqlpp::TypeLookupFailed& e) {
         // row[4] is clearly not an integer type
     }
Thread
mysql_type_info::is_num_type() and sql_type() are gone in3.1.0, what's the alternative?Wilfred van Velzen10 Aug
  • Re: mysql_type_info::is_num_type() and sql_type() are gone in 3.1.0, what's the alternative?Wilfred van Velzen10 Aug
    • Re: mysql_type_info::is_num_type() and sql_type() are gone in 3.1.0,what's the alternative?Warren Young11 Aug