From c3c31ddec6ac58675984e815b2f68950dc8b2a7f Mon Sep 17 00:00:00 2001 From: Vilnis Termanis Date: Thu, 20 Oct 2016 16:17:53 +0100 Subject: [PATCH] fix microsecond conversion from MySQL DATETIME to Python datetime --- src/mysql_capi_conversion.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mysql_capi_conversion.c b/src/mysql_capi_conversion.c index d2d1655..145ecb9 100644 --- a/src/mysql_capi_conversion.c +++ b/src/mysql_capi_conversion.c @@ -441,7 +441,7 @@ mytopy_datetime(const char *data, const unsigned long length) if (data != end && end - data >= 2 && *data == '.') { // Fractional part - int field_length= 6; // max fractional - 1 + int field_length= 5; data++; value= (unsigned int)(*data - '0'); while (data++ != end && isdigit(*data)) @@ -451,6 +451,13 @@ mytopy_datetime(const char *data, const unsigned long length) value= (value * 10) + (unsigned int)(*data - '0'); } } + if (field_length >= 0) + { + while (field_length-- > 0) + { + value*= 10; + } + } parts[6]= value; }