From 84485fb7bbc31ecc20176c088af671b2c27311bc Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 14 Feb 2008 18:22:47 +0000 Subject: [PATCH] - fixed bug in result proxy where anonymously generated column labels would not be accessible using their straight string name --- CHANGES | 4 ++++ lib/sqlalchemy/sql/compiler.py | 2 +- test/sql/query.py | 20 +++++++++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index afc3fedd4e..210467b5ac 100644 --- a/CHANGES +++ b/CHANGES @@ -39,6 +39,10 @@ CHANGES - cast() accepts text('something') and other non-literal operands properly [ticket:962] + - fixed bug in result proxy where anonymously generated + column labels would not be accessible using their straight + string name + - Deferrable constraints can now be defined. - Added "autocommit=True" keyword argument to select() and diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index e87d3d2fb4..3f32778d6e 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -236,7 +236,7 @@ class DefaultCompiler(engine.Compiled): labelname = self._truncated_identifier("colident", label.name) if result_map is not None: - result_map[labelname.lower()] = (label.name, (label, label.obj), label.obj.type) + result_map[labelname.lower()] = (label.name, (label, label.obj, labelname), label.obj.type) return " ".join([self.process(label.obj), self.operator_string(operators.as_), self.preparer.format_label(label, labelname)]) diff --git a/test/sql/query.py b/test/sql/query.py index 533f40fb5f..2cc4ab0d02 100644 --- a/test/sql/query.py +++ b/test/sql/query.py @@ -129,15 +129,29 @@ class QueryTest(TestBase): table.drop() def test_row_iteration(self): - users.insert().execute(user_id = 7, user_name = 'jack') - users.insert().execute(user_id = 8, user_name = 'ed') - users.insert().execute(user_id = 9, user_name = 'fred') + users.insert().execute( + {'user_id':7, 'user_name':'jack'}, + {'user_id':8, 'user_name':'ed'}, + {'user_id':9, 'user_name':'fred'}, + ) r = users.select().execute() l = [] for row in r: l.append(row) self.assert_(len(l) == 3) + def test_anonymous_rows(self): + users.insert().execute( + {'user_id':7, 'user_name':'jack'}, + {'user_id':8, 'user_name':'ed'}, + {'user_id':9, 'user_name':'fred'}, + ) + + sel = select([users.c.user_id]).where(users.c.user_name=='jack').as_scalar() + for row in select([sel + 1, sel + 3], bind=users.bind).execute(): + assert row['anon_1'] == 8 + assert row['anon_2'] == 10 + def test_row_comparison(self): users.insert().execute(user_id = 7, user_name = 'jack') rp = users.select().execute().fetchone() -- 2.47.3