From a579e8f687833257757d53e772698f652e90472a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 13 Mar 2006 01:13:47 +0000 Subject: [PATCH] small tweak to select in order to fix [ticket:112]...the exported columns when doing select on a select() will be the column names, not the keys. this is with selects that have use_labels=False. which makes sense since using the "key" and not the name implies a label has to be used. --- lib/sqlalchemy/sql.py | 2 +- test/query.py | 3 ++- test/select.py | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 4eaf33e00a..a6fe3e8800 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -1272,7 +1272,7 @@ class Select(SelectBaseMixin, FromClause): if self.use_labels: return column._make_proxy(self, name=column._label) else: - return column._make_proxy(self, name=column.key) + return column._make_proxy(self, name=column.name) def append_whereclause(self, whereclause): self._append_condition('whereclause', whereclause) diff --git a/test/query.py b/test/query.py index a6e1bb4191..bbed574412 100644 --- a/test/query.py +++ b/test/query.py @@ -124,7 +124,8 @@ class QueryTest(PersistTest): self.assert_(r==[(3, 'ed'), (4, 'wendy'), (5, 'laura')]) r = self.users.select(offset=5, order_by=[self.users.c.user_id]).execute().fetchall() self.assert_(r==[(6, 'ralph'), (7, 'fido')]) - + + def test_column_accessor(self): self.users.insert().execute(user_id=1, user_name='john') self.users.insert().execute(user_id=2, user_name='jack') diff --git a/test/select.py b/test/select.py index 768827347e..e9f02545c7 100644 --- a/test/select.py +++ b/test/select.py @@ -174,6 +174,12 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A select([table2.c.othername, func.count(table2.c.otherid)], group_by = [table2.c.othername]), "SELECT myothertable.othername, count(myothertable.otherid) FROM myothertable GROUP BY myothertable.othername" ) + + def testoraclelimit(self): + e = create_engine('oracle') + users = Table('users', e, Column('name', String(10), key='username')) + self.runtest(select([users.c.username], limit=5), "SELECT name FROM (SELECT users.name AS name, ROW_NUMBER() OVER (ORDER BY users.rowid ASC) AS ora_rn FROM users) WHERE ora_rn<=5", engine=e) + def testgroupby_and_orderby(self): self.runtest( select([table2.c.othername, func.count(table2.c.otherid)], group_by = [table2.c.othername], order_by = [table2.c.othername]), -- 2.47.2