diff --git a/cmake/install.inc b/cmake/install.inc index e9ad240a793b9736edbe5769c6af12276e13a1a6..7ea2ba8da0af79c15378cda956a330b357804c5a 100755 --- a/cmake/install.inc +++ b/cmake/install.inc @@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS) #INSTALL(TARGETS taos RUNTIME DESTINATION driver) #INSTALL(TARGETS shell RUNTIME DESTINATION .) IF (TD_MVN_INSTALLED) - INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.34-dist.jar DESTINATION connector/jdbc) + INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.35-dist.jar DESTINATION connector/jdbc) ENDIF () ELSEIF (TD_DARWIN) SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh") diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index ae47adc36e95bec19e8684bf1ef4a2c19b2b4f94..7811f39e33529476d361881f4291189530e4c510 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -443,7 +443,7 @@ static int taos_set_config_imp(const char *config){ static bool setConfFlag = false; if (setConfFlag) { tscError("already set config"); - return -1; + return 0; } cJSON *root = cJSON_Parse(config); if (root == NULL) { @@ -451,18 +451,22 @@ static int taos_set_config_imp(const char *config){ return -1; } + int ret = 0; int size = cJSON_GetArraySize(root); for(int i = 0; i < size; i++){ cJSON *item = cJSON_GetArrayItem(root, i); if (!item) { tscError("failed to read index:%d", i); + ret = -2; continue; } - taosReadConfigOption(item->string, item->valuestring, NULL, NULL); + if(!taosReadConfigOption(item->string, item->valuestring, NULL, NULL)){ + ret = -2; + } } taosPrintGlobalCfg(); setConfFlag = true; - return 0; + return ret; } int taos_set_config(const char *config){ diff --git a/src/connector/jdbc/CMakeLists.txt b/src/connector/jdbc/CMakeLists.txt index e432dac1cea593b371a173f334e5313236091ab3..1e5cede714820f29defe3c6b458b2daf467bc4d2 100644 --- a/src/connector/jdbc/CMakeLists.txt +++ b/src/connector/jdbc/CMakeLists.txt @@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED) ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME} POST_BUILD COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.34-dist.jar ${LIBRARY_OUTPUT_PATH} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.35-dist.jar ${LIBRARY_OUTPUT_PATH} COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml COMMENT "build jdbc driver") ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME}) diff --git a/src/connector/jdbc/deploy-pom.xml b/src/connector/jdbc/deploy-pom.xml index ef57198e78d2268faba526d5506b0dc384f5766f..7caf46848d18c4491cdea1ab50df31d8d2d26daf 100755 --- a/src/connector/jdbc/deploy-pom.xml +++ b/src/connector/jdbc/deploy-pom.xml @@ -5,7 +5,7 @@ com.taosdata.jdbc taos-jdbcdriver - 2.0.34 + 2.0.35 jar JDBCDriver diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index fbeeeb56d30357294663a5ebf64608c57e066a7d..d79be3ac86ffd2504c13fa4c4acf6b4f336ccfb3 100644 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.taosdata.jdbc taos-jdbcdriver - 2.0.34 + 2.0.35 jar JDBCDriver https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java index 521a88b128ff930510bf00cdcb6a12cbc3211742..33d2560bcca28116db49a283f02d566bda5e3852 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java @@ -118,9 +118,6 @@ public class TSDBDriver extends AbstractDriver { } public Connection connect(String url, Properties info) throws SQLException { - if (url == null) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET); - if (!acceptsURL(url)) return null; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index c634fe2e9503ff19afae85f285d921f330562612..e5676a44925172b357c1b31ebaa31a3f78e7bbbc 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -38,14 +38,6 @@ public class TSDBJNIConnector { System.loadLibrary("taos"); } - public boolean isClosed() { - return this.taos == TSDBConstants.JNI_NULL_POINTER; - } - - public boolean isResultsetClosed() { - return this.isResultsetClosed; - } - public static void init(String configDir, String locale, String charset, String timezone) throws SQLWarning { synchronized (isInitialized) { if (!isInitialized) { @@ -71,6 +63,8 @@ public class TSDBJNIConnector { public static native String getTsCharset(); + public static native int setConfig(String config); + public boolean connect(String host, int port, String dbName, String user, String password) throws SQLException { if (this.taos != TSDBConstants.JNI_NULL_POINTER) { closeConnection(); @@ -159,6 +153,14 @@ public class TSDBJNIConnector { private native long isUpdateQueryImp(long connection, long pSql); + public boolean isClosed() { + return this.taos == TSDBConstants.JNI_NULL_POINTER; + } + + public boolean isResultsetClosed() { + return this.isResultsetClosed; + } + /** * Free result set operation from C to release result set pointer by JNI */ @@ -357,4 +359,6 @@ public class TSDBJNIConnector { } private native int insertLinesImp(String[] lines, long conn); + + } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SetConfigurationInJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SetConfigurationInJNITest.java new file mode 100644 index 0000000000000000000000000000000000000000..c083716277b6d805a2bb554beb523bd8396ebdd8 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SetConfigurationInJNITest.java @@ -0,0 +1,66 @@ +package com.taosdata.jdbc; + +import org.junit.Test; + +import java.sql.SQLException; +import java.util.Arrays; + +import static org.junit.Assert.*; + + +public class SetConfigurationInJNITest { + + private String host = "127.0.0.1"; + private String dbname = "test_jni"; + private long maxSQLLength = 1024000; + private String debugFlagJSON = "{ \"debugFlag\": 135}"; + private String maxSqlLengthJSON = "{ \"maxSQLLength\": " + maxSQLLength + "}"; + + @Test + public void testDebugFlag() { + try { + // init + TSDBJNIConnector.initImp(null); + TSDBJNIConnector.setOptions(0, null); + TSDBJNIConnector.setOptions(1, null); + TSDBJNIConnector.setOptions(2, null); + String tsCharset = TSDBJNIConnector.getTsCharset(); + assertEquals("", tsCharset); + + TSDBJNIConnector.setConfig(debugFlagJSON); + + // connect + TSDBJNIConnector jniConnector = new TSDBJNIConnector(); + boolean connected = jniConnector.connect(host, 0, null, "root", "taosdata"); + assertTrue(connected); + + String[] setupSqls = { + "drop database if exists " + dbname, + "create database if not exists " + dbname, + "use " + dbname, + "create table weather(ts timestamp, f1 int) tags(loc nchar(10))", + "insert into t1 using weather tags('beijing') values(now, 1)", + "drop database if exists " + dbname + }; + + Arrays.asList(setupSqls).forEach(sql -> { + try { + long setupSql = jniConnector.executeQuery(sql); + if (jniConnector.isUpdateQuery(setupSql)) { + jniConnector.freeResultSet(setupSql); + } + } catch (SQLException e) { + e.printStackTrace(); + } + }); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Test + public void testMaxSQLLength() { + + } +} \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java index 88ff5d3a811e17aaabbeb0a451fbff010307ab6d..b63c88a875142c29722209382c6139d890f1176c 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.sql.SQLException; -import java.sql.SQLWarning; import java.util.ArrayList; import java.util.List; @@ -19,7 +18,6 @@ public class TSDBJNIConnectorTest { @Test public void test() { try { - try { //change sleepSeconds when debugging with attach to process to find PID int sleepSeconds = -1; @@ -122,8 +120,6 @@ public class TSDBJNIConnectorTest { // close connection connector.closeConnection(); - } catch (SQLWarning throwables) { - throwables.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } @@ -140,11 +136,7 @@ public class TSDBJNIConnectorTest { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0); - } else if (code == TSDBConstants.JNI_FETCH_END) { - return false; - } else { - return true; - } + } else return code != TSDBConstants.JNI_FETCH_END; } } diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h index 3b90bd22b411c8b9d57412cc77415110191b8e24..3c5cdfe08c0a0411d968bb8211cc0d2e691706ec 100644 --- a/src/util/inc/tconfig.h +++ b/src/util/inc/tconfig.h @@ -89,7 +89,7 @@ void taosDumpGlobalCfg(); void taosInitConfigOption(SGlobalCfg cfg); SGlobalCfg * taosGetConfigOption(const char *option); -void taosReadConfigOption(const char *option, char *value, char *value2, char *value3); +bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3); #ifdef __cplusplus } diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index 8923bdeddfbf08773cc02eaccb1f31a013112708..548b3bc4f5aed921ee50cd3ed3629b5b7916f8a9 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -26,6 +26,11 @@ SGlobalCfg tsGlobalConfig[TSDB_CFG_MAX_NUM] = {{0}}; int32_t tsGlobalConfigNum = 0; +#define ATOI_JUDGE if ( !value && strcmp(input_value, "0") != 0) { \ + uError("atoi error, input value:%s",input_value); \ + return false; \ + } + static char *tsGlobalUnit[] = { " ", "(%)", @@ -44,12 +49,14 @@ char *tsCfgStatusStr[] = { "program argument list" }; -static void taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) { +static bool taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) { float value = (float)atof(input_value); + ATOI_JUDGE float *option = (float *)cfg->ptr; if (value < cfg->minValue || value > cfg->maxValue) { uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f", cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); + return false; } else { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { *option = value; @@ -57,16 +64,20 @@ static void taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) { } else { uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value, tsCfgStatusStr[cfg->cfgStatus], *option); + return false; } } + return true; } -static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) { +static bool taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) { double value = atof(input_value); + ATOI_JUDGE double *option = (double *)cfg->ptr; if (value < cfg->minValue || value > cfg->maxValue) { uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f", cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); + return false; } else { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { *option = value; @@ -74,17 +85,21 @@ static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) { } else { uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value, tsCfgStatusStr[cfg->cfgStatus], *option); + return false; } } + return true; } -static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) { +static bool taosReadInt32Config(SGlobalCfg *cfg, char *input_value) { int32_t value = atoi(input_value); + ATOI_JUDGE int32_t *option = (int32_t *)cfg->ptr; if (value < cfg->minValue || value > cfg->maxValue) { uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); + return false; } else { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { *option = value; @@ -92,16 +107,20 @@ static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) { } else { uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, tsCfgStatusStr[cfg->cfgStatus], *option); + return false; } } + return true; } -static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) { +static bool taosReadInt16Config(SGlobalCfg *cfg, char *input_value) { int32_t value = atoi(input_value); + ATOI_JUDGE int16_t *option = (int16_t *)cfg->ptr; if (value < cfg->minValue || value > cfg->maxValue) { uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); + return false; } else { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { *option = (int16_t)value; @@ -109,16 +128,20 @@ static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) { } else { uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, tsCfgStatusStr[cfg->cfgStatus], *option); + return false; } } + return true; } -static void taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) { +static bool taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) { int32_t value = atoi(input_value); + ATOI_JUDGE uint16_t *option = (uint16_t *)cfg->ptr; if (value < cfg->minValue || value > cfg->maxValue) { uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); + return false; } else { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { *option = (uint16_t)value; @@ -126,16 +149,20 @@ static void taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) { } else { uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, tsCfgStatusStr[cfg->cfgStatus], *option); + return false; } } + return true; } -static void taosReadInt8Config(SGlobalCfg *cfg, char *input_value) { +static bool taosReadInt8Config(SGlobalCfg *cfg, char *input_value) { int32_t value = atoi(input_value); + ATOI_JUDGE int8_t *option = (int8_t *)cfg->ptr; if (value < cfg->minValue || value > cfg->maxValue) { uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); + return false; } else { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { *option = (int8_t)value; @@ -143,8 +170,10 @@ static void taosReadInt8Config(SGlobalCfg *cfg, char *input_value) { } else { uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, tsCfgStatusStr[cfg->cfgStatus], *option); + return false; } } + return true; } static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { @@ -191,12 +220,13 @@ static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { return true; } -static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) { +static bool taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) { uint32_t value = taosInetAddr(input_value); char * option = (char *)cfg->ptr; if (value == INADDR_NONE) { uError("config option:%s, input value:%s, is not a valid ip address, use default value:%s", cfg->option, input_value, option); + return false; } else { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { strncpy(option, input_value, cfg->ptrLength); @@ -204,16 +234,19 @@ static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) { } else { uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, tsCfgStatusStr[cfg->cfgStatus], option); + return false; } } + return true; } -static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) { +static bool taosReadStringConfig(SGlobalCfg *cfg, char *input_value) { int length = (int) strlen(input_value); char *option = (char *)cfg->ptr; if (length <= 0 || length > cfg->ptrLength) { uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", cfg->option, input_value, cfg->ptrLength, option); + return false; } else { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { strncpy(option, input_value, cfg->ptrLength); @@ -221,8 +254,10 @@ static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) { } else { uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, tsCfgStatusStr[cfg->cfgStatus], option); + return false; } } + return true; } static void taosReadLogOption(char *option, char *value) { @@ -258,7 +293,7 @@ SGlobalCfg *taosGetConfigOption(const char *option) { return NULL; } -void taosReadConfigOption(const char *option, char *value, char *value2, char *value3) { +bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3) { for (int i = 0; i < tsGlobalConfigNum; ++i) { SGlobalCfg *cfg = tsGlobalConfig + i; if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue; @@ -266,43 +301,35 @@ void taosReadConfigOption(const char *option, char *value, char *value2, char *v switch (cfg->valType) { case TAOS_CFG_VTYPE_INT8: - taosReadInt8Config(cfg, value); - break; + return taosReadInt8Config(cfg, value); case TAOS_CFG_VTYPE_INT16: - taosReadInt16Config(cfg, value); - break; + return taosReadInt16Config(cfg, value); case TAOS_CFG_VTYPE_INT32: - taosReadInt32Config(cfg, value); - break; + return taosReadInt32Config(cfg, value); case TAOS_CFG_VTYPE_UINT16: - taosReadUInt16Config(cfg, value); - break; + return taosReadUInt16Config(cfg, value); case TAOS_CFG_VTYPE_FLOAT: - taosReadFloatConfig(cfg, value); - break; + return taosReadFloatConfig(cfg, value); case TAOS_CFG_VTYPE_DOUBLE: - taosReadDoubleConfig(cfg, value); - break; + return taosReadDoubleConfig(cfg, value); case TAOS_CFG_VTYPE_STRING: - taosReadStringConfig(cfg, value); - break; + return taosReadStringConfig(cfg, value); case TAOS_CFG_VTYPE_IPSTR: - taosReadIpStrConfig(cfg, value); - break; + return taosReadIpStrConfig(cfg, value); case TAOS_CFG_VTYPE_DIRECTORY: - taosReadDirectoryConfig(cfg, value); - break; + return taosReadDirectoryConfig(cfg, value); case TAOS_CFG_VTYPE_DATA_DIRCTORY: if (taosReadDirectoryConfig(cfg, value)) { - taosReadDataDirCfg(value, value2, value3); + taosReadDataDirCfg(value, value2, value3); + return true; } - break; + return false; default: uError("config option:%s, input value:%s, can't be recognized", option, value); - break; + return false; } - break; } + return false; } void taosInitConfigOption(SGlobalCfg cfg) {