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,10 +3260,13 @@ 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;
infos[iInfo].bytes /*bind->buffer_length*/); }
(void)memcpy(&value.val, val,
/*(uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow,*/
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

@ -48,15 +48,15 @@ static char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision);
static int64_t shellDumpResultToFile(const char *fname, TAOS_RES *tres); static int64_t shellDumpResultToFile(const char *fname, TAOS_RES *tres);
static void shellPrintNChar(const char *str, int32_t length, int32_t width); static void shellPrintNChar(const char *str, int32_t length, int32_t width);
static void shellPrintGeometry(const unsigned char *str, int32_t length, int32_t width); static void shellPrintGeometry(const unsigned char *str, int32_t length, int32_t width);
static void shellVerticalPrintResult(TAOS_RES *tres, tsDumpInfo* dump_info); static void shellVerticalPrintResult(TAOS_RES *tres, tsDumpInfo *dump_info);
static void shellHorizontalPrintResult(TAOS_RES *tres, tsDumpInfo* dump_info); static void shellHorizontalPrintResult(TAOS_RES *tres, tsDumpInfo *dump_info);
static int64_t shellDumpResult(TAOS_RES *tres, char *fname, int32_t *error_no, bool vertical, const char *sql); static int64_t shellDumpResult(TAOS_RES *tres, char *fname, int32_t *error_no, bool vertical, const char *sql);
static void shellReadHistory(); static void shellReadHistory();
static void shellWriteHistory(); static void shellWriteHistory();
static void shellPrintError(TAOS_RES *tres, int64_t st); static void shellPrintError(TAOS_RES *tres, int64_t st);
static bool shellIsCommentLine(char *line); static bool shellIsCommentLine(char *line);
static void shellSourceFile(const char *file); static void shellSourceFile(const char *file);
static bool shellGetGrantInfo(char* buf); static bool shellGetGrantInfo(char *buf);
static void shellCleanup(void *arg); static void shellCleanup(void *arg);
static void *shellCancelHandler(void *arg); static void *shellCancelHandler(void *arg);
@ -165,12 +165,12 @@ int32_t shellRunCommand(char *command, bool recordHistory) {
// add help or help; // add help or help;
if (strncasecmp(command, "help", 4) == 0) { if (strncasecmp(command, "help", 4) == 0) {
if(command[4] == ';' || command[4] == ' ' || command[4] == 0) { if (command[4] == ';' || command[4] == ' ' || command[4] == 0) {
showHelp(); showHelp();
return 0; return 0;
} }
} }
if (recordHistory) shellRecordCommandToHistory(command); if (recordHistory) shellRecordCommandToHistory(command);
char quote = 0, *cmd = command; char quote = 0, *cmd = command;
@ -197,19 +197,18 @@ 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;
} }
size_t len = strlen(pstr); size_t len = strlen(pstr);
if(len < 4) { if (len < 4) {
return NULL; return NULL;
} }
char * p = (char *)pstr + len - 2; char *p = (char *)pstr + len - 2;
if (strcmp(p, "\\G") == 0 ){ if (strcmp(p, "\\G") == 0) {
return p; return p;
} }
@ -285,10 +284,11 @@ void shellRunSingleCommandImp(char *command) {
et = taosGetTimestampUs(); et = taosGetTimestampUs();
if (error_no == 0) { if (error_no == 0) {
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 {
@ -366,10 +366,10 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
return; return;
} }
char quotationStr[2] ={'"', 0}; char quotationStr[2] = {'"', 0};
int32_t width; int32_t width;
int n = 0; int n = 0;
#define LENGTH 64 #define LENGTH 64
char buf[LENGTH] = {0}; char buf[LENGTH] = {0};
switch (field->type) { switch (field->type) {
@ -431,8 +431,8 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_JSON: { case TSDB_DATA_TYPE_JSON: {
int32_t bufIndex = 0; int32_t bufIndex = 0;
char* tmp = (char*)taosMemoryCalloc(length * 2 + 1, 1); char *tmp = (char *)taosMemoryCalloc(length * 2 + 1, 1);
if(tmp == NULL) break; if (tmp == NULL) break;
for (int32_t i = 0; i < length; i++) { for (int32_t i = 0; i < length; i++) {
tmp[bufIndex] = val[i]; tmp[bufIndex] = val[i];
bufIndex++; bufIndex++;
@ -446,19 +446,19 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr); taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr);
taosMemoryFree(tmp); taosMemoryFree(tmp);
} break; } break;
case TSDB_DATA_TYPE_VARBINARY:{ case TSDB_DATA_TYPE_VARBINARY: {
void* tmp = NULL; void *tmp = NULL;
uint32_t size = 0; uint32_t size = 0;
if(taosAscii2Hex(val, length, &tmp, &size) < 0){ if (taosAscii2Hex(val, length, &tmp, &size) < 0) {
break; break;
} }
taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr); taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr);
taosMemoryFree(tmp); taosMemoryFree(tmp);
break; break;
} }
case TSDB_DATA_TYPE_GEOMETRY:{ case TSDB_DATA_TYPE_GEOMETRY: {
char* tmp = (char*)taosMemoryCalloc(length * 2 + 1, 1); char *tmp = (char *)taosMemoryCalloc(length * 2 + 1, 1);
if(tmp == NULL) break; if (tmp == NULL) break;
shellDumpHexValue(tmp, val, length); shellDumpHexValue(tmp, val, length);
taosFprintfFile(pFile, "%s", buf); taosFprintfFile(pFile, "%s", buf);
taosMemoryFree(tmp); taosMemoryFree(tmp);
@ -635,12 +635,12 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
return; return;
} }
int n = 0; int n = 0;
#define LENGTH 64 #define LENGTH 64
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));
@ -680,7 +680,7 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
break; break;
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
if (tsEnableScience) { if (tsEnableScience) {
snprintf(buf, LENGTH, "%*.15e", width,GET_DOUBLE_VAL(val)); snprintf(buf, LENGTH, "%*.15e", width, GET_DOUBLE_VAL(val));
printf("%s", buf); printf("%s", buf);
} else { } else {
n = snprintf(buf, LENGTH, "%*.15f", width, GET_DOUBLE_VAL(val)); n = snprintf(buf, LENGTH, "%*.15f", width, GET_DOUBLE_VAL(val));
@ -691,10 +691,10 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
} }
} }
break; break;
case TSDB_DATA_TYPE_VARBINARY:{ case TSDB_DATA_TYPE_VARBINARY: {
void* data = NULL; void *data = NULL;
uint32_t size = 0; uint32_t size = 0;
if(taosAscii2Hex(val, length, &data, &size) < 0){ if (taosAscii2Hex(val, length, &data, &size) < 0) {
break; break;
} }
shellPrintNChar(data, size, width); shellPrintNChar(data, size, width);
@ -867,7 +867,7 @@ int32_t shellCalcColWidth(TAOS_FIELD *field, int32_t precision) {
} else { } else {
return TMAX(field->bytes + 2, width); return TMAX(field->bytes + 2, width);
} }
case TSDB_DATA_TYPE_VARBINARY:{ case TSDB_DATA_TYPE_VARBINARY: {
int32_t bytes = field->bytes * 2 + 2; int32_t bytes = field->bytes * 2 + 2;
if (bytes > shell.args.displayWidth) { if (bytes > shell.args.displayWidth) {
return TMAX(shell.args.displayWidth, width); return TMAX(shell.args.displayWidth, width);
@ -1121,8 +1121,9 @@ 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;
@ -1156,7 +1157,7 @@ void shellSourceFile(const char *file) {
taosCloseFile(&pFile); taosCloseFile(&pFile);
} }
bool shellGetGrantInfo(char* buf) { bool shellGetGrantInfo(char *buf) {
bool community = true; bool community = true;
char sinfo[256] = {0}; char sinfo[256] = {0};
tstrncpy(sinfo, taos_get_server_info(shell.conn), sizeof(sinfo)); tstrncpy(sinfo, taos_get_server_info(shell.conn), sizeof(sinfo));
@ -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);
@ -1325,13 +1325,13 @@ int32_t shellExecute() {
shellSetConn(shell.conn, runOnce); shellSetConn(shell.conn, runOnce);
shellReadHistory(); shellReadHistory();
if(shell.args.is_bi_mode) { if (shell.args.is_bi_mode) {
// need set bi mode // need set bi mode
printf("Set BI mode is true.\n"); printf("Set BI mode is true.\n");
#ifndef WEBSOCKET #ifndef WEBSOCKET
taos_set_conn_mode(shell.conn, TAOS_CONN_MODE_BI, 1); taos_set_conn_mode(shell.conn, TAOS_CONN_MODE_BI, 1);
#endif #endif
} }
if (runOnce) { if (runOnce) {
if (pArgs->commands != NULL) { if (pArgs->commands != NULL) {
@ -1374,22 +1374,22 @@ int32_t shellExecute() {
#ifdef WEBSOCKET #ifdef WEBSOCKET
if (!shell.args.restful && !shell.args.cloud) { if (!shell.args.restful && !shell.args.cloud) {
#endif #endif
char* buf = taosMemoryMalloc(512); char *buf = taosMemoryMalloc(512);
bool community = shellGetGrantInfo(buf); bool community = shellGetGrantInfo(buf);
#ifndef WINDOWS #ifndef WINDOWS
printfIntroduction(community); printfIntroduction(community);
#else #else
#ifndef WEBSOCKET #ifndef WEBSOCKET
if(community) { if (community) {
showAD(false); showAD(false);
} }
#endif
#endif #endif
// printf version #endif
if(!community) { // printf version
printf("%s\n", buf); if (!community) {
} printf("%s\n", buf);
taosMemoryFree(buf); }
taosMemoryFree(buf);
#ifdef WEBSOCKET #ifdef WEBSOCKET
} }
@ -1408,7 +1408,7 @@ taosMemoryFree(buf);
if (community) { if (community) {
showAD(true); showAD(true);
} }
#endif #endif
taosThreadJoin(spid, NULL); taosThreadJoin(spid, NULL);