Skip to content

Commit 856d0aa

Browse files
Tweaks to boolean variable improvements patch supplied by Alex Henrie
(#435).
1 parent 17fd92f commit 856d0aa

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed

doc/src/release_notes.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ Version 8.0 (TBD)
6666
`421 <https://github.com/oracle/python-cx_Oracle/pull/421>`__,
6767
`422 <https://github.com/oracle/python-cx_Oracle/pull/422>`__ and
6868
`423 <https://github.com/oracle/python-cx_Oracle/pull/423>`__).
69+
#) Python objects bound to boolean variables are now converted to True or
70+
False based on whether they would be considered True or False in a Python
71+
if statement. Previously, only True was treated as True and all other
72+
Python values (including 1, 1.0, and "foo") were treated as False
73+
(pull request
74+
`435 <https://github.com/oracle/python-cx_Oracle/pull/435>`__).
6975
#) Documentation and test suite improvements.
70-
#) Python objects bound to boolean variables are now converted to true or false
71-
based on whether they would be considered true or false in a Python if
72-
statement. (Previously, only True was treated as true and all other Python
73-
values including 1, 1.0, and "foo" were treated as false.)
7476

7577

7678
Version 7.3 (December 2019)

src/cxoTransform.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ int cxoTransform_fromPython(cxoTransformNum transformNum,
244244
switch (transformNum) {
245245
case CXO_TRANSFORM_BOOLEAN:
246246
dbValue->asBoolean = PyObject_IsTrue(pyValue);
247+
if (PyErr_Occurred())
248+
return -1;
247249
return 0;
248250
case CXO_TRANSFORM_BINARY:
249251
case CXO_TRANSFORM_FIXED_CHAR:

test/BooleanVar.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515

1616
class TestCase(TestEnv.BaseTestCase):
1717

18+
def __testBindValueAsBoolean(self, value):
19+
expectedResult = str(bool(value)).upper()
20+
var = self.cursor.var(bool)
21+
var.setvalue(0, value)
22+
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
23+
(var,))
24+
self.assertEqual(result, expectedResult)
25+
1826
def testBindFalse(self):
1927
"test binding in a False value"
2028
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
@@ -23,29 +31,13 @@ def testBindFalse(self):
2331

2432
def testBindFloatAsBoolean(self):
2533
"test binding in a float as a boolean"
26-
var = self.cursor.var(bool)
27-
var.setvalue(0, 0.0)
28-
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
29-
(var,))
30-
self.assertEqual(result, "FALSE")
31-
var = self.cursor.var(bool)
32-
var.setvalue(0, 1.0)
33-
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
34-
(var,))
35-
self.assertEqual(result, "TRUE")
34+
self.__testBindValueAsBoolean(0.0)
35+
self.__testBindValueAsBoolean(1.0)
3636

3737
def testBindIntegerAsBoolean(self):
3838
"test binding in an integer as a boolean"
39-
var = self.cursor.var(bool)
40-
var.setvalue(0, 0)
41-
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
42-
(var,))
43-
self.assertEqual(result, "FALSE")
44-
var = self.cursor.var(bool)
45-
var.setvalue(0, 1)
46-
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
47-
(var,))
48-
self.assertEqual(result, "TRUE")
39+
self.__testBindValueAsBoolean(0)
40+
self.__testBindValueAsBoolean(1)
4941

5042
def testBindNull(self):
5143
"test binding in a null value"
@@ -68,16 +60,8 @@ def testBindOutTrue(self):
6860

6961
def testBindStringAsBoolean(self):
7062
"test binding in a string as a boolean"
71-
var = self.cursor.var(bool)
72-
var.setvalue(0, "")
73-
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
74-
(var,))
75-
self.assertEqual(result, "FALSE")
76-
var = self.cursor.var(bool)
77-
var.setvalue(0, "0")
78-
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
79-
(var,))
80-
self.assertEqual(result, "TRUE")
63+
self.__testBindValueAsBoolean("")
64+
self.__testBindValueAsBoolean("0")
8165

8266
def testBindTrue(self):
8367
"test binding in a True value"
@@ -87,4 +71,3 @@ def testBindTrue(self):
8771

8872
if __name__ == "__main__":
8973
TestEnv.RunTestCases()
90-

0 commit comments

Comments
 (0)