From bd1d6012dcbe5fbc6d1097a79d85b972b0d4fd8a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 10 May 2018 11:39:06 -0400 Subject: SQL Server is not native boolean; add new flag for CHECK constraint Fixed a 1.2 regression caused by :ticket:`4061` where the SQL Server "BIT" type would be considered to be "native boolean". The goal here was to avoid creating a CHECK constraint on the column, however the bigger issue is that the BIT value does not behave like a true/false constant and cannot be interpreted as a standalone expression, e.g. "WHERE ". The SQL Server dialect now goes back to being non-native boolean, but with an extra flag that still avoids creating the CHECK constraint. Change-Id: I4765d2a2a00b0d14f50282603cc4d48d4739dac1 Fixes: #4250 --- lib/sqlalchemy/testing/suite/test_types.py | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'lib/sqlalchemy/testing') diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index b9458c570..4cdf14dc9 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -612,6 +612,48 @@ class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest): (None, None) ) + def test_whereclause(self): + # testing "WHERE " renders a compatible expression + boolean_table = self.tables.boolean_table + + with config.db.connect() as conn: + conn.execute( + boolean_table.insert(), + [ + {'id': 1, 'value': True, 'unconstrained_value': True}, + {'id': 2, 'value': False, 'unconstrained_value': False} + ] + ) + + eq_( + conn.scalar( + select([boolean_table.c.id]).where(boolean_table.c.value) + ), + 1 + ) + eq_( + conn.scalar( + select([boolean_table.c.id]).where( + boolean_table.c.unconstrained_value) + ), + 1 + ) + eq_( + conn.scalar( + select([boolean_table.c.id]).where(~boolean_table.c.value) + ), + 2 + ) + eq_( + conn.scalar( + select([boolean_table.c.id]).where( + ~boolean_table.c.unconstrained_value) + ), + 2 + ) + + + class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest): __requires__ = 'json_type', -- cgit v1.2.1