Hi there,

I am experiencing some annoying problems with type casting in mysql backend.
In my non trivial SQL query I am doing casts for generated columns to 
avoid problems with the type the server sends for each column.

     ,CAST(COALESCE((p2e.inserted IS NOT NULL),0) AS UNSIGNED) AS 'exists'
     ,CAST(COALESCE(p2e.active,0) AS UNSIGNED) AS 'active'
     ,CAST(UNIX_TIMESTAMP(COALESCE(p2e.last_full_update,0)) AS UNSIGNED) 
AS 'last_full_update'
     ,CAST(0 AS UNSIGNED) AS already_ordered

The problem is, that these "CAST" columns do not getting the same type 
from server! For example field "exists" and "active" are of type 
MYSQL_TYPE_LONG (unsigned flag set) and "already_ordered" and 
"last_full_update" are of type MYSQL_TYPE_LONGLONG (unsigned flag set). 
So I cant rely on the resulting type of the "CAST" call.

Here are the lines with the problem from statement.cpp in mysql backend:

     case FIELD_TYPE_LONG:       //MYSQL_TYPE_LONG:
         type = field->flags & UNSIGNED_FLAG ? dt_long_long
                                             : dt_integer;
         break;
     case FIELD_TYPE_LONGLONG:   //MYSQL_TYPE_LONGLONG:
         type = field->flags & UNSIGNED_FLAG ? dt_unsigned_long_long :
                                               dt_long_long;
         break;


The problem shows up if i try to use such a field in my orm mapping. At 
the beginning I used:

p.exists = v.get<long long>("exists", 0);

Which is at least logically wrong. Because i casted the column to 
"UNSIGNED" and the mapping from the MySQL backend returned an signed 
type? But, not matter, this code was working right... until the type 
changed to MYSQL_TYPE_LONGLONG. The maped type was than "unsigned long 
long" and I got the "bad_cast" error.

 From the technical and the logical view and if "UNSIGNED_FLAG" is set 
the resulting type should be an unsigned type! In this case the result 
should be "dt_unsigned_long_long".

Is this change valid or are I am missing something there?


User versions:
Linus version is 3.9-1-686-pae #1 SMP Debian 3.9.8-1 i686 GNU/Linux
MySQL server version is "5.5.28"
MySQL client version is "14.14 Distrib 5.5.31, for debian-linux-gnu 
(i686) using readline 6.2" (32bit)
SOCI is latest from git

Mit freundlichen Grüßen / Best Regards,
Daniel Walter


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to