)
def update_stmt():
- clause = sql.and_()
+ clauses = []
for col in mapper._pks_by_table[table]:
- clause.clauses.append(
- col == sql.bindparam(col._label, type_=col.type)
- )
+ clauses.append(col == sql.bindparam(col._label, type_=col.type))
if needs_version_id:
- clause.clauses.append(
+ clauses.append(
mapper.version_id_col
== sql.bindparam(
mapper.version_id_col._label,
)
)
- stmt = table.update(clause)
+ stmt = table.update(sql.and_(*clauses) if len(clauses) > 0 else None)
return stmt
cached_stmt = base_mapper._memo(("update", table), update_stmt)
)
def update_stmt():
- clause = sql.and_()
+ clauses = []
for col in mapper._pks_by_table[table]:
- clause.clauses.append(
- col == sql.bindparam(col._label, type_=col.type)
- )
+ clauses.append(col == sql.bindparam(col._label, type_=col.type))
if needs_version_id:
- clause.clauses.append(
+ clauses.append(
mapper.version_id_col
== sql.bindparam(
mapper.version_id_col._label,
)
)
- stmt = table.update(clause)
+ stmt = table.update(sql.and_(*clauses) if len(clauses) > 0 else None)
if mapper.version_id_col is not None:
stmt = stmt.return_defaults(mapper.version_id_col)
)
def delete_stmt():
- clause = sql.and_()
+ clauses = []
for col in mapper._pks_by_table[table]:
- clause.clauses.append(
- col == sql.bindparam(col.key, type_=col.type)
- )
+ clauses.append(col == sql.bindparam(col.key, type_=col.type))
if need_version_id:
- clause.clauses.append(
+ clauses.append(
mapper.version_id_col
== sql.bindparam(
mapper.version_id_col.key, type_=mapper.version_id_col.type
)
)
- return table.delete(clause)
+ return table.delete(sql.and_(*clauses) if len(clauses) > 0 else None)
statement = base_mapper._memo(("delete", table), delete_stmt)
for connection, recs in groupby(delete, lambda rec: rec[1]): # connection
for obj in (
Table("foo", MetaData(), Column("x", Integer)),
Column("x", Integer),
- tsa.and_(),
+ tsa.and_(True),
column("foo"),
- tsa.and_().compile(),
+ tsa.and_(True).compile(),
column("foo").compile(),
MetaData(),
Integer(),
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import eq_
from sqlalchemy.testing import eq_ignore_whitespace
+from sqlalchemy.testing import expect_deprecated
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
from sqlalchemy.util import u
and_(
or_(
or_(t.c.x == 12),
- and_(or_(), or_(and_(t.c.x == 8)), and_()),
+ and_(or_(and_(t.c.x == 8))),
)
)
),
"SELECT t.x FROM t WHERE t.x = :x_1 OR t.x = :x_2",
)
+ with expect_deprecated():
+ self.assert_compile(
+ select([t]).where(
+ and_(
+ or_(
+ or_(t.c.x == 12),
+ and_(or_(), or_(and_(t.c.x == 8)), and_()),
+ )
+ )
+ ),
+ "SELECT t.x FROM t WHERE t.x = :x_1 OR t.x = :x_2",
+ )
def test_true_short_circuit(self):
t = table("t", column("x"))
)
def test_where_empty(self):
- self.assert_compile(
- select([table1.c.myid]).where(and_()),
- "SELECT mytable.myid FROM mytable",
- )
- self.assert_compile(
- select([table1.c.myid]).where(or_()),
- "SELECT mytable.myid FROM mytable",
- )
+ with expect_deprecated():
+ self.assert_compile(
+ select([table1.c.myid]).where(and_()),
+ "SELECT mytable.myid FROM mytable",
+ )
+ with expect_deprecated():
+ self.assert_compile(
+ select([table1.c.myid]).where(or_()),
+ "SELECT mytable.myid FROM mytable",
+ )
def test_order_by_nulls(self):
self.assert_compile(
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import eq_
+from sqlalchemy.testing import expect_deprecated
from sqlalchemy.testing import fixtures
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
def test_where_empty(self):
table1 = self.tables.mytable
- self.assert_compile(
- table1.delete().where(and_()), "DELETE FROM mytable"
- )
- self.assert_compile(
- table1.delete().where(or_()), "DELETE FROM mytable"
- )
+ with expect_deprecated():
+ self.assert_compile(
+ table1.delete().where(and_()), "DELETE FROM mytable"
+ )
+ with expect_deprecated():
+ self.assert_compile(
+ table1.delete().where(or_()), "DELETE FROM mytable"
+ )
def test_prefix_with(self):
table1 = self.tables.mytable
self.assert_compile(or_(~and_(true())), "false")
def test_three(self):
- self.assert_compile(or_(and_()), "")
+ with expect_deprecated():
+ self.assert_compile(or_(and_()), "")
def test_four(self):
x = column("x")
elements.True_(),
elements.False_(),
elements.ClauseList(),
- elements.BooleanClauseList.and_(),
+ elements.BooleanClauseList.and_(True),
+ elements.BooleanClauseList.or_(False),
elements.Tuple(),
elements.Case([]),
elements.Extract("foo", column("x")),
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import eq_
+from sqlalchemy.testing import expect_deprecated
from sqlalchemy.testing import fixtures
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
def test_where_empty(self):
table1 = self.tables.mytable
- self.assert_compile(
- table1.update().where(and_()),
- "UPDATE mytable SET myid=:myid, name=:name, "
- "description=:description",
- )
- self.assert_compile(
- table1.update().where(or_()),
- "UPDATE mytable SET myid=:myid, name=:name, "
- "description=:description",
- )
+ with expect_deprecated():
+ self.assert_compile(
+ table1.update().where(and_()),
+ "UPDATE mytable SET myid=:myid, name=:name, "
+ "description=:description",
+ )
+ with expect_deprecated():
+ self.assert_compile(
+ table1.update().where(or_()),
+ "UPDATE mytable SET myid=:myid, name=:name, "
+ "description=:description",
+ )
def test_prefix_with(self):
table1 = self.tables.mytable