From e4a450fa6927733382fcdc518acd890999c26229 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 9 Apr 2024 19:28:19 +0800 Subject: [PATCH 1/2] enh: insert nchar by sql --- source/libs/parser/src/parInsertSql.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 9a7d0f4839..344a6e7fe2 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -1572,11 +1572,13 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, case TSDB_DATA_TYPE_NCHAR: { // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' int32_t len = 0; - char* pUcs4 = taosMemoryCalloc(1, pSchema->bytes - VARSTR_HEADER_SIZE); + int64_t maxLen = pToken->n << 2; + if (maxLen > pSchema->bytes - VARSTR_HEADER_SIZE) maxLen = pSchema->bytes - VARSTR_HEADER_SIZE; + char* pUcs4 = taosMemoryMalloc(maxLen); if (NULL == pUcs4) { return TSDB_CODE_OUT_OF_MEMORY; } - if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)pUcs4, pSchema->bytes - VARSTR_HEADER_SIZE, &len)) { + if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)pUcs4, maxLen, &len)) { taosMemoryFree(pUcs4); if (errno == E2BIG) { return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); From 706ac9a9e600d7b517e7cec117a8160961695126 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 9 Apr 2024 19:33:32 +0800 Subject: [PATCH 2/2] enh: insert nchar by sql --- source/libs/parser/src/parInsertSql.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 344a6e7fe2..afdd6089d2 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -1572,13 +1572,13 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, case TSDB_DATA_TYPE_NCHAR: { // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' int32_t len = 0; - int64_t maxLen = pToken->n << 2; - if (maxLen > pSchema->bytes - VARSTR_HEADER_SIZE) maxLen = pSchema->bytes - VARSTR_HEADER_SIZE; - char* pUcs4 = taosMemoryMalloc(maxLen); + int64_t realLen = pToken->n << 2; + if (realLen > pSchema->bytes - VARSTR_HEADER_SIZE) realLen = pSchema->bytes - VARSTR_HEADER_SIZE; + char* pUcs4 = taosMemoryMalloc(realLen); if (NULL == pUcs4) { return TSDB_CODE_OUT_OF_MEMORY; } - if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)pUcs4, maxLen, &len)) { + if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)pUcs4, realLen, &len)) { taosMemoryFree(pUcs4); if (errno == E2BIG) { return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);