Selectively bypass the converter?

  • Jack Repenning

    Jack Repenning - 2010-07-30

    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).

  • Andy Dustman

    Andy Dustman - 2010-07-30

    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)

  • Jack Repenning

    Jack Repenning - 2010-07-30

    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.

  • Andy Dustman

    Andy Dustman - 2010-08-01

    Actually, you could. Whatever decoder you write can basically do anything,
    include checking global variables, ..


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks