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 | |
| parent | 1ad157a0a1823706ffb43ee7d235c38ae16f46ff (diff) | |
| download | sqlalchemy-aca84bebb091a51ceeb911249c366e17b954826a.tar.gz | |
extract() is now dialect-sensitive and supports SQLite and others.
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/functions.py | 38 | ||||
| -rw-r--r-- | test/sql/select.py | 6 |
2 files changed, 38 insertions, 6 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.""" diff --git a/test/sql/select.py b/test/sql/select.py index 15c47a674..52c382f81 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -831,12 +831,6 @@ FROM mytable, myothertable WHERE foo.id = foofoo(lala) AND datetime(foo) = Today "SELECT values.id FROM values WHERE values.val1 / (values.val2 - values.val1) / values.val1 > :param_1" ) - def test_extract(self): - """test the EXTRACT function""" - self.assert_compile(select([extract("month", table3.c.otherstuff)]), "SELECT extract(month FROM thirdtable.otherstuff) AS extract_1 FROM thirdtable") - - self.assert_compile(select([extract("day", func.to_date("03/20/2005", "MM/DD/YYYY"))]), "SELECT extract(day FROM to_date(:to_date_1, :to_date_2)) AS extract_1") - def test_collate(self): for expr in (select([table1.c.name.collate('latin1_german2_ci')]), select([collate(table1.c.name, 'latin1_german2_ci')])): |
