Skip to content
Permalink
Browse files
Fix for CONPY-150:
Since Python complains about invalid date types (year, month or day=0),
they need to converted to NULL instead of PyDate* object.
  • Loading branch information
9EOR9 committed Apr 6, 2021
1 parent fdee513 commit 8b5f9ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
@@ -666,11 +666,11 @@ field_fetch_callback(void *data, unsigned int column, unsigned char **row)
uint8_t len= 0;
int year= 0, month= 0, day= 0,
hour= 0, minute= 0, second= 0, second_part= 0;

len= (uint8_t)mysql_net_field_length(row);
if (!len)
{
self->values[column]= PyDateTime_FromDateAndTime(0,0,0,0,0,0,0);
Py_INCREF(Py_None);
self->values[column]= Py_None;
break;
}
year= uint2korr(*row);
@@ -698,7 +698,8 @@ field_fetch_callback(void *data, unsigned int column, unsigned char **row)

if (!len)
{
self->values[column]= PyDate_FromDate(0,0,0);
Py_INCREF(Py_None);
self->values[column]= Py_None;
break;
}
year= uint2korr(*row);
@@ -1152,6 +1152,22 @@ def test_conpy139(self):
del c1, c2
connection.close()

def test_conpy150(self):
connection= create_connection()
cursor= connection.cursor()
cursor.execute("create temporary table t1 (id int, a datetime not null default '0000-00-00 00:00:00', b date not null default '0000-00-00')")
cursor.execute("insert into t1 (id) values (1)");
cursor.execute("select * from t1")
row= cursor.fetchone()
self.assertEqual(row[1], None)
self.assertEqual(row[2], None)
cursor.execute("select * from t1 WHERE 1=?", (1,))
row= cursor.fetchone()
self.assertEqual(row[1], None)
self.assertEqual(row[2], None)
del cursor
connection.close()

def test_conpy91(self):
with create_connection() as connection:
with connection.cursor() as cursor:

0 comments on commit 8b5f9ab

Please sign in to comment.