diff options
| author | Jason Kirtland <jek@discorporate.us> | 2009-03-30 20:41:48 +0000 |
|---|---|---|
| committer | Jason Kirtland <jek@discorporate.us> | 2009-03-30 20:41:48 +0000 |
| commit | aca84bebb091a51ceeb911249c366e17b954826a (patch) | |
| tree | 87a0424805905c9fdae0ab6930144c91b9a78ff6 /test/sql/functions.py | |
| parent | 1ad157a0a1823706ffb43ee7d235c38ae16f46ff (diff) | |
| download | sqlalchemy-aca84bebb091a51ceeb911249c366e17b954826a.tar.gz | |
extract() is now dialect-sensitive and supports SQLite and others.
Diffstat (limited to 'test/sql/functions.py')
| -rw-r--r-- | test/sql/functions.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/sql/functions.py b/test/sql/functions.py index 151957503..17d8a35e9 100644 --- a/test/sql/functions.py +++ b/test/sql/functions.py @@ -271,6 +271,44 @@ class ExecuteTest(TestBase): assert x == y == z == w == q == r + def test_extract_bind(self): + """Basic common denominator execution tests for extract()""" + + date = datetime.date(2010, 5, 1) + + def execute(field): + return testing.db.execute(select([extract(field, date)])).scalar() + + assert execute('year') == 2010 + assert execute('month') == 5 + assert execute('day') == 1 + + date = datetime.datetime(2010, 5, 1, 12, 11, 10) + + assert execute('year') == 2010 + assert execute('month') == 5 + assert execute('day') == 1 + + def test_extract_expression(self): + meta = MetaData(testing.db) + table = Table('test', meta, + Column('dt', DateTime), + Column('d', Date)) + meta.create_all() + try: + table.insert().execute( + {'dt': datetime.datetime(2010, 5, 1, 12, 11, 10), + 'd': datetime.date(2010, 5, 1) }) + rs = select([extract('year', table.c.dt), + extract('month', table.c.d)]).execute() + row = rs.fetchone() + assert row[0] == 2010 + assert row[1] == 5 + rs.close() + finally: + meta.drop_all() + + def exec_sorted(statement, *args, **kw): """Executes a statement and returns a sorted list plain tuple rows.""" |
