diff options
Diffstat (limited to 'ext/mysqlnd/mysqlnd_ps_codec.c')
-rw-r--r-- | ext/mysqlnd/mysqlnd_ps_codec.c | 82 |
1 files changed, 26 insertions, 56 deletions
diff --git a/ext/mysqlnd/mysqlnd_ps_codec.c b/ext/mysqlnd/mysqlnd_ps_codec.c index e942f10fac..eba4805b9d 100644 --- a/ext/mysqlnd/mysqlnd_ps_codec.c +++ b/ext/mysqlnd/mysqlnd_ps_codec.c @@ -40,7 +40,7 @@ struct st_mysqlnd_time { unsigned int year, month, day, hour, minute, second; zend_ulong second_part; - zend_bool neg; + bool neg; enum mysqlnd_timestamp_type time_type; }; @@ -57,7 +57,7 @@ ps_fetch_from_1_to_8_bytes(zval * zv, const MYSQLND_FIELD * const field, const u { char tmp[22]; size_t tmp_len = 0; - zend_bool is_bit = field->type == MYSQL_TYPE_BIT; + bool is_bit = field->type == MYSQL_TYPE_BIT; DBG_ENTER("ps_fetch_from_1_to_8_bytes"); DBG_INF_FMT("zv=%p byte_count=%u", zv, byte_count); if (field->flags & UNSIGNED_FLAG) { @@ -74,6 +74,11 @@ ps_fetch_from_1_to_8_bytes(zval * zv, const MYSQLND_FIELD * const field, const u case 1:uval = (uint64_t) uint1korr(*row);break; } + if (field->flags & ZEROFILL_FLAG) { + DBG_INF("stringify due to zerofill"); + tmp_len = sprintf((char *)&tmp, "%0*" PRIu64, (int) field->length, uval); + DBG_INF_FMT("value=%s", tmp); + } else #if SIZEOF_ZEND_LONG==4 if (uval > INT_MAX) { DBG_INF("stringify"); @@ -212,15 +217,14 @@ static void ps_fetch_time(zval * zv, const MYSQLND_FIELD * const field, const unsigned int pack_len, const zend_uchar ** row) { struct st_mysqlnd_time t; - zend_ulong length; /* First byte encodes the length*/ - char * value; + zend_ulong length; /* First byte encodes the length */ DBG_ENTER("ps_fetch_time"); if ((length = php_mysqlnd_net_field_length(row))) { const zend_uchar * to = *row; t.time_type = MYSQLND_TIMESTAMP_TIME; - t.neg = (zend_bool) to[0]; + t.neg = (bool) to[0]; t.day = (zend_ulong) sint4korr(to+1); t.hour = (unsigned int) to[5]; @@ -241,24 +245,13 @@ ps_fetch_time(zval * zv, const MYSQLND_FIELD * const field, const unsigned int p } if (field->decimals > 0 && field->decimals < 7) { - length = mnd_sprintf( - &value, - 0, - "%s%02u:%02u:%02u.%0*u", - (t.neg ? "-" : ""), - t.hour, - t.minute, - t.second, - field->decimals, - (uint32_t) (t.second_part / pow(10, 6 - field->decimals)) - ); + ZVAL_STR(zv, zend_strpprintf(0, "%s%02u:%02u:%02u.%0*u", + (t.neg ? "-" : ""), t.hour, t.minute, t.second, field->decimals, + (uint32_t) (t.second_part / pow(10, 6 - field->decimals)))); } else { - length = mnd_sprintf(&value, 0, "%s%02u:%02u:%02u", (t.neg ? "-" : ""), t.hour, t.minute, t.second); + ZVAL_STR(zv, zend_strpprintf(0, "%s%02u:%02u:%02u", + (t.neg ? "-" : ""), t.hour, t.minute, t.second)); } - - DBG_INF_FMT("%s", value); - ZVAL_STRINGL(zv, value, length); - mnd_sprintf_free(value); DBG_VOID_RETURN; } /* }}} */ @@ -270,7 +263,6 @@ ps_fetch_date(zval * zv, const MYSQLND_FIELD * const field, const unsigned int p { struct st_mysqlnd_time t = {0}; zend_ulong length; /* First byte encodes the length*/ - char * value; DBG_ENTER("ps_fetch_date"); if ((length = php_mysqlnd_net_field_length(row))) { @@ -291,11 +283,7 @@ ps_fetch_date(zval * zv, const MYSQLND_FIELD * const field, const unsigned int p t.time_type = MYSQLND_TIMESTAMP_DATE; } - length = mnd_sprintf(&value, 0, "%04u-%02u-%02u", t.year, t.month, t.day); - - DBG_INF_FMT("%s", value); - ZVAL_STRINGL(zv, value, length); - mnd_sprintf_free(value); + ZVAL_STR(zv, zend_strpprintf(0, "%04u-%02u-%02u", t.year, t.month, t.day)); DBG_VOID_RETURN; } /* }}} */ @@ -307,7 +295,6 @@ ps_fetch_datetime(zval * zv, const MYSQLND_FIELD * const field, const unsigned i { struct st_mysqlnd_time t; zend_ulong length; /* First byte encodes the length*/ - char * value; DBG_ENTER("ps_fetch_datetime"); if ((length = php_mysqlnd_net_field_length(row))) { @@ -336,26 +323,13 @@ ps_fetch_datetime(zval * zv, const MYSQLND_FIELD * const field, const unsigned i } if (field->decimals > 0 && field->decimals < 7) { - length = mnd_sprintf( - &value, - 0, - "%04u-%02u-%02u %02u:%02u:%02u.%0*u", - t.year, - t.month, - t.day, - t.hour, - t.minute, - t.second, - field->decimals, - (uint32_t) (t.second_part / pow(10, 6 - field->decimals)) - ); + ZVAL_STR(zv, zend_strpprintf(0, "%04u-%02u-%02u %02u:%02u:%02u.%0*u", + t.year, t.month, t.day, t.hour, t.minute, t.second, field->decimals, + (uint32_t) (t.second_part / pow(10, 6 - field->decimals)))); } else { - length = mnd_sprintf(&value, 0, "%04u-%02u-%02u %02u:%02u:%02u", t.year, t.month, t.day, t.hour, t.minute, t.second); + ZVAL_STR(zv, zend_strpprintf(0, "%04u-%02u-%02u %02u:%02u:%02u", + t.year, t.month, t.day, t.hour, t.minute, t.second)); } - - DBG_INF_FMT("%s", value); - ZVAL_STRINGL(zv, value, length); - mnd_sprintf_free(value); DBG_VOID_RETURN; } /* }}} */ @@ -365,15 +339,11 @@ ps_fetch_datetime(zval * zv, const MYSQLND_FIELD * const field, const unsigned i static void ps_fetch_string(zval * zv, const MYSQLND_FIELD * const field, const unsigned int pack_len, const zend_uchar ** row) { - /* - For now just copy, before we make it possible - to write \0 to the row buffer - */ const zend_ulong length = php_mysqlnd_net_field_length(row); DBG_ENTER("ps_fetch_string"); DBG_INF_FMT("len = %lu", length); DBG_INF("copying from the row buffer"); - ZVAL_STRINGL(zv, (char *)*row, length); + ZVAL_STRINGL_FAST(zv, (char *)*row, length); (*row) += length; DBG_VOID_RETURN; @@ -638,7 +608,7 @@ mysqlnd_stmt_execute_prepare_param_types(MYSQLND_STMT_DATA * stmt, zval ** copie */ if (d >= (double) ZEND_LONG_MAX || d < (double) ZEND_LONG_MIN) { stmt->send_types_to_server = *resend_types_next_time = 1; - convert_to_string_ex(tmp_data); + convert_to_string(tmp_data); } else { convert_to_long(tmp_data); } @@ -682,7 +652,7 @@ mysqlnd_stmt_execute_store_types(MYSQLND_STMT_DATA * stmt, zval * copies, zend_u current_type = MYSQL_TYPE_VAR_STRING; /* don't change stmt->param_bind[i].type to MYSQL_TYPE_VAR_STRING - we force convert_to_long_ex in all cases, thus the type will be right in the next switch. + we force convert_to_long in all cases, thus the type will be right in the next switch. if the type is however not long, then we will do a goto in the next switch. We want to preserve the original bind type given by the user. Thus, we do these hacks. */ @@ -749,7 +719,7 @@ mysqlnd_stmt_execute_calculate_param_values_size(MYSQLND_STMT_DATA * stmt, zval if (Z_TYPE_P(tmp_data) == IS_STRING) { goto use_string; } - convert_to_long_ex(tmp_data); + convert_to_long(tmp_data); } *data_size += 4 + is_longlong; break; @@ -806,7 +776,7 @@ mysqlnd_stmt_execute_store_param_values(MYSQLND_STMT_DATA * stmt, zval * copies, } else { switch (stmt->param_bind[i].type) { case MYSQL_TYPE_DOUBLE: - convert_to_double_ex(data); + convert_to_double(data); float8store(*p, Z_DVAL_P(data)); (*p) += 8; break; @@ -940,7 +910,7 @@ end: /* {{{ mysqlnd_stmt_execute_generate_request */ enum_func_status -mysqlnd_stmt_execute_generate_request(MYSQLND_STMT * const s, zend_uchar ** request, size_t *request_len, zend_bool * free_buffer) +mysqlnd_stmt_execute_generate_request(MYSQLND_STMT * const s, zend_uchar ** request, size_t *request_len, bool * free_buffer) { MYSQLND_STMT_DATA * stmt = s->data; zend_uchar *p = stmt->execute_cmd_buffer.buffer, |