diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-21 16:32:38 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-21 16:32:38 -0400 |
| commit | d5609d77841ab4e607e6b372a15396b38ddace9a (patch) | |
| tree | eb6faaeed9e58ed6d87b675eb0c27f363fc4de56 /test | |
| parent | 2272f30af435c5283157724bbb16fb0a573159ce (diff) | |
| download | sqlalchemy-d5609d77841ab4e607e6b372a15396b38ddace9a.tar.gz | |
- [feature] Added "MATCH" clause to ForeignKey,
ForeignKeyConstraint, courtesy Ryan Kelly.
[ticket:2502]
- [feature] Added support for DELETE and UPDATE from
an alias of a table, which would assumedly
be related to itself elsewhere in the query,
courtesy Ryan Kelly. [ticket:2507]
- [feature] Added support for the Postgresql ONLY
keyword, which can appear corresponding to a
table in a SELECT, UPDATE, or DELETE statement.
The phrase is established using with_hint().
Courtesy Ryan Kelly [ticket:2506]
Diffstat (limited to 'test')
| -rw-r--r-- | test/dialect/test_postgresql.py | 50 | ||||
| -rw-r--r-- | test/sql/test_compiler.py | 18 |
2 files changed, 68 insertions, 0 deletions
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 5729bf354..b50b0dcbb 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -272,6 +272,56 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile(x, '''SELECT pg_table.col1, pg_table."variadic" FROM pg_table''') + def test_from_only(self): + m = MetaData() + tbl1 = Table('testtbl1', m, Column('id', Integer)) + tbl2 = Table('testtbl2', m, Column('id', Integer)) + + stmt = tbl1.select().with_hint(tbl1, 'ONLY', 'postgresql') + expected = 'SELECT testtbl1.id FROM ONLY testtbl1' + self.assert_compile(stmt, expected) + + talias1 = tbl1.alias('foo') + stmt = talias1.select().with_hint(talias1, 'ONLY', 'postgresql') + expected = 'SELECT foo.id FROM ONLY testtbl1 AS foo' + self.assert_compile(stmt, expected) + + stmt = select([tbl1, tbl2]).with_hint(tbl1, 'ONLY', 'postgresql') + expected = ('SELECT testtbl1.id, testtbl2.id FROM ONLY testtbl1, ' + 'testtbl2') + self.assert_compile(stmt, expected) + + stmt = select([tbl1, tbl2]).with_hint(tbl2, 'ONLY', 'postgresql') + expected = ('SELECT testtbl1.id, testtbl2.id FROM testtbl1, ONLY ' + 'testtbl2') + self.assert_compile(stmt, expected) + + stmt = select([tbl1, tbl2]) + stmt = stmt.with_hint(tbl1, 'ONLY', 'postgresql') + stmt = stmt.with_hint(tbl2, 'ONLY', 'postgresql') + expected = ('SELECT testtbl1.id, testtbl2.id FROM ONLY testtbl1, ' + 'ONLY testtbl2') + self.assert_compile(stmt, expected) + + stmt = update(tbl1, values=dict(id=1)) + stmt = stmt.with_hint('ONLY', dialect_name='postgresql') + expected = 'UPDATE ONLY testtbl1 SET id=%(id)s' + self.assert_compile(stmt, expected) + + stmt = delete(tbl1).with_hint('ONLY', selectable=tbl1, dialect_name='postgresql') + expected = 'DELETE FROM ONLY testtbl1' + self.assert_compile(stmt, expected) + + tbl3 = Table('testtbl3', m, Column('id', Integer), schema='testschema') + stmt = tbl3.select().with_hint(tbl3, 'ONLY', 'postgresql') + expected = 'SELECT testschema.testtbl3.id FROM ONLY testschema.testtbl3' + self.assert_compile(stmt, expected) + + assert_raises( + exc.CompileError, + tbl3.select().with_hint(tbl3, "FAKE", "postgresql").compile, + dialect=postgresql.dialect() + ) class FloatCoercionTest(fixtures.TablesTest, AssertsExecutionResults): __only_on__ = 'postgresql' diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 61dcf61ab..4bf0eb70e 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -2906,6 +2906,18 @@ class CRUDTest(fixtures.TestBase, AssertsCompiledSQL): "WHERE mytable.myid = hoho(:hoho_1) AND mytable.name = :param_2 || " "mytable.name || :param_3") + def test_aliased_update(self): + talias1 = table1.alias('t1') + self.assert_compile( + update(talias1, talias1.c.myid == 7), + "UPDATE mytable AS t1 SET name=:name WHERE t1.myid = :myid_1", + params = {table1.c.name:'fred'}) + self.assert_compile( + update(talias1, table1.c.myid == 7), + "UPDATE mytable AS t1 SET name=:name FROM " + "mytable WHERE mytable.myid = :myid_1", + params = {table1.c.name:'fred'}) + def test_correlated_update(self): # test against a straight text subquery u = update(table1, values = { @@ -2988,6 +3000,12 @@ class CRUDTest(fixtures.TestBase, AssertsCompiledSQL): "DELETE FROM mytable WHERE mytable.myid = :myid_1 " "AND mytable.name = :name_1") + def test_aliased_delete(self): + talias1 = table1.alias('t1') + self.assert_compile( + delete(talias1).where(talias1.c.myid == 7), + "DELETE FROM mytable AS t1 WHERE t1.myid = :myid_1") + def test_correlated_delete(self): # test a non-correlated WHERE clause s = select([table2.c.othername], table2.c.otherid == 7) |
