While for the most part, the MySQLdb automatic converter (to return
appropriate data types instead of strings) is sweet, in one teeny place I
really want the actual string, instead of what happens to be a
datetime.datetime. Can I do that without opening a separate connection?
(This is actually in a unit test case, where I want to protect some other code
that actually uses the DB, doesn't use anything as sweet as MySQLdb, and in
fact is rather stupid but unfixable legacy nonsense).
The trunk version (in Hg, not SVN) has the capability of doing this. You can
register your own decoder that can be specific to a particular column. Trunk
passes unit tests, but there are been no releases yet. There are probably some
other small API changes. It would be good to get some feedback from someone
who already has an application.
Maybe the other (sensible) thing to do is use the MySQL CAST function to
return that column as CHAR, i.e. CAST(expr AS CHAR)
Ah, "CAST", sure. That works. Thanks! (head-slap)
Unfortunately, even the new column-specific decoder doesn't quite work, as I
want it as string sometimes, datetime others (within the same test suite /
connection). So I won't be testing that new code.
Actually, you could. Whatever decoder you write can basically do anything,
include checking global variables, ..
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.