mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Make Binary(None) work as expected, adapting to NULL
Issue reported by Stefano Dal Pra.
This commit is contained in:
parent
8530ef1793
commit
836f8a1aa1
|
@ -113,6 +113,12 @@ exit:
|
||||||
if (got_view) { PyBuffer_Release(&view); }
|
if (got_view) { PyBuffer_Release(&view); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Allow Binary(None) to work */
|
||||||
|
if (self->wrapped == Py_None) {
|
||||||
|
Py_INCREF(psyco_null);
|
||||||
|
rv = psyco_null;
|
||||||
|
}
|
||||||
|
|
||||||
/* if the wrapped object is not bytes or a buffer, this is an error */
|
/* if the wrapped object is not bytes or a buffer, this is an error */
|
||||||
if (!rv && !PyErr_Occurred()) {
|
if (!rv && !PyErr_Occurred()) {
|
||||||
PyErr_Format(PyExc_TypeError, "can't escape %s to binary",
|
PyErr_Format(PyExc_TypeError, "can't escape %s to binary",
|
||||||
|
|
|
@ -128,6 +128,11 @@ class TypesBasicTests(unittest.TestCase):
|
||||||
buf = self.execute("SELECT %s::bytea AS foo", (b,))
|
buf = self.execute("SELECT %s::bytea AS foo", (b,))
|
||||||
self.assertEqual(s, buf)
|
self.assertEqual(s, buf)
|
||||||
|
|
||||||
|
def testBinaryNone(self):
|
||||||
|
b = psycopg2.Binary(None)
|
||||||
|
buf = self.execute("SELECT %s::bytea AS foo", (b,))
|
||||||
|
self.assertEqual(buf, None)
|
||||||
|
|
||||||
def testBinaryEmptyString(self):
|
def testBinaryEmptyString(self):
|
||||||
# test to make sure an empty Binary is converted to an empty string
|
# test to make sure an empty Binary is converted to an empty string
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user