normalize bool's value

This commit is contained in:
Minglei Jin 2024-08-23 09:12:22 +08:00
parent f90ec9d94f
commit 44eb4661dc
3 changed files with 73 additions and 61 deletions

View File

@ -3171,8 +3171,12 @@ int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int3
if (allValue) { if (allValue) {
// optimize (todo) // optimize (todo)
for (int32_t i = 0; i < pBind->num; ++i) { for (int32_t i = 0; i < pBind->num; ++i) {
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE]( uint8_t *val = (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i;
pColData, (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i, TYPE_BYTES[pColData->type]); if (TSDB_DATA_TYPE_BOOL == pColData->type && *val > 1) {
*val = 1;
}
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, val, TYPE_BYTES[pColData->type]);
} }
} else if (allNull) { } else if (allNull) {
// optimize (todo) // optimize (todo)
@ -3186,8 +3190,12 @@ int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int3
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NULL](pColData, NULL, 0); code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NULL](pColData, NULL, 0);
if (code) goto _exit; if (code) goto _exit;
} else { } else {
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE]( uint8_t *val = (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i;
pColData, (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i, TYPE_BYTES[pColData->type]); if (TSDB_DATA_TYPE_BOOL == pColData->type && *val > 1) {
*val = 1;
}
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, val, TYPE_BYTES[pColData->type]);
} }
} }
} }
@ -3252,9 +3260,12 @@ int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorte
*data += length; *data += length;
// value.pData = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow; // value.pData = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow;
} else { } else {
(void)memcpy( uint8_t *val = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bytes * iRow;
&value.val, if (TSDB_DATA_TYPE_BOOL == value.type && *val > 1) {
(uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bytes /*infos[iInfo].bind->buffer_length*/ * iRow, *val = 1;
}
(void)memcpy(&value.val, val,
/*(uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow,*/
infos[iInfo].bytes /*bind->buffer_length*/); infos[iInfo].bytes /*bind->buffer_length*/);
} }
colVal = COL_VAL_VALUE(infos[iInfo].columnId, value); colVal = COL_VAL_VALUE(infos[iInfo].columnId, value);

View File

@ -220,7 +220,8 @@ void veriry_stmt(TAOS* taos) {
is_null[i] = 0; is_null[i] = 0;
v.ts[i] = ts++; v.ts[i] = ts++;
v.b[i] = (int8_t)i % 2; // v.b[i] = (int8_t)i % 2;
v.b[i] = (int8_t)i % 10;
v.v1[i] = (int8_t)i; v.v1[i] = (int8_t)i;
v.v2[i] = (int16_t)(i * 2); v.v2[i] = (int16_t)(i * 2);
v.v4[i] = (int32_t)(i * 4); v.v4[i] = (int32_t)(i * 4);

View File

@ -197,7 +197,6 @@ int32_t shellRunCommand(char *command, bool recordHistory) {
return shellRunSingleCommand(cmd); return shellRunSingleCommand(cmd);
} }
char *strendG(const char *pstr) { char *strendG(const char *pstr) {
if (pstr == NULL) { if (pstr == NULL) {
return NULL; return NULL;
@ -288,7 +287,8 @@ void shellRunSingleCommandImp(char *command) {
printf("Query OK, %" PRId64 " row(s) in set (%.6fs)\r\n", numOfRows, (et - st) / 1E6); printf("Query OK, %" PRId64 " row(s) in set (%.6fs)\r\n", numOfRows, (et - st) / 1E6);
} else { } else {
terrno = error_no; terrno = error_no;
printf("Query interrupted (%s), %"PRId64 " row(s) in set (%.6fs)\r\n", taos_errstr(NULL), numOfRows, (et - st) / 1E6); printf("Query interrupted (%s), %" PRId64 " row(s) in set (%.6fs)\r\n", taos_errstr(NULL), numOfRows,
(et - st) / 1E6);
} }
taos_free_result(pSql); taos_free_result(pSql);
} else { } else {
@ -640,7 +640,7 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
char buf[LENGTH] = {0}; char buf[LENGTH] = {0};
switch (field->type) { switch (field->type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
shellPrintString(((((int32_t)(*((char *)val))) == 1) ? "true" : "false"), width); shellPrintString(((((int32_t)(*((char *)val))) == TSDB_FALSE) ? "false" : "true"), width);
break; break;
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
printf("%*d", width, *((int8_t *)val)); printf("%*d", width, *((int8_t *)val));
@ -1122,7 +1122,8 @@ void shellSourceFile(const char *file) {
char *line = taosMemoryMalloc(TSDB_MAX_ALLOWED_SQL_LEN + 1); char *line = taosMemoryMalloc(TSDB_MAX_ALLOWED_SQL_LEN + 1);
while ((read_len = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) > 0) { while ((read_len = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) > 0) {
if (cmd_len + read_len >= TSDB_MAX_ALLOWED_SQL_LEN) { if (cmd_len + read_len >= TSDB_MAX_ALLOWED_SQL_LEN) {
printf("read command line too long over 1M, ignore this line. cmd_len = %d read_len=%d \n", (int32_t)cmd_len, read_len); printf("read command line too long over 1M, ignore this line. cmd_len = %d read_len=%d \n", (int32_t)cmd_len,
read_len);
cmd_len = 0; cmd_len = 0;
memset(line, 0, TSDB_MAX_ALLOWED_SQL_LEN + 1); memset(line, 0, TSDB_MAX_ALLOWED_SQL_LEN + 1);
continue; continue;
@ -1207,8 +1208,7 @@ bool shellGetGrantInfo(char* buf) {
sprintf(buf, "Server is %s, %s and will never expire.\r\n", serverVersion, sinfo); sprintf(buf, "Server is %s, %s and will never expire.\r\n", serverVersion, sinfo);
} else { } else {
community = false; community = false;
sprintf(buf, "Server is %s, %s and will expire at %s.\r\n", serverVersion, sinfo, sprintf(buf, "Server is %s, %s and will expire at %s.\r\n", serverVersion, sinfo, expiretime);
expiretime);
} }
taos_free_result(tres); taos_free_result(tres);