Daniel Walter
2013-07-22 11:38:23 UTC
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.
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.