All pastes #593443 Raw Edit

Mine

public text v1 · immutable
#593443 ·published 2007-06-28 10:20 UTC
rendered paste body
class PsycoPG2(PsycoPG):
    """PostgreSQL driver class using psycopg2."""

    _db_mod = 'psycopg2'
    from mx import DateTime

    def __init__(self, *args, **kws):
        super(PsycoPG2, self).__init__(*args, **kws)
        from psycopg2 import extensions
        USE_DATE_TIME = extensions.new_type(
            self._db_mod.DATETIME.values + self._db_mod._psycopg.DATE.values,
            "USE_DATE_TIME", PsycoPG2.cast_date_time)
        extensions.register_type(USE_DATE_TIME)

    def cast_date_time(value, curs):
        if value is not None:
            if isinstance(value, str):
                t = value.split()
                if len(t) > 1:
                    t = t[0].split("-") + t[1].split(":")
                else:
                    t = t[0].split("-")
                return PsycoPG2.DateTime.DateTime(*tuple([float(s) for s in t]))
            else:
                raise ValueError, "alt er visst ikke string...", repr(value)
            return PsycoPG2.DateTime(*value.timetuple()[:-3])

    cast_date_time = staticmethod(cast_date_time)