diff options
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/default.py | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/sqltypes.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/testing/suite/test_types.py | 42 |
4 files changed, 47 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index f55f7e74d..2975a6c69 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -1820,7 +1820,8 @@ class MSDialect(default.DefaultDialect): ischema_names = ischema_names - supports_native_boolean = True + supports_native_boolean = False + non_native_boolean_check_constraint = False supports_unicode_binds = True postfetch_lastrowid = True diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 5806fe2a9..099e694b6 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -63,6 +63,7 @@ class DefaultDialect(interfaces.Dialect): supports_native_enum = False supports_native_boolean = False + non_native_boolean_check_constraint = True supports_simple_order_by_label = True diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 573fda98f..a2ae9de50 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -1643,7 +1643,8 @@ class Boolean(Emulated, TypeEngine, SchemaType): def _should_create_constraint(self, compiler, **kw): if not self._is_impl_for_variant(compiler.dialect, kw): return False - return not compiler.dialect.supports_native_boolean + return not compiler.dialect.supports_native_boolean and \ + compiler.dialect.non_native_boolean_check_constraint @util.dependencies("sqlalchemy.sql.schema") def _set_table(self, schema, column, table): 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 <column>" 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', |
