summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-08-22 18:41:46 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-08-22 18:41:46 -0400
commit8f5a31441aed9d223e67d211472445e574fc521f (patch)
tree5f95780d99cf6c77ffd569d34d709514fa98263c /test
parent477dd0f774f1c2f2f3873924ac0606bf499e0061 (diff)
downloadsqlalchemy-8f5a31441aed9d223e67d211472445e574fc521f.tar.gz
- [bug] Fixed cextension bug whereby the
"ambiguous column error" would fail to function properly if the given index were a Column object and not a string. Note there are still some column-targeting issues here which are fixed in 0.8. [ticket:2553] - find more cases where column targeting is being inaccurate, add more information to result_map to better differentiate "ambiguous" results from "present" or "not present". In particular, result_map is sensitive to dupes, even though no error is raised; the conflicting columns are added to the "obj" member of the tuple so that the two are both directly accessible in the result proxy - handwringing over the damn "name fallback" thing in results. can't really make it perfect yet - fix up oracle returning clause. not sure why its guarding against labels, remove that for now and see what the bot says.
Diffstat (limited to 'test')
-rw-r--r--test/dialect/test_oracle.py8
-rw-r--r--test/sql/test_query.py66
2 files changed, 72 insertions, 2 deletions
diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py
index 2a5ab0627..b70358ffd 100644
--- a/test/dialect/test_oracle.py
+++ b/test/dialect/test_oracle.py
@@ -445,6 +445,14 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
'addresses.user_id = :user_id_1 ORDER BY '
'addresses.id, address_types.id')
+ def test_returning_insert(self):
+ t1 = table('t1', column('c1'), column('c2'), column('c3'))
+ self.assert_compile(
+ t1.insert().values(c1=1).returning(t1.c.c2, t1.c.c3),
+ "INSERT INTO t1 (c1) VALUES (:c1) RETURNING "
+ "t1.c2, t1.c3 INTO :ret_0, :ret_1"
+ )
+
def test_compound(self):
t1 = table('t1', column('c1'), column('c2'), column('c3'))
t2 = table('t2', column('c1'), column('c2'), column('c3'))
diff --git a/test/sql/test_query.py b/test/sql/test_query.py
index f54162bda..16a2f254d 100644
--- a/test/sql/test_query.py
+++ b/test/sql/test_query.py
@@ -954,13 +954,36 @@ class QueryTest(fixtures.TestBase):
def test_ambiguous_column(self):
users.insert().execute(user_id=1, user_name='john')
- r = users.outerjoin(addresses).select().execute().first()
+ result = users.outerjoin(addresses).select().execute()
+ r = result.first()
+
assert_raises_message(
exc.InvalidRequestError,
"Ambiguous column name",
lambda: r['user_id']
)
+ assert_raises_message(
+ exc.InvalidRequestError,
+ "Ambiguous column name",
+ lambda: r[users.c.user_id]
+ )
+
+ assert_raises_message(
+ exc.InvalidRequestError,
+ "Ambiguous column name",
+ lambda: r[addresses.c.user_id]
+ )
+
+ # try to trick it - fake_table isn't in the result!
+ # we get the correct error
+ fake_table = Table('fake', MetaData(), Column('user_id', Integer))
+ assert_raises_message(
+ exc.InvalidRequestError,
+ "Could not locate column in row for column 'fake.user_id'",
+ lambda: r[fake_table.c.user_id]
+ )
+
r = util.pickle.loads(util.pickle.dumps(r))
assert_raises_message(
exc.InvalidRequestError,
@@ -978,6 +1001,41 @@ class QueryTest(fixtures.TestBase):
lambda: r['user_id']
)
+ def test_ambiguous_column_by_col(self):
+ users.insert().execute(user_id=1, user_name='john')
+ ua = users.alias()
+ u2 = users.alias()
+ result = select([users.c.user_id, ua.c.user_id]).execute()
+ row = result.first()
+
+ assert_raises_message(
+ exc.InvalidRequestError,
+ "Ambiguous column name",
+ lambda: row[users.c.user_id]
+ )
+
+ assert_raises_message(
+ exc.InvalidRequestError,
+ "Ambiguous column name",
+ lambda: row[ua.c.user_id]
+ )
+
+ # Unfortunately, this fails -
+ # we'd like
+ # "Could not locate column in row"
+ # to be raised here, but the check for
+ # "common column" in _compare_name_for_result()
+ # has other requirements to be more liberal.
+ # Ultimately the
+ # expression system would need a way to determine
+ # if given two columns in a "proxy" relationship, if they
+ # refer to a different parent table
+ assert_raises_message(
+ exc.InvalidRequestError,
+ "Ambiguous column name",
+ lambda: row[u2.c.user_id]
+ )
+
@testing.requires.subqueries
def test_column_label_targeting(self):
users.insert().execute(user_id=7, user_name='ed')
@@ -1365,10 +1423,14 @@ class KeyTargetingTest(fixtures.TablesTest):
keyed3 = self.tables.keyed3
row = testing.db.execute(select([keyed1, keyed3])).first()
- assert 'b' not in row
eq_(row.q, "c1")
assert_raises_message(
exc.InvalidRequestError,
+ "Ambiguous column name 'b'",
+ getattr, row, "b"
+ )
+ assert_raises_message(
+ exc.InvalidRequestError,
"Ambiguous column name 'a'",
getattr, row, "a"
)