Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 17fd92f

Browse filesBrowse files
authored
Convert Python objects to booleans based on their Python truth value (#435)
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
1 parent ba9a3ea commit 17fd92f
Copy full SHA for 17fd92f

File tree

Expand file treeCollapse file tree

3 files changed

+44
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+44
-1
lines changed

‎doc/src/release_notes.rst

Copy file name to clipboardExpand all lines: doc/src/release_notes.rst
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ Version 8.0 (TBD)
6767
`422 <https://github.com/oracle/python-cx_Oracle/pull/422>`__ and
6868
`423 <https://github.com/oracle/python-cx_Oracle/pull/423>`__).
6969
#) 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.)
7074

7175

7276
Version 7.3 (December 2019)

‎src/cxoTransform.c

Copy file name to clipboardExpand all lines: src/cxoTransform.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ int cxoTransform_fromPython(cxoTransformNum transformNum,
243243

244244
switch (transformNum) {
245245
case CXO_TRANSFORM_BOOLEAN:
246-
dbValue->asBoolean = (pyValue == Py_True);
246+
dbValue->asBoolean = PyObject_IsTrue(pyValue);
247247
return 0;
248248
case CXO_TRANSFORM_BINARY:
249249
case CXO_TRANSFORM_FIXED_CHAR:

‎test/BooleanVar.py

Copy file name to clipboardExpand all lines: test/BooleanVar.py
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,32 @@ def testBindFalse(self):
2121
(False,))
2222
self.assertEqual(result, "FALSE")
2323

24+
def testBindFloatAsBoolean(self):
25+
"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")
36+
37+
def testBindIntegerAsBoolean(self):
38+
"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")
49+
2450
def testBindNull(self):
2551
"test binding in a null value"
2652
self.cursor.setinputsizes(None, bool)
@@ -40,6 +66,19 @@ def testBindOutTrue(self):
4066
(5,))
4167
self.assertEqual(result, True)
4268

69+
def testBindStringAsBoolean(self):
70+
"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")
81+
4382
def testBindTrue(self):
4483
"test binding in a True value"
4584
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.