On Sunday 05 April 2009 15:08:37 Oleg Broytmann wrote:
> On Sun, Apr 05, 2009 at 01:02:35PM +0200, Markus W. Barth wrote:
> > The value for DateCol is set as a formatted date string
>
>    Why? You can set datetime:
>
> class Test(SQLObject):
>     date = DateCol()
>
> Test.createTable()
>
> t = Test(date=date(2001, 12, 21))
> print type(t.date), t.date
>
> t.date = date(2002, 1, 1)
> print type(t.date), t.date
>
>    Output:
>
>  1/Query   :  CREATE TABLE test (
>     id INTEGER PRIMARY KEY,
>     date DATE
> )
>  1/QueryR  :  CREATE TABLE test (
>     id INTEGER PRIMARY KEY,
>     date DATE
> )
>  2/QueryIns:  INSERT INTO test (date) VALUES ('2001-12-21')
>  2/QueryR  :  INSERT INTO test (date) VALUES ('2001-12-21')
>  3/QueryOne:  SELECT date FROM test WHERE ((test.id) = (1))
>  3/QueryR  :  SELECT date FROM test WHERE ((test.id) = (1))
> <type 'datetime.date'> 2001-12-21
>  4/Query   :  UPDATE test SET date = ('2002-01-01') WHERE id = (1)
>  4/QueryR  :  UPDATE test SET date = ('2002-01-01') WHERE id = (1)
> <type 'datetime.date'> 2002-01-01
>
> > In the docs it also says that
> > it's _usually_ returned as these data types. Does this depend on the used
> > db and is it predictable
>
>    The docs is a bit outdated. That part of the docs was written before
> DateCol got stable validator/converter. Now with the converter the returned
> value must always be datetime/mxDateTime.
>
> Oleg.

Sorry, Oleg, you are right, it accepts both string and datetime. I got a bit 
misleaded by the formencode exception
<snippet>
formencode.api.Invalid: expected a date/time string of the '%Y-%m-%d' format 
in the DateTimeCol 'date', got <type 'str'> '' instead
</snippet>

------------------------------------------------------------------------------
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to