>
> from sqlobject import *
> from sqlobject.sqlbuilder import *
>
> __connection__ = "sqlite:/:memory:?debug=1"
>
> from datetime import datetime
>
> class Test(SQLObject):
> ts = DateTimeCol()
>
> Test.createTable()
>
> Test(ts=datetime.strptime('2008-08-01 21:44:33', '%Y-%m-%d %H:%M:%S'))
>
> print list(Test.select(func.date(Test.q.ts) == '2008-08-01'))
>
> 2/QueryIns: INSERT INTO test (ts) VALUES ('2008-08-01 21:44:33')
> 2/QueryR : INSERT INTO test (ts) VALUES ('2008-08-01 21:44:33')
> 3/QueryOne: SELECT ts FROM test WHERE ((test.id) = (1))
> 3/QueryR : SELECT ts FROM test WHERE ((test.id) = (1))
> 4/Select : SELECT test.id, test.ts FROM test WHERE ((date(test.ts)) =
> ('2008-08-01'))
> 4/QueryR : SELECT test.id, test.ts FROM test WHERE ((date(test.ts)) =
> ('2008-08-01'))
> [<Test 1 ts='datetime.datetime...)'>]
>
> 'func' is SQLBuilder's magic that passes its attribute to SQL unchanged.
> Note 'date(test.ts)'! You should check that your backend actually
> implements the function (for 'date' most do).
I am on Firebird right now. AFIK Firebird does not support 'date'.
The syntax which works is:
cast(test.ts as date) = '2008-08-01'
But Python does not accept following construction:
print list(Test.select(func.cast(Test.q.ts as date) == '2008-08-01'))
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss