in reply to Class::DBI and MySQL ENCODE/DECODE

Overriding the SQL fragments is pretty easy. If you look in at the top of the Class::DBI code, you'll see them.

Replies are listed 'Best First'.
Re^2: Class::DBI and MySQL ENCODE/DECODE
by Anonymous Monk on Dec 23, 2005 at 01:36 UTC

    Well yes, but ...

    SELECT %s
    FROM __TABLE__
    WHERE __IDENTIFIER__

    or

    UPDATE __TABLE__
    SET %s
    WHERE __IDENTIFIER__

    One would need to define custom SQL for the fields that need to be encoded or decoded, or else encode or decode everything.

    So it seems that the string being passed in must contain the ENCODE/DECODE only for the fields that need it, or else modify the query after it has been built.

    What I am trying to identify is where to put it to avoid duplication of code and/or special casing.

      Didn't you just say you want encode/decode everything for this table? If you override these in one class/table, it will not affect any others.

        I didn't mean to say that the entire table is encoded, although it looks like what I did say could be read that way. I thought I had said only some columns were encoded. So a straight query might be something like:

        SELECT a, b, DECODE(c, 'foo') AS c
        FROM mytable

        The problem being that not all columns are encoded - otherwise rewriting the fragments would be perfect.

        Sorry about any confusion caused.