[td-14428] return correct length for both nchar and varchar type.
This commit is contained in:
parent
7b3e488173
commit
fb36f5e24e
|
@ -153,6 +153,7 @@ typedef struct SReqResultInfo {
|
||||||
const char* pRspMsg;
|
const char* pRspMsg;
|
||||||
const char* pData;
|
const char* pData;
|
||||||
TAOS_FIELD* fields;
|
TAOS_FIELD* fields;
|
||||||
|
TAOS_FIELD* userFields; // the fields info that return to user
|
||||||
uint32_t numOfCols;
|
uint32_t numOfCols;
|
||||||
int32_t* length;
|
int32_t* length;
|
||||||
char** convertBuf;
|
char** convertBuf;
|
||||||
|
|
|
@ -169,6 +169,7 @@ static void doFreeReqResultInfo(SReqResultInfo *pResInfo) {
|
||||||
taosMemoryFreeClear(pResInfo->row);
|
taosMemoryFreeClear(pResInfo->row);
|
||||||
taosMemoryFreeClear(pResInfo->pCol);
|
taosMemoryFreeClear(pResInfo->pCol);
|
||||||
taosMemoryFreeClear(pResInfo->fields);
|
taosMemoryFreeClear(pResInfo->fields);
|
||||||
|
taosMemoryFreeClear(pResInfo->userFields);
|
||||||
|
|
||||||
if (pResInfo->convertBuf != NULL) {
|
if (pResInfo->convertBuf != NULL) {
|
||||||
for (int32_t i = 0; i < pResInfo->numOfCols; ++i) {
|
for (int32_t i = 0; i < pResInfo->numOfCols; ++i) {
|
||||||
|
|
|
@ -228,12 +228,24 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
||||||
assert(pSchema != NULL && numOfCols > 0);
|
assert(pSchema != NULL && numOfCols > 0);
|
||||||
|
|
||||||
pResInfo->numOfCols = numOfCols;
|
pResInfo->numOfCols = numOfCols;
|
||||||
pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(pSchema[0]));
|
pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||||
|
pResInfo->userFields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||||
|
|
||||||
for (int32_t i = 0; i < pResInfo->numOfCols; ++i) {
|
for (int32_t i = 0; i < pResInfo->numOfCols; ++i) {
|
||||||
pResInfo->fields[i].bytes = pSchema[i].bytes;
|
pResInfo->fields[i].bytes = pSchema[i].bytes;
|
||||||
pResInfo->fields[i].type = pSchema[i].type;
|
pResInfo->fields[i].type = pSchema[i].type;
|
||||||
|
|
||||||
|
pResInfo->userFields[i].bytes = pSchema[i].bytes;
|
||||||
|
pResInfo->userFields[i].type = pSchema[i].type;
|
||||||
|
|
||||||
|
if (pSchema[i].type == TSDB_DATA_TYPE_VARCHAR) {
|
||||||
|
pResInfo->userFields[i].bytes -= VARSTR_HEADER_SIZE;
|
||||||
|
} else if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
pResInfo->userFields[i].bytes = (pResInfo->userFields[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
tstrncpy(pResInfo->fields[i].name, pSchema[i].name, tListLen(pResInfo->fields[i].name));
|
tstrncpy(pResInfo->fields[i].name, pSchema[i].name, tListLen(pResInfo->fields[i].name));
|
||||||
|
tstrncpy(pResInfo->userFields[i].name, pSchema[i].name, tListLen(pResInfo->userFields[i].name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SReqResultInfo *pResInfo = &(((SRequestObj *)res)->body.resInfo);
|
SReqResultInfo *pResInfo = &(((SRequestObj *)res)->body.resInfo);
|
||||||
return pResInfo->fields;
|
return pResInfo->userFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
TAOS_RES *taos_query(TAOS *taos, const char *sql) {
|
TAOS_RES *taos_query(TAOS *taos, const char *sql) {
|
||||||
|
|
Loading…
Reference in New Issue