This commit is contained in:
hjxilinx 2020-05-07 18:26:19 +08:00
parent 7ef4b3ab13
commit 309076cd03
5 changed files with 19 additions and 16 deletions

View File

@ -327,15 +327,16 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
*(uint32_t*) payload = TSDB_DATA_NCHAR_NULL; *(uint32_t*) payload = TSDB_DATA_NCHAR_NULL;
} else { } else {
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
int32_t resLen = -1; size_t wcharLength = 0;
if (!taosMbsToUcs4(pToken->z, pToken->n, payload + VARSTR_HEADER_SIZE, pSchema->bytes - VARSTR_HEADER_SIZE, &resLen)) { if (!taosMbsToUcs4(pToken->z, pToken->n, payload + VARSTR_HEADER_SIZE, pSchema->bytes - VARSTR_HEADER_SIZE,
char buf[512] = {0}; &wcharLength)) {
snprintf(buf, 512, "%s", strerror(errno));
char buf[512] = {0};
snprintf(buf, tListLen(buf), "%s", strerror(errno));
return tscInvalidSQLErrMsg(msg, buf, pToken->z); return tscInvalidSQLErrMsg(msg, buf, pToken->z);
} }
*(uint16_t*)payload = (uint16_t) (resLen * TSDB_NCHAR_SIZE); *(uint16_t*) payload = (uint16_t) (wcharLength);
} }
break; break;

View File

@ -40,6 +40,10 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void *param, void *handle,
void taosTmrCleanUp(void *handle); void taosTmrCleanUp(void *handle);
int32_t taosInitTimer(void (*callback)(int), int32_t ms);
void taosUninitTimer();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -141,10 +141,7 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP
*/ */
void getTmpfilePath(const char *fileNamePattern, char *dstPath); void getTmpfilePath(const char *fileNamePattern, char *dstPath);
int32_t taosInitTimer(void (*callback)(int), int32_t ms); bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, size_t* len);
void taosUninitTimer();
bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t* len);
int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes); int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes);

View File

@ -490,25 +490,26 @@ bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
#endif #endif
} }
bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t* len) { bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, size_t* len) {
memset(ucs4, 0, ucs4_max_len); memset(ucs4, 0, ucs4_max_len);
#ifdef USE_LIBICONV #ifdef USE_LIBICONV
iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset); iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
size_t ucs4_input_len = mbs_len; size_t ucs4_input_len = mbsLength;
size_t outLen = ucs4_max_len; size_t outLeft = ucs4_max_len;
if (iconv(cd, &mbs, &ucs4_input_len, &ucs4, &outLen) == -1) { if (iconv(cd, &mbs, &ucs4_input_len, &ucs4, &outLeft) == -1) {
iconv_close(cd); iconv_close(cd);
return false; return false;
} }
iconv_close(cd); iconv_close(cd);
if (len != NULL) { if (len != NULL) {
*len = outLen; *len = ucs4_max_len - outLeft;
} }
return true; return true;
#else #else
mbstate_t state = {0}; mbstate_t state = {0};
int32_t len = mbsnrtowcs((wchar_t *) ucs4, (const char **) &mbs, mbs_len, ucs4_max_len / 4, &state); int32_t len = mbsnrtowcs((wchar_t *) ucs4, (const char **) &mbs, mbsLength, ucs4_max_len / 4, &state);
return len >= 0; return len >= 0;
#endif #endif
} }

View File

@ -688,7 +688,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
} }
if (row[i] == 0) { if (row[i] == 0) {
strcpy(value, "null"); strcpy(value, TSDB_DATA_NULL_STR);
continue; continue;
} }