From bee71f5f42de8bbc9f775e1359871fa61d53c58d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 28 Mar 2022 15:38:58 +0800 Subject: [PATCH] [td-13039] support nchar in taos_fetch_block. --- source/client/src/clientImpl.c | 44 ++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index e8dddb1238..d8017a8727 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; } -- GitLab