Fix for CONPY-329:

Return None for invalid dates instead of raising an exception
This commit is contained in:
Georg Richter
2025-11-18 10:55:17 +01:00
parent 5e6ed7b642
commit f04e098105
2 changed files with 15 additions and 1 deletions

View File

@ -790,7 +790,6 @@ field_fetch_callback(void *data, unsigned int column, unsigned char **row)
if (!len)
{
self->values[column]= PyDate_FromDate(0,0,0);
break;
}
year= uint2korr(*row);
@ -899,6 +898,12 @@ field_fetch_callback(void *data, unsigned int column, unsigned char **row)
default:
break;
}
if (!self->values[column])
{
PyErr_Clear();
Py_INCREF(Py_None);
self->values[column]= Py_None;
}
/* check if values need to be converted */
if (self->connection->converter)
{

View File

@ -57,6 +57,15 @@ class TestCursor(unittest.TestCase):
self.assertEqual(row[1], 255)
cursor.execute("DROP TABLE t1")
def test_conpy329(self):
cursor= self.connection.cursor(binary=True)
cursor.execute("CREATE TEMPORARY TABLE t1 (a date)")
cursor.execute("INSERT INTO t1 VALUES ('0000-01-01')")
cursor.execute("SELECT * FROM t1")
row= cursor.fetchone()
self.assertEqual(row[0],None)
cursor.execute("DROP TABLE t1")
def test_conpy306(self):
with create_connection() as conn:
cursor=conn.cursor(binary=False)