@@ -50,6 +50,9 @@ struct st_mysqlnd_perm_bind mysqlnd_ps_fetch_functions[MYSQL_TYPE_LAST + 1];
5050#define MYSQLND_PS_SKIP_RESULT_W_LEN -1
5151#define MYSQLND_PS_SKIP_RESULT_STR -2
5252
53+ #define MYSQLND_SEC_PART_DIGITS 6
54+ #define MYSQLND_AUTO_SEC_PART_DIGITS 39
55+
5356/* {{{ ps_fetch_from_1_to_8_bytes */
5457void
5558ps_fetch_from_1_to_8_bytes (zval * zv , const MYSQLND_FIELD * const field , const unsigned int pack_len ,
@@ -237,7 +240,9 @@ ps_fetch_time(zval * zv, const MYSQLND_FIELD * const field, const unsigned int p
237240 t .time_type = MYSQLND_TIMESTAMP_TIME ;
238241 }
239242
240- if (field -> decimals > 0 && field -> decimals < 7 ) {
243+ if (field -> decimals > 0 && (field -> decimals <= MYSQLND_SEC_PART_DIGITS ||
244+ (field -> decimals == MYSQLND_AUTO_SEC_PART_DIGITS && t .second_part ))) {
245+ uint8_t decimals = (field -> decimals == MYSQLND_AUTO_SEC_PART_DIGITS ) ? MYSQLND_SEC_PART_DIGITS : field -> decimals ;
241246 ZVAL_STR (zv , zend_strpprintf (0 , "%s%02u:%02u:%02u.%0*u" ,
242247 (t .neg ? "-" : "" ), t .hour , t .minute , t .second , field -> decimals ,
243248 (uint32_t ) (t .second_part / pow (10 , 6 - field -> decimals ))));
@@ -315,10 +320,12 @@ ps_fetch_datetime(zval * zv, const MYSQLND_FIELD * const field, const unsigned i
315320 t .time_type = MYSQLND_TIMESTAMP_DATETIME ;
316321 }
317322
318- if (field -> decimals > 0 && field -> decimals < 7 ) {
323+ if (field -> decimals > 0 && (field -> decimals <= MYSQLND_SEC_PART_DIGITS ||
324+ (field -> decimals == MYSQLND_AUTO_SEC_PART_DIGITS && t .second_part ))) {
325+ uint8_t decimals = (field -> decimals == MYSQLND_AUTO_SEC_PART_DIGITS ) ? MYSQLND_SEC_PART_DIGITS : field -> decimals ;
319326 ZVAL_STR (zv , zend_strpprintf (0 , "%04u-%02u-%02u %02u:%02u:%02u.%0*u" ,
320- t .year , t .month , t .day , t .hour , t .minute , t .second , field -> decimals ,
321- (uint32_t ) (t .second_part / pow (10 , 6 - field -> decimals ))));
327+ t .year , t .month , t .day , t .hour , t .minute , t .second , decimals ,
328+ (uint32_t ) (t .second_part / pow (10 , 6 - decimals ))));
322329 } else {
323330 ZVAL_STR (zv , zend_strpprintf (0 , "%04u-%02u-%02u %02u:%02u:%02u" ,
324331 t .year , t .month , t .day , t .hour , t .minute , t .second ));
0 commit comments