diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-08-31 20:04:04 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-08-31 20:04:04 -0400 |
| commit | 51f1fdf3e40065e349310a6ba9a49306b9648160 (patch) | |
| tree | f8950316421ba71113393f6184eedd550e28f218 /test/sql/test_query.py | |
| parent | 19d04346260e794c7364d7f7ce2415602e6f101c (diff) | |
| download | sqlalchemy-51f1fdf3e40065e349310a6ba9a49306b9648160.tar.gz | |
- [bug] Fixed a regression since 0.6 regarding
result-row targeting. It should be possible
to use a select() statement with string
based columns in it, that is
select(['id', 'name']).select_from('mytable'),
and have this statement be targetable by
Column objects with those names; this is the
mechanism by which
query(MyClass).from_statement(some_statement)
works. At some point the specific case of
using select(['id']), which is equivalent to
select([literal_column('id')]), stopped working
here, so this has been re-instated and of
course tested. [ticket:2558]
Diffstat (limited to 'test/sql/test_query.py')
| -rw-r--r-- | test/sql/test_query.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/test/sql/test_query.py b/test/sql/test_query.py index 670fb2c64..67c0fec22 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -325,12 +325,16 @@ class QueryTest(fixtures.TestBase): row = testing.db.execute(select([content.c.type.label("content_type")])).first() assert content.c.type in row + assert bar.c.content_type not in row + assert sql.column('content_type') in row row = testing.db.execute(select([func.now().label("content_type")])).first() assert content.c.type not in row + assert bar.c.content_type not in row + assert sql.column('content_type') in row def test_pickled_rows(self): @@ -731,7 +735,23 @@ class QueryTest(fixtures.TestBase): dict(user_id=1, user_name='john'), dict(user_id=2, user_name='jack') ) - r = text("select * from query_users where user_id=2", bind=testing.db).execute().first() + r = testing.db.execute( + text("select * from query_users where user_id=2") + ).first() + self.assert_(r.user_id == r['user_id'] == r[users.c.user_id] == 2) + self.assert_(r.user_name == r['user_name'] == r[users.c.user_name] == 'jack') + + def test_column_accessor_textual_select(self): + users.insert().execute( + dict(user_id=1, user_name='john'), + dict(user_id=2, user_name='jack') + ) + # this will create column() objects inside + # the select(), these need to match on name anyway + r = testing.db.execute( + select(['user_id', 'user_name']).select_from('query_users'). + where('user_id=2') + ).first() self.assert_(r.user_id == r['user_id'] == r[users.c.user_id] == 2) self.assert_(r.user_name == r['user_name'] == r[users.c.user_name] == 'jack') @@ -742,9 +762,11 @@ class QueryTest(fixtures.TestBase): # test a little sqlite weirdness - with the UNION, # cols come back as "query_users.user_id" in cursor.description - r = text("select query_users.user_id, query_users.user_name from query_users " - "UNION select query_users.user_id, query_users.user_name from query_users", - bind=testing.db).execute().first() + r = testing.db.execute( + text("select query_users.user_id, query_users.user_name from query_users " + "UNION select query_users.user_id, query_users.user_name from query_users" + ) + ).first() eq_(r['user_id'], 1) eq_(r['user_name'], "john") eq_(r.keys(), ["user_id", "user_name"]) |
