osString
This commit is contained in:
parent
dca6b21e88
commit
78e9bb95ac
|
@ -65,7 +65,10 @@ typedef enum { M2C = 0, C2M } ConvType;
|
||||||
|
|
||||||
char *tstrdup(const char *src);
|
char *tstrdup(const char *src);
|
||||||
int32_t taosUcs4len(TdUcs4 *ucs4);
|
int32_t taosUcs4len(TdUcs4 *ucs4);
|
||||||
int64_t taosStr2int64(const char *str);
|
int32_t taosStr2int64(const char *str, int64_t *val);
|
||||||
|
int32_t taosStr2int16(const char *str, int16_t *val);
|
||||||
|
int32_t taosStr2int32(const char *str, int32_t *val);
|
||||||
|
int32_t taosStr2int8(const char *str, int8_t *val);
|
||||||
|
|
||||||
int32_t taosConvInit(void);
|
int32_t taosConvInit(void);
|
||||||
void taosConvDestroy();
|
void taosConvDestroy();
|
||||||
|
|
|
@ -298,6 +298,7 @@ void tmq_conf_destroy(tmq_conf_t* conf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value) {
|
tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value) {
|
||||||
|
int32_t code = 0;
|
||||||
if (conf == NULL || key == NULL || value == NULL) {
|
if (conf == NULL || key == NULL || value == NULL) {
|
||||||
return TMQ_CONF_INVALID;
|
return TMQ_CONF_INVALID;
|
||||||
}
|
}
|
||||||
|
@ -324,8 +325,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(key, "auto.commit.interval.ms") == 0) {
|
if (strcasecmp(key, "auto.commit.interval.ms") == 0) {
|
||||||
int64_t tmp = taosStr2int64(value);
|
int64_t tmp;
|
||||||
if (tmp < 0 || EINVAL == errno || ERANGE == errno) {
|
code = taosStr2int64(value, &tmp);
|
||||||
|
if (tmp < 0 || code != 0) {
|
||||||
return TMQ_CONF_INVALID;
|
return TMQ_CONF_INVALID;
|
||||||
}
|
}
|
||||||
conf->autoCommitInterval = (tmp > INT32_MAX ? INT32_MAX : tmp);
|
conf->autoCommitInterval = (tmp > INT32_MAX ? INT32_MAX : tmp);
|
||||||
|
@ -333,8 +335,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(key, "session.timeout.ms") == 0) {
|
if (strcasecmp(key, "session.timeout.ms") == 0) {
|
||||||
int64_t tmp = taosStr2int64(value);
|
int64_t tmp;
|
||||||
if (tmp < 6000 || tmp > 1800000) {
|
code = taosStr2int64(value, &tmp);
|
||||||
|
if (tmp < 6000 || tmp > 1800000 || code != 0) {
|
||||||
return TMQ_CONF_INVALID;
|
return TMQ_CONF_INVALID;
|
||||||
}
|
}
|
||||||
conf->sessionTimeoutMs = tmp;
|
conf->sessionTimeoutMs = tmp;
|
||||||
|
@ -342,8 +345,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(key, "heartbeat.interval.ms") == 0) {
|
if (strcasecmp(key, "heartbeat.interval.ms") == 0) {
|
||||||
int64_t tmp = taosStr2int64(value);
|
int64_t tmp;
|
||||||
if (tmp < 1000 || tmp >= conf->sessionTimeoutMs) {
|
code = taosStr2int64(value, &tmp);
|
||||||
|
if (tmp < 1000 || tmp >= conf->sessionTimeoutMs || code != 0) {
|
||||||
return TMQ_CONF_INVALID;
|
return TMQ_CONF_INVALID;
|
||||||
}
|
}
|
||||||
conf->heartBeatIntervalMs = tmp;
|
conf->heartBeatIntervalMs = tmp;
|
||||||
|
@ -351,8 +355,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(key, "max.poll.interval.ms") == 0) {
|
if (strcasecmp(key, "max.poll.interval.ms") == 0) {
|
||||||
int64_t tmp = taosStr2int64(value);
|
int32_t tmp;
|
||||||
if (tmp < 1000 || tmp > INT32_MAX) {
|
code = taosStr2int32(value, &tmp);
|
||||||
|
if (tmp < 1000 || code != 0) {
|
||||||
return TMQ_CONF_INVALID;
|
return TMQ_CONF_INVALID;
|
||||||
}
|
}
|
||||||
conf->maxPollIntervalMs = tmp;
|
conf->maxPollIntervalMs = tmp;
|
||||||
|
@ -414,8 +419,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(key, "td.connect.port") == 0) {
|
if (strcasecmp(key, "td.connect.port") == 0) {
|
||||||
int64_t tmp = taosStr2int64(value);
|
int64_t tmp;
|
||||||
if (tmp <= 0 || tmp > 65535) {
|
code = taosStr2int64(value, &tmp);
|
||||||
|
if (tmp <= 0 || tmp > 65535 || code != 0) {
|
||||||
return TMQ_CONF_INVALID;
|
return TMQ_CONF_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,7 +441,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strcasecmp(key, "msg.consume.excluded") == 0) {
|
if (strcasecmp(key, "msg.consume.excluded") == 0) {
|
||||||
conf->sourceExcluded = (taosStr2int64(value) != 0) ? TD_REQ_FROM_TAOX : 0;
|
int64_t tmp;
|
||||||
|
code = taosStr2int64(value, &tmp);
|
||||||
|
conf->sourceExcluded = (0 == code && tmp != 0) ? TD_REQ_FROM_TAOX : 0;
|
||||||
return TMQ_CONF_OK;
|
return TMQ_CONF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +452,9 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(key, "msg.enable.batchmeta") == 0) {
|
if (strcasecmp(key, "msg.enable.batchmeta") == 0) {
|
||||||
conf->enableBatchMeta = (taosStr2int64(value) != 0) ? true : false;
|
int64_t tmp;
|
||||||
|
code = taosStr2int64(value, &tmp);
|
||||||
|
conf->enableBatchMeta = (0 == code && tmp != 0) ? true : false;
|
||||||
return TMQ_CONF_OK;
|
return TMQ_CONF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,36 +132,52 @@ TExeCond tCompare(__compar_fn_t func, int8_t cmptype, void* a, void* b, int8_t d
|
||||||
}
|
}
|
||||||
#if 1
|
#if 1
|
||||||
if (dtype == TSDB_DATA_TYPE_TIMESTAMP) {
|
if (dtype == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
int64_t va = taosStr2int64(a);
|
int64_t va;
|
||||||
int64_t vb = taosStr2int64(b);
|
taosStr2int64(a, &va);
|
||||||
|
int64_t vb;
|
||||||
|
taosStr2int64(b, &vb);
|
||||||
return tDoCompare(func, cmptype, &va, &vb);
|
return tDoCompare(func, cmptype, &va, &vb);
|
||||||
} else if (dtype == TSDB_DATA_TYPE_BOOL || dtype == TSDB_DATA_TYPE_UTINYINT) {
|
} else if (dtype == TSDB_DATA_TYPE_BOOL || dtype == TSDB_DATA_TYPE_UTINYINT) {
|
||||||
uint8_t va = taosStr2int64(a);
|
uint8_t va;
|
||||||
uint8_t vb = taosStr2int64(b);
|
taosStr2int8(a, &va);
|
||||||
|
uint8_t vb;
|
||||||
|
taosStr2int8(b, &vb);
|
||||||
return tDoCompare(func, cmptype, &va, &vb);
|
return tDoCompare(func, cmptype, &va, &vb);
|
||||||
} else if (dtype == TSDB_DATA_TYPE_TINYINT) {
|
} else if (dtype == TSDB_DATA_TYPE_TINYINT) {
|
||||||
int8_t va = taosStr2int64(a);
|
int8_t va;
|
||||||
int8_t vb = taosStr2int64(b);
|
taosStr2int8(a, &va);
|
||||||
|
int8_t vb;
|
||||||
|
taosStr2int8(b, &vb);
|
||||||
return tDoCompare(func, cmptype, &va, &vb);
|
return tDoCompare(func, cmptype, &va, &vb);
|
||||||
} else if (dtype == TSDB_DATA_TYPE_SMALLINT) {
|
} else if (dtype == TSDB_DATA_TYPE_SMALLINT) {
|
||||||
int16_t va = taosStr2int64(a);
|
int16_t va;
|
||||||
int16_t vb = taosStr2int64(b);
|
taosStr2int16(a, &va);
|
||||||
|
int16_t vb;
|
||||||
|
taosStr2int16(b, &vb);
|
||||||
return tDoCompare(func, cmptype, &va, &vb);
|
return tDoCompare(func, cmptype, &va, &vb);
|
||||||
} else if (dtype == TSDB_DATA_TYPE_USMALLINT) {
|
} else if (dtype == TSDB_DATA_TYPE_USMALLINT) {
|
||||||
uint16_t va = taosStr2int64(a);
|
uint16_t va;
|
||||||
uint16_t vb = taosStr2int64(b);
|
taosStr2int16(a, &va);
|
||||||
|
uint16_t vb;
|
||||||
|
taosStr2int16(b, &vb);
|
||||||
return tDoCompare(func, cmptype, &va, &vb);
|
return tDoCompare(func, cmptype, &va, &vb);
|
||||||
} else if (dtype == TSDB_DATA_TYPE_INT) {
|
} else if (dtype == TSDB_DATA_TYPE_INT) {
|
||||||
int32_t va = taosStr2int64(a);
|
int32_t va;
|
||||||
int32_t vb = taosStr2int64(b);
|
taosStr2int32(a, &va);
|
||||||
|
int32_t vb;
|
||||||
|
taosStr2int32(b, &vb);
|
||||||
return tDoCompare(func, cmptype, &va, &vb);
|
return tDoCompare(func, cmptype, &va, &vb);
|
||||||
} else if (dtype == TSDB_DATA_TYPE_UINT) {
|
} else if (dtype == TSDB_DATA_TYPE_UINT) {
|
||||||
uint32_t va = taosStr2int64(a);
|
uint32_t va;
|
||||||
uint32_t vb = taosStr2int64(b);
|
taosStr2int32(a, &va);
|
||||||
|
uint32_t vb;
|
||||||
|
taosStr2int32(b, &vb);
|
||||||
return tDoCompare(func, cmptype, &va, &vb);
|
return tDoCompare(func, cmptype, &va, &vb);
|
||||||
} else if (dtype == TSDB_DATA_TYPE_BIGINT) {
|
} else if (dtype == TSDB_DATA_TYPE_BIGINT) {
|
||||||
int64_t va = taosStr2int64(a);
|
int64_t va;
|
||||||
int64_t vb = taosStr2int64(b);
|
taosStr2int64(a, &va);
|
||||||
|
int64_t vb;
|
||||||
|
taosStr2int64(b, &vb);
|
||||||
return tDoCompare(func, cmptype, &va, &vb);
|
return tDoCompare(func, cmptype, &va, &vb);
|
||||||
} else if (dtype == TSDB_DATA_TYPE_UBIGINT) {
|
} else if (dtype == TSDB_DATA_TYPE_UBIGINT) {
|
||||||
uint64_t va, vb;
|
uint64_t va, vb;
|
||||||
|
|
|
@ -328,13 +328,17 @@ TEST_F(UtilEnv, testFill) {
|
||||||
int64_t val = i;
|
int64_t val = i;
|
||||||
char buf[65] = {0};
|
char buf[65] = {0};
|
||||||
idxInt2str(val, buf, 1);
|
idxInt2str(val, buf, 1);
|
||||||
EXPECT_EQ(val, taosStr2int64(buf));
|
int64_t ret = 0;
|
||||||
|
taosStr2int64(buf, &ret);
|
||||||
|
EXPECT_EQ(val, ret);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 1000000; i++) {
|
for (int i = 0; i < 1000000; i++) {
|
||||||
int64_t val = 0 - i;
|
int64_t val = 0 - i;
|
||||||
char buf[65] = {0};
|
char buf[65] = {0};
|
||||||
idxInt2str(val, buf, -1);
|
idxInt2str(val, buf, -1);
|
||||||
EXPECT_EQ(val, taosStr2int64(buf));
|
int64_t ret = 0;
|
||||||
|
taosStr2int64(buf, &ret);
|
||||||
|
EXPECT_EQ(val, ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TEST_F(UtilEnv, TempResult) {
|
TEST_F(UtilEnv, TempResult) {
|
||||||
|
|
|
@ -143,13 +143,13 @@ static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchem
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)(p), kv->length * TSDB_NCHAR_SIZE, &output)) {
|
if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)(p), kv->length * TSDB_NCHAR_SIZE, &output)) {
|
||||||
if (errno == E2BIG) {
|
if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
|
||||||
taosMemoryFree(p);
|
taosMemoryFree(p);
|
||||||
code = generateSyntaxErrMsg(msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
|
code = generateSyntaxErrMsg(msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
char buf[512] = {0};
|
char buf[512] = {0};
|
||||||
(void)snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno));
|
(void)snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno));
|
||||||
taosMemoryFree(p);
|
taosMemoryFree(p);
|
||||||
code = buildSyntaxErrMsg(msg, buf, kv->value);
|
code = buildSyntaxErrMsg(msg, buf, kv->value);
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -257,7 +257,7 @@ int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, size, &len)) {
|
if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, size, &len)) {
|
||||||
if (errno == E2BIG) {
|
if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
|
||||||
taosMemoryFree(pUcs4);
|
taosMemoryFree(pUcs4);
|
||||||
ret = TSDB_CODE_PAR_VALUE_TOO_LONG;
|
ret = TSDB_CODE_PAR_VALUE_TOO_LONG;
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -404,14 +404,14 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, pColSchema->bytes - VARSTR_HEADER_SIZE, &len)) {
|
if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, pColSchema->bytes - VARSTR_HEADER_SIZE, &len)) {
|
||||||
if (errno == E2BIG) {
|
if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
|
||||||
uError("sml bind taosMbsToUcs4 error, kv length:%d, bytes:%d, kv->value:%s", (int)kv->length,
|
uError("sml bind taosMbsToUcs4 error, kv length:%d, bytes:%d, kv->value:%s", (int)kv->length,
|
||||||
pColSchema->bytes, kv->value);
|
pColSchema->bytes, kv->value);
|
||||||
(void)buildInvalidOperationMsg(&pBuf, "value too long");
|
(void)buildInvalidOperationMsg(&pBuf, "value too long");
|
||||||
ret = TSDB_CODE_PAR_VALUE_TOO_LONG;
|
ret = TSDB_CODE_PAR_VALUE_TOO_LONG;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
ret = buildInvalidOperationMsg(&pBuf, strerror(errno));
|
ret = buildInvalidOperationMsg(&pBuf, strerror(terrno));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
pVal->value.pData = pUcs4;
|
pVal->value.pData = pUcs4;
|
||||||
|
|
|
@ -682,12 +682,12 @@ static int32_t parseTagToken(const char** end, SToken* pToken, SSchema* pSchema,
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)(p), realLen, &output)) {
|
if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)(p), realLen, &output)) {
|
||||||
if (errno == E2BIG) {
|
if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
|
||||||
taosMemoryFree(p);
|
taosMemoryFree(p);
|
||||||
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
||||||
}
|
}
|
||||||
char buf[512] = {0};
|
char buf[512] = {0};
|
||||||
snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno));
|
snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno));
|
||||||
taosMemoryFree(p);
|
taosMemoryFree(p);
|
||||||
return buildSyntaxErrMsg(pMsgBuf, buf, pToken->z);
|
return buildSyntaxErrMsg(pMsgBuf, buf, pToken->z);
|
||||||
}
|
}
|
||||||
|
@ -1616,11 +1616,11 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
|
||||||
}
|
}
|
||||||
if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)pUcs4, realLen, &len)) {
|
if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)pUcs4, realLen, &len)) {
|
||||||
taosMemoryFree(pUcs4);
|
taosMemoryFree(pUcs4);
|
||||||
if (errno == E2BIG) {
|
if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
||||||
}
|
}
|
||||||
char buf[512] = {0};
|
char buf[512] = {0};
|
||||||
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
snprintf(buf, tListLen(buf), "%s", strerror(terrno));
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, buf, pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, buf, pToken->z);
|
||||||
}
|
}
|
||||||
pVal->value.pData = pUcs4;
|
pVal->value.pData = pUcs4;
|
||||||
|
|
|
@ -194,13 +194,13 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) {
|
if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) {
|
||||||
if (errno == E2BIG) {
|
if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
|
||||||
taosMemoryFree(p);
|
taosMemoryFree(p);
|
||||||
code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
|
code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
char buf[512] = {0};
|
char buf[512] = {0};
|
||||||
snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno));
|
snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno));
|
||||||
taosMemoryFree(p);
|
taosMemoryFree(p);
|
||||||
code = buildSyntaxErrMsg(&pBuf, buf, bind[c].buffer);
|
code = buildSyntaxErrMsg(&pBuf, buf, bind[c].buffer);
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -274,11 +274,11 @@ int32_t convertStmtNcharCol(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_MULTI_BIND*
|
||||||
|
|
||||||
if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i],
|
if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i],
|
||||||
(TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) {
|
(TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) {
|
||||||
if (errno == E2BIG) {
|
if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
|
||||||
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
||||||
}
|
}
|
||||||
char buf[512] = {0};
|
char buf[512] = {0};
|
||||||
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
snprintf(buf, tListLen(buf), "%s", strerror(terrno));
|
||||||
return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
|
return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,13 +534,13 @@ int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const c
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) {
|
if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) {
|
||||||
if (errno == E2BIG) {
|
if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
|
||||||
taosMemoryFree(p);
|
taosMemoryFree(p);
|
||||||
code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
|
code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
char buf[512] = {0};
|
char buf[512] = {0};
|
||||||
snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno));
|
snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno));
|
||||||
taosMemoryFree(p);
|
taosMemoryFree(p);
|
||||||
code = buildSyntaxErrMsg(&pBuf, buf, bind[c].buffer);
|
code = buildSyntaxErrMsg(&pBuf, buf, bind[c].buffer);
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -610,11 +610,11 @@ static int32_t convertStmtStbNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output)) {
|
if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output)) {
|
||||||
if (errno == E2BIG) {
|
if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
|
||||||
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
||||||
}
|
}
|
||||||
char buf[512] = {0};
|
char buf[512] = {0};
|
||||||
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
snprintf(buf, tListLen(buf), "%s", strerror(terrno));
|
||||||
return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
|
return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,11 +740,11 @@ static int32_t convertStmtNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STM
|
||||||
/*if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i],
|
/*if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i],
|
||||||
(TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) {*/
|
(TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) {*/
|
||||||
if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output)) {
|
if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output)) {
|
||||||
if (errno == E2BIG) {
|
if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
|
||||||
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
||||||
}
|
}
|
||||||
char buf[512] = {0};
|
char buf[512] = {0};
|
||||||
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
snprintf(buf, tListLen(buf), "%s", strerror(terrno));
|
||||||
return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
|
return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -469,7 +469,7 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi
|
||||||
val.type = TSDB_DATA_TYPE_NCHAR;
|
val.type = TSDB_DATA_TYPE_NCHAR;
|
||||||
if (valLen > 0 && !taosMbsToUcs4(jsonValue, valLen, (TdUcs4*)tmp, (int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen)) {
|
if (valLen > 0 && !taosMbsToUcs4(jsonValue, valLen, (TdUcs4*)tmp, (int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen)) {
|
||||||
uError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue,
|
uError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue,
|
||||||
strerror(errno));
|
strerror(terrno));
|
||||||
retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue);
|
retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue);
|
||||||
taosMemoryFree(tmp);
|
taosMemoryFree(tmp);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
|
@ -198,7 +198,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) {
|
||||||
int32_t output = 0;
|
int32_t output = 0;
|
||||||
if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes,
|
if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes,
|
||||||
&output)) {
|
&output)) {
|
||||||
return errno;
|
return terrno;
|
||||||
}
|
}
|
||||||
varDataSetLen(pVal->datum.p, output);
|
varDataSetLen(pVal->datum.p, output);
|
||||||
pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE;
|
pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE;
|
||||||
|
@ -486,7 +486,7 @@ static int32_t setValueByBindParam2(SValueNode* pVal, TAOS_STMT2_BIND* pParam) {
|
||||||
int32_t output = 0;
|
int32_t output = 0;
|
||||||
if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes,
|
if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes,
|
||||||
&output)) {
|
&output)) {
|
||||||
return errno;
|
return terrno;
|
||||||
}
|
}
|
||||||
varDataSetLen(pVal->datum.p, output);
|
varDataSetLen(pVal->datum.p, output);
|
||||||
pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE;
|
pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE;
|
||||||
|
|
|
@ -38,6 +38,8 @@ char *tstrdup(const char *str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
|
||||||
|
// No errors are expected to occur
|
||||||
char *strsep(char **stringp, const char *delim) {
|
char *strsep(char **stringp, const char *delim) {
|
||||||
char *s;
|
char *s;
|
||||||
const char *spanp;
|
const char *spanp;
|
||||||
|
@ -84,9 +86,57 @@ char *stpncpy(char *dest, const char *src, int n) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int64_t taosStr2int64(const char *str) {
|
int32_t taosStr2int64(const char *str, int64_t *val) {
|
||||||
char *endptr = NULL;
|
if (str == NULL || val == NULL) {
|
||||||
return strtoll(str, &endptr, 10);
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
}
|
||||||
|
char *endptr = NULL;
|
||||||
|
int64_t ret = strtoll(str, &endptr, 10);
|
||||||
|
if (errno == ERANGE && (ret == LLONG_MAX || ret == LLONG_MIN)) {
|
||||||
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
|
} else {
|
||||||
|
*val = ret;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t taosStr2int16(const char *str, int16_t *val) {
|
||||||
|
int64_t tmp = 0;
|
||||||
|
int32_t code = taosStr2int64(str, &tmp);
|
||||||
|
if (code) {
|
||||||
|
return code;
|
||||||
|
} else if (tmp > INT16_MAX || tmp < INT16_MIN) {
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
} else {
|
||||||
|
*val = (int16_t)tmp;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t taosStr2int32(const char *str, int32_t *val) {
|
||||||
|
int64_t tmp = 0;
|
||||||
|
int32_t code = taosStr2int64(str, &tmp);
|
||||||
|
if (code) {
|
||||||
|
return code;
|
||||||
|
} else if (tmp > INT32_MAX || tmp < INT32_MIN) {
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
} else {
|
||||||
|
*val = (int32_t)tmp;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t taosStr2int8(const char *str, int8_t *val) {
|
||||||
|
int64_t tmp = 0;
|
||||||
|
int32_t code = taosStr2int64(str, &tmp);
|
||||||
|
if (code) {
|
||||||
|
return code;
|
||||||
|
} else if (tmp > INT8_MAX || tmp < INT8_MIN) {
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
} else {
|
||||||
|
*val = (int8_t)tmp;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) {
|
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) {
|
||||||
|
@ -253,12 +303,12 @@ void taosReleaseConv(int32_t idx, iconv_t conv, ConvType type) {
|
||||||
bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len) {
|
bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len) {
|
||||||
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV
|
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV
|
||||||
printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n");
|
printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n");
|
||||||
return -1;
|
terrno = TSDB_CODE_APP_ERROR;
|
||||||
|
return false;
|
||||||
#else
|
#else
|
||||||
(void)memset(ucs4, 0, ucs4_max_len);
|
(void)memset(ucs4, 0, ucs4_max_len);
|
||||||
|
|
||||||
int32_t idx = -1;
|
int32_t idx = -1;
|
||||||
int32_t code = 0;
|
|
||||||
iconv_t conv = taosAcquireConv(&idx, M2C);
|
iconv_t conv = taosAcquireConv(&idx, M2C);
|
||||||
if ((iconv_t)-1 == conv || (iconv_t)0 == conv) {
|
if ((iconv_t)-1 == conv || (iconv_t)0 == conv) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -267,9 +317,8 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4
|
||||||
size_t ucs4_input_len = mbsLength;
|
size_t ucs4_input_len = mbsLength;
|
||||||
size_t outLeft = ucs4_max_len;
|
size_t outLeft = ucs4_max_len;
|
||||||
if (iconv(conv, (char **)&mbs, &ucs4_input_len, (char **)&ucs4, &outLeft) == -1) {
|
if (iconv(conv, (char **)&mbs, &ucs4_input_len, (char **)&ucs4, &outLeft) == -1) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosReleaseConv(idx, conv, M2C);
|
taosReleaseConv(idx, conv, M2C);
|
||||||
terrno = code;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,6 +326,8 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4
|
||||||
if (len != NULL) {
|
if (len != NULL) {
|
||||||
*len = (int32_t)(ucs4_max_len - outLeft);
|
*len = (int32_t)(ucs4_max_len - outLeft);
|
||||||
if (*len < 0) {
|
if (*len < 0) {
|
||||||
|
// can not happen
|
||||||
|
terrno = TSDB_CODE_APP_ERROR;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue