[Sqlalchemy-tickets] Issue #4061: SQL Server BIT is native boolean (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2017-08-30 22:00:43
|
New issue 4061: SQL Server BIT is native boolean https://bitbucket.org/zzzeek/sqlalchemy/issues/4061/sql-server-bit-is-native-boolean Michael Bayer: we should not be creating a constraint for Boolean on SQL Server and we should support native boolean rules. The BIT type only stores 1 or 0 and converts any other integer into a 1: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) data = Column(Boolean(create_constraint=False)) #e = create_engine("mssql+pymssql://scott:tiger^5HHH@mssql2017:1433/test", echo=True) e = create_engine("mssql+pyodbc://scott:tiger^5HHH@mssql2017:1433/test?driver=FreeTDS", echo=True) Base.metadata.drop_all(e) Base.metadata.create_all(e) conn = e.connect() conn.execute("INSERT INTO a (data) VALUES (1)") conn.execute("INSERT INTO a (data) VALUES (15)") if e.dialect.driver == 'pymssql': conn.execute("INSERT INTO a (data) VALUES (%(data)s)", {"data": True}) conn.execute("INSERT INTO a (data) VALUES (%(data)s)", {"data": 25}) conn.execute("INSERT INTO a (data) VALUES (%(data)s)", {"data": 1}) else: conn.execute("INSERT INTO a (data) VALUES (?)", [True]) conn.execute("INSERT INTO a (data) VALUES (?)", [25]) conn.execute("INSERT INTO a (data) VALUES (?)", [1]) print e.execute(select([A.data])).fetchall() ``` |