mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-16 21:57:22 -04:00
91f376692d
Several weeks of using the future_select() construct has led to the proposal there be just one select() construct again which features the new join() method, and otherwise accepts both the 1.x and 2.x argument styles. This would make migration simpler and reduce confusion. However, confusion may be increased by the fact that select().join() is different Current thinking is we may be better off with a few hard behavioral changes to old and relatively unknown APIs rather than trying to play both sides within two extremely similar but subtly different APIs. At the moment, the .join() thing seems to be the only behavioral change that occurs without the user taking any explicit steps. Session.execute() will still behave the old way as we are adding a future flag. This change also adds the "future" flag to Session() and session.execute(), so that interpretation of the incoming statement, as well as that the new style result is returned, does not occur for existing applications unless they add the use of this flag. The change in general is moving the "removed in 2.0" system further along where we want the test suite to fully pass even if the SQLALCHEMY_WARN_20 flag is set. Get many tests to pass when SQLALCHEMY_WARN_20 is set; this should be ongoing after this patch merges. Improve the RemovedIn20 warning; these are all deprecated "since" 1.4, so ensure that's what the messages read. Make sure the inforamtion link is on all warnings. Add deprecation warnings for parameters present and add warnings to all FromClause.select() types of methods. Fixes: #5379 Fixes: #5284 Change-Id: I765a0b912b3dcd0e995426427d8bb7997cbffd51 References: #5159
63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
from sqlalchemy import extract
|
|
from sqlalchemy import select
|
|
from sqlalchemy import sql
|
|
from sqlalchemy.dialects import sybase
|
|
from sqlalchemy.testing import AssertsCompiledSQL
|
|
from sqlalchemy.testing import fixtures
|
|
|
|
|
|
class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
|
|
__dialect__ = sybase.dialect()
|
|
|
|
def test_extract(self):
|
|
t = sql.table("t", sql.column("col1"))
|
|
|
|
mapping = {
|
|
"day": "day",
|
|
"doy": "dayofyear",
|
|
"dow": "weekday",
|
|
"milliseconds": "millisecond",
|
|
"millisecond": "millisecond",
|
|
"year": "year",
|
|
}
|
|
|
|
for field, subst in list(mapping.items()):
|
|
self.assert_compile(
|
|
select(extract(field, t.c.col1)),
|
|
'SELECT DATEPART("%s", t.col1) AS anon_1 FROM t' % subst,
|
|
)
|
|
|
|
def test_limit_offset(self):
|
|
stmt = select(1).limit(5).offset(6)
|
|
assert stmt.compile().params == {"param_1": 5, "param_2": 6}
|
|
self.assert_compile(
|
|
stmt, "SELECT 1 ROWS LIMIT :param_1 OFFSET :param_2"
|
|
)
|
|
|
|
def test_offset(self):
|
|
stmt = select(1).offset(10)
|
|
assert stmt.compile().params == {"param_1": 10}
|
|
self.assert_compile(stmt, "SELECT 1 ROWS OFFSET :param_1")
|
|
|
|
def test_limit(self):
|
|
stmt = select(1).limit(5)
|
|
assert stmt.compile().params == {"param_1": 5}
|
|
self.assert_compile(stmt, "SELECT 1 ROWS LIMIT :param_1")
|
|
|
|
def test_delete_extra_froms(self):
|
|
t1 = sql.table("t1", sql.column("c1"))
|
|
t2 = sql.table("t2", sql.column("c1"))
|
|
q = sql.delete(t1).where(t1.c.c1 == t2.c.c1)
|
|
self.assert_compile(
|
|
q, "DELETE FROM t1 FROM t1, t2 WHERE t1.c1 = t2.c1"
|
|
)
|
|
|
|
def test_delete_extra_froms_alias(self):
|
|
a1 = sql.table("t1", sql.column("c1")).alias("a1")
|
|
t2 = sql.table("t2", sql.column("c1"))
|
|
q = sql.delete(a1).where(a1.c.c1 == t2.c.c1)
|
|
self.assert_compile(
|
|
q, "DELETE FROM a1 FROM t1 AS a1, t2 WHERE a1.c1 = t2.c1"
|
|
)
|
|
self.assert_compile(sql.delete(a1), "DELETE FROM t1 AS a1")
|