diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-06-15 18:06:50 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-06-15 20:38:39 -0400 |
commit | 009acc95b8804b5b62fbd43c6fdd61d6fd407ef7 (patch) | |
tree | b6e8d799be87d73b3f981c7a876b8c22a18809d4 /test/dialect/oracle/test_compiler.py | |
parent | de08740d7c21fa9dcef453bfd07a3defa428e88f (diff) | |
download | sqlalchemy-009acc95b8804b5b62fbd43c6fdd61d6fd407ef7.tar.gz |
Turn off the is_literal flag when proxying literal_column() to Label
Fixed a series of quoting issues which all stemmed from the concept of the
:func:`.literal_column` construct, which when being "proxied" through a
subquery to be referred towards by a label that matches its text, the label
would not have quoting rules applied to it, even if the string in the
:class:`.Label` were set up as a :class:`.quoted_name` construct. Not
applying quoting to the text of the :class:`.Label` is a bug because this
text is strictly a SQL identifier name and not a SQL expression, and the
string should not have quotes embedded into it already unlike the
:func:`.literal_column` which it may be applied towards. The existing
behavior of a non-labeled :func:`.literal_column` being propagated as is on
the outside of a subquery is maintained in order to help with manual
quoting schemes, although it's not clear if valid SQL can be generated for
such a construct in any case.
Fixes: #4730
Change-Id: I300941f27872fc4298c74a1d1ed65aef1a5cdd82
Diffstat (limited to 'test/dialect/oracle/test_compiler.py')
-rw-r--r-- | test/dialect/oracle/test_compiler.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/dialect/oracle/test_compiler.py b/test/dialect/oracle/test_compiler.py index 931079240..f11daebb4 100644 --- a/test/dialect/oracle/test_compiler.py +++ b/test/dialect/oracle/test_compiler.py @@ -9,6 +9,7 @@ from sqlalchemy import ForeignKey from sqlalchemy import func from sqlalchemy import Index from sqlalchemy import Integer +from sqlalchemy import literal_column from sqlalchemy import MetaData from sqlalchemy import or_ from sqlalchemy import outerjoin @@ -25,6 +26,7 @@ from sqlalchemy.dialects.oracle import base as oracle from sqlalchemy.dialects.oracle import cx_oracle from sqlalchemy.engine import default from sqlalchemy.sql import column +from sqlalchemy.sql import quoted_name from sqlalchemy.sql import table from sqlalchemy.testing import assert_raises_message from sqlalchemy.testing import AssertsCompiledSQL @@ -260,6 +262,62 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): "UPDATE", ) + def test_limit_special_quoting(self): + """Oracle-specific test for #4730. + + Even though this issue is generic, test the originally reported Oracle + use case. + + """ + + col = literal_column("SUM(ABC)").label("SUM(ABC)") + tbl = table("my_table") + query = select([col]).select_from(tbl).order_by(col).limit(100) + + self.assert_compile( + query, + 'SELECT anon_1."SUM(ABC)" FROM ' + '(SELECT SUM(ABC) AS "SUM(ABC)" ' + "FROM my_table ORDER BY SUM(ABC)) anon_1 " + "WHERE ROWNUM <= :param_1", + ) + + col = literal_column("SUM(ABC)").label(quoted_name("SUM(ABC)", True)) + tbl = table("my_table") + query = select([col]).select_from(tbl).order_by(col).limit(100) + + self.assert_compile( + query, + 'SELECT anon_1."SUM(ABC)" FROM ' + '(SELECT SUM(ABC) AS "SUM(ABC)" ' + "FROM my_table ORDER BY SUM(ABC)) anon_1 " + "WHERE ROWNUM <= :param_1", + ) + + col = literal_column("SUM(ABC)").label("SUM(ABC)_") + tbl = table("my_table") + query = select([col]).select_from(tbl).order_by(col).limit(100) + + self.assert_compile( + query, + 'SELECT anon_1."SUM(ABC)_" FROM ' + '(SELECT SUM(ABC) AS "SUM(ABC)_" ' + "FROM my_table ORDER BY SUM(ABC)) anon_1 " + "WHERE ROWNUM <= :param_1", + ) + + col = literal_column("SUM(ABC)").label(quoted_name("SUM(ABC)_", True)) + tbl = table("my_table") + query = select([col]).select_from(tbl).order_by(col).limit(100) + + self.assert_compile( + query, + 'SELECT anon_1."SUM(ABC)_" FROM ' + '(SELECT SUM(ABC) AS "SUM(ABC)_" ' + "FROM my_table ORDER BY SUM(ABC)) anon_1 " + "WHERE ROWNUM <= :param_1", + ) + def test_for_update(self): table1 = table( "mytable", column("myid"), column("name"), column("description") |