mirror of
https://github.com/mariadb-corporation/mariadb-connector-python.git
synced 2026-01-14 02:00:30 +00:00
Fix for CONPY-329:
Return None for invalid dates instead of raising an exception
This commit is contained in:
@ -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)
|
||||
{
|
||||
|
||||
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user