Hi Oleg,

I was misundestanding my problem, I was thinking that I couldn't
create an object, I take a look a while and undestand now that the
insert is ok, the select is with problem...

>    Aha, I see. In MySQL, TIME is both time of day and time difference.
> Adding timedelta requires some work...

I don't think so, if we start at the following:

1) TimeCol should limit the date to 24 hours, if mysql users want more
than that, they should use IntervalCol (there is not IntervalCol yet
:-P). Postgresql don't support more than 24 hours to time datatype,
there is the interval datatype to compensate it;

2) The input type of the TimeCol should be datetime.time (this is already done);

3) The output type of the TimeCol should be datetime.time too (here is
the problem). When using mysql, we can convert the datetime.timedelta
to datetime.time as above:

>>> import datetime
>>> import time
>>> td = datetime.timedelta(hours=9) # it could be the timedelta
returned by the query
>>> datetime.time(*time.gmtime(td.seconds)[3:6])
datetime.time(9, 0, 0)
>>>

Once we are presuming that the TimeCol is in range 0-24 hours, we
won't have problems with the convertion of timedelta to datetime.time.
I change the TimeValidator to conform my idea:

    class TimeValidator(DateTimeValidator):
        def to_python(self, value, state):
            if isinstance(value, datetime.time):
                return value
            if isinstance(value, datetime.timedelta):
                import time
                return datetime.time(*time.gmtime(value.seconds)[3:6])
            value = super(TimeValidator, self).to_python(value, state)
            if isinstance(value, datetime.datetime):
                value = value.time()
            return value

I tested with mysql and it solved my problem, the select is now
returning a datetime.time object. I tested with postgresql and it
worked too. I sent a patch on attachment, if you can take a look.

Thanks for all help,
Regards,
-- 
Michel Thadeu Sabchuk
Curitiba - Brasil

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to