diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index e8dddb1238708863422a90166c42eba4fe18f02d..d8017a8727af05c947323f424c41abc642b91d6d 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -558,15 +558,6 @@ static void doSetOneRowPtr(SReqResultInfo* pResultInfo) { pResultInfo->length[i] = varDataLen(pStart); pResultInfo->row[i] = varDataVal(pStart); - - if (type == TSDB_DATA_TYPE_NCHAR) { - int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(pResultInfo->convertBuf[i])); - ASSERT(len <= bytes); - - pResultInfo->row[i] = varDataVal(pResultInfo->convertBuf[i]); - varDataSetLen(pResultInfo->convertBuf[i], len); - pResultInfo->length[i] = len; - } } else { pResultInfo->row[i] = NULL; } @@ -689,12 +680,6 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { if (pResInfo->row == NULL || pResInfo->pCol == NULL || pResInfo->length == NULL || pResInfo->convertBuf == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - - for(int32_t i = 0; i < pResInfo->numOfCols; ++i) { - if(pResInfo->fields[i].type == TSDB_DATA_TYPE_NCHAR) { - pResInfo->convertBuf[i] = taosMemoryCalloc(1, NCHAR_WIDTH_TO_BYTES(pResInfo->fields[i].bytes)); - } - } } return TSDB_CODE_SUCCESS; @@ -731,6 +716,35 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 pStart += colLength[i]; } + for (int32_t i = 0; i < numOfCols; ++i) { + int32_t type = pResultInfo->fields[i].type; + int32_t bytes = pResultInfo->fields[i].bytes; + + if (type == TSDB_DATA_TYPE_NCHAR) { + char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pResultInfo->convertBuf[i] = p; + + SResultColumn* pCol = &pResultInfo->pCol[i]; + for (int32_t j = 0; j < numOfRows; ++j) { + if (pCol->offset[j] != -1) { + pStart = pCol->offset[j] + pCol->pData; + + int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(p)); + ASSERT(len <= bytes); + + varDataSetLen(p, len); + pCol->offset[j] = (p - pResultInfo->convertBuf[i]); + p += (len + VARSTR_HEADER_SIZE); + } + } + + pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; + } + } + return TSDB_CODE_SUCCESS; }