On Sep 24, 2008, at 10:13 PM, Shawn Church wrote:
> I am trying to construct a select query in mysql (version
> 5.0.51a-3ubuntu5.3-log) using SQL functions. Once I set the
> convert_unicode flag = True on my engine some function results are
> returned as type str and some results are returned as type unicode
> (I want, and expected, all unicode). Although this problem can be
> resolved with an explict cast I suspect there might be a deeper
> problem.
>
> It seems that when an obvious string function is used (i.e. CONCAT
> in my case) then unicode is correctly returned. However when the
> return type is dependent on the results of the query (i.e. IFNULL,
> could return any type dependent on the arguments) then a str is
> returned.
>
> Am I just missing something or is this a problem with mysql or is
> there some other problem? Sample code and output is included below.
the func.XXX() construct can draw upon a module of "known functions"
such as CONCAT, in which case the return type of the function is known
(sqlalchemy terms these "generic functions"). However, if the
function name given is not a "known" function, then the return type is
not known to be a string (which is necessary for convert_unicode to
take effect). To coerce an arbitrary func to apply String
processing to the result, use the type_ parameter:
func.foo(arg1, arg2, ..., type_=Unicode)
we can of course add more functions to the list of "known" functions
such as ifnull() (it would be best if ifnull() is a SQL standard
function, I'm not sure if it is).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---