diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-06-23 19:26:28 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-06-23 19:58:43 -0400 |
| commit | 7c74d702a9632a8c7264d6972e46985de3fb2487 (patch) | |
| tree | 9db49b27827f580b856671186aae2d40952d74f2 /test/sql | |
| parent | bf03d4332ae35e2087b175f8a2e0291d2f4c9aa0 (diff) | |
| download | sqlalchemy-7c74d702a9632a8c7264d6972e46985de3fb2487.tar.gz | |
Make boolean processors consistent between Py/C; coerce to 1/0
The processing performed by the :class:`.Boolean` datatype for backends
that only feature integer types has been made consistent between the
pure Python and C-extension versions, in that the C-extension version
will accept any integer value from the database as a boolean, not just
zero and one; additionally, non-boolean integer values being sent to
the database are coerced to exactly zero or one, instead of being
passed as the original integer value.
Change-Id: I01e647547fd7047bd549dd70e1fa202c51e8328b
Fixes: #3730
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_types.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/sql/test_types.py b/test/sql/test_types.py index e540f9246..49a1d8f15 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -2314,6 +2314,37 @@ class BooleanTest( dialect="sqlite" ) + @testing.skip_if(lambda: testing.db.dialect.supports_native_boolean) + def test_nonnative_processor_coerces_to_onezero(self): + boolean_table = self.tables.boolean_table + with testing.db.connect() as conn: + conn.execute( + boolean_table.insert(), + {"id": 1, "unconstrained_value": 5} + ) + + eq_( + conn.scalar("select unconstrained_value from boolean_table"), + 1 + ) + + @testing.skip_if(lambda: testing.db.dialect.supports_native_boolean) + def test_nonnative_processor_coerces_integer_to_boolean(self): + boolean_table = self.tables.boolean_table + with testing.db.connect() as conn: + conn.execute( + "insert into boolean_table (id, unconstrained_value) values (1, 5)" + ) + + eq_( + conn.scalar("select unconstrained_value from boolean_table"), + 5 + ) + + eq_( + conn.scalar(select([boolean_table.c.unconstrained_value])), + True + ) class PickleTest(fixtures.TestBase): |
