diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index da0a2047f5de9079ec30addc40b162d00e18e0a3..6f229a5d77e8457add84f2adf7bf72fa4a64db11 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2428,7 +2428,7 @@ static int setColumnFilterInfoForTimestamp(SSqlCmd* pCmd, tVariant* pVar) { } tVariantDestroy(pVar); - tVariantCreateB(pVar, &time, 0, TSDB_DATA_TYPE_BIGINT); + tVariantCreateB(pVar, (char*)&time, 0, TSDB_DATA_TYPE_BIGINT); return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 2cf55a287f040cead5404e27c24bdde34e2bc656..f2a8b8bc8d50f4d31cc99f3c454f535ee27adacb 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -210,22 +210,25 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { if (cfg_locale && cfg_charset && cfg_locale->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { char sep = '.'; - char oldLocale[64] = {0}; - strncpy(oldLocale, tsLocale, sizeof(oldLocale) / sizeof(oldLocale[0])); + if (strlen(tsLocale) == 0) { // locale does not set yet + char* defaultLocale = setlocale(LC_CTYPE, ""); + strcpy(tsLocale, defaultLocale); + } + + // set the user specified locale char *locale = setlocale(LC_CTYPE, pStr); if (locale != NULL) { - tscPrint("locale set, prev locale:%s, new locale:%s", oldLocale, locale); + tscPrint("locale set, prev locale:%s, new locale:%s", tsLocale, locale); cfg_locale->cfgStatus = TSDB_CFG_CSTATUS_OPTION; } else { - /* set the user-specified localed failed, use default LC_CTYPE as - * current locale */ - locale = setlocale(LC_CTYPE, oldLocale); - tscPrint("failed to set locale:%s, restore locale:%s", pStr, oldLocale); + /* set the user-specified localed failed, use default LC_CTYPE as current locale */ + locale = setlocale(LC_CTYPE, tsLocale); + tscPrint("failed to set locale:%s, current locale:%s", pStr, tsLocale); } - strncpy(tsLocale, locale, sizeof(tsLocale) / sizeof(tsLocale[0])); + strncpy(tsLocale, locale, tListLen(tsLocale)); char *charset = strrchr(tsLocale, sep); if (charset != NULL) { @@ -234,15 +237,21 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { charset = taosCharsetReplace(charset); if (taosValidateEncodec(charset)) { - tscPrint("charset changed from %s to %s", tsCharset, charset); + if (strlen(tsCharset) == 0) { + tscPrint("charset set:%s", charset); + } else { + tscPrint("charset changed from %s to %s", tsCharset, charset); + } + strncpy(tsCharset, charset, tListLen(tsCharset)); cfg_charset->cfgStatus = TSDB_CFG_CSTATUS_OPTION; - ; + } else { tscPrint("charset:%s is not valid in locale, charset remains:%s", charset, tsCharset); } + free(charset); - } else { + } else { // it may be windows system tscPrint("charset remains:%s", tsCharset); } } else { @@ -256,22 +265,24 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { /* set charset will override the value of charset, assigned during system locale changed */ pStr = (char *)arg; - char oldCharset[64] = {0}; - strncpy(oldCharset, tsCharset, tListLen(oldCharset)); - size_t len = strlen(pStr); if (len == 0 || len > TSDB_LOCALE_LEN) { - tscPrint("Invalid charset:%s, failed to set charset, current charset:%s", pStr, oldCharset); + tscPrint("failed to set charset:%s", pStr); return -1; } if (cfg_charset && cfg_charset->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { if (taosValidateEncodec(pStr)) { - tscPrint("charset changed from %s to %s", tsCharset, pStr); + if (strlen(tsCharset) == 0) { + tscPrint("charset is set:%s", pStr); + } else { + tscPrint("charset changed from %s to %s", tsCharset, pStr); + } + strncpy(tsCharset, pStr, tListLen(tsCharset)); cfg_charset->cfgStatus = TSDB_CFG_CSTATUS_OPTION; } else { - tscPrint("charset:%s is not valid, charset remains:%s", pStr, tsCharset); + tscPrint("charset:%s not valid", pStr); } } else { tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg_charset->option, pStr, diff --git a/src/util/src/tsystem.c b/src/util/src/tsystem.c index b6d5250f12c42ea9ebffe24d3c83d429ed25ba7c..c0764552d82db40453e7806e2a342548a1f416be 100644 --- a/src/util/src/tsystem.c +++ b/src/util/src/tsystem.c @@ -229,30 +229,24 @@ char *taosCharsetReplace(char *charsetstr) { return strdup(charsetstr); } +/* + * POSIX format locale string: + * (Language Strings)_(Country/Region Strings).(code_page) + * + * example: en_US.UTF-8, zh_CN.GB18030, zh_CN.UTF-8, + * + * if user does not specify the locale in taos.cfg the program use default LC_CTYPE as system locale. + * + * In case of some CentOS systems, their default locale is "en_US.utf8", which is not valid code_page + * for libiconv that is employed to convert string in this system. This program will automatically use + * UTF-8 instead as the charset. + * + * In case of windows client, the locale string is not valid POSIX format, user needs to set the + * correct code_page for libiconv. Usually, the code_page of windows system with simple chinese is + * CP936, CP437 for English charset. + * + */ void taosGetSystemLocale() { // get and set default locale - /* - * POSIX format locale string: - * (Language Strings)_(Country/Region Strings).(code_page) - * - * example: en_US.UTF-8, zh_CN.GB18030, zh_CN.UTF-8, - * - * if user does not specify the locale in taos.cfg - * the program use default LC_CTYPE as system locale. - * - * In case of some CentOS systems, their default locale is "en_US.utf8", which - * is not - * valid code_page for libiconv that is employed to convert string in this - * system. - * User needs to specify the locale explicitly - * in config file in the correct format: en_US.UTF-8 - * - * In case of windows client, the locale string is not legal POSIX format, - * user needs to - * set the correct code_page for libiconv. Usually, the code_page of windows - * system - * with simple chinese is CP936, CP437 for English locale. - * - */ char sep = '.'; char *locale = NULL; @@ -262,7 +256,7 @@ void taosGetSystemLocale() { // get and set default locale if (locale == NULL) { pError("can't get locale from system"); } else { - strncpy(tsLocale, locale, sizeof(tsLocale) / sizeof(tsLocale[0])); + strncpy(tsLocale, locale, tListLen(tsLocale)); pPrint("locale not configured, set to system default:%s", tsLocale); } } @@ -275,7 +269,7 @@ void taosGetSystemLocale() { // get and set default locale str++; char *revisedCharset = taosCharsetReplace(str); - strncpy(tsCharset, revisedCharset, sizeof(tsCharset) / sizeof(tsCharset[0])); + strncpy(tsCharset, revisedCharset, tListLen(tsCharset)); free(revisedCharset); pPrint("charset not configured, set to system default:%s", tsCharset);