.. changelog::
:version: 0.8.7
+ .. change::
+ :tags: bug, sql
+ :tickets: 3045
+ :versions: 0.9.5
+
+ Fixed bug where :meth:`.Table.update` and :meth:`.Table.delete`
+ would produce an empty WHERE clause when an empty :func:`.and_()`
+ or :func:`.or_()` or other blank expression were applied. This is
+ now consistent with that of :func:`.select`.
+
.. change::
:tags: bug, postgresql
:pullreq: bitbucket:13
text += " " + extra_from_text
if update_stmt._whereclause is not None:
- text += " WHERE " + self.process(update_stmt._whereclause)
+ t = self.process(update_stmt._whereclause)
+ if t:
+ text += " WHERE " + t
limit_clause = self.update_limit_clause(update_stmt)
if limit_clause:
delete_stmt, delete_stmt._returning)
if delete_stmt._whereclause is not None:
- text += " WHERE "
- text += delete_stmt._whereclause._compiler_dispatch(self)
+ t = delete_stmt._whereclause._compiler_dispatch(self)
+ if t:
+ text += " WHERE " + t
if self.returning and not self.returning_precedes_values:
text += " " + self.returning_clause(
)
+ 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"
+ )
def test_multiple_col_binds(self):
self.assert_compile(
#! coding:utf-8
-from sqlalchemy import Column, Integer, String, Table, delete, select
+from sqlalchemy import Column, Integer, String, Table, delete, select, and_, or_
from sqlalchemy.dialects import mysql
from sqlalchemy.testing import AssertsCompiledSQL, fixtures
'WHERE mytable.myid = :myid_1 '
'AND mytable.name = :name_1')
+ 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"
+ )
+
def test_prefix_with(self):
table1 = self.tables.mytable
'mytable.myid = hoho(:hoho_1) AND '
'mytable.name = :param_2 || mytable.name || :param_3')
+ 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"
+ )
+
def test_prefix_with(self):
table1 = self.tables.mytable