From cbc4b2bbee6fb038287da0b92e95b220e143b34f Mon Sep 17 00:00:00 2001 From: zyyang Date: Mon, 23 Aug 2021 14:48:39 +0800 Subject: [PATCH] [TD-5949]: add setConfig test case and change jdbc's version --- cmake/install.inc | 2 +- src/connector/jdbc/CMakeLists.txt | 2 +- src/connector/jdbc/deploy-pom.xml | 2 +- src/connector/jdbc/pom.xml | 2 +- .../java/com/taosdata/jdbc/TSDBDriver.java | 3 - .../com/taosdata/jdbc/TSDBJNIConnector.java | 16 +++--- .../jdbc/SetConfigurationInJNITest.java | 55 ++++++++++++++++++- 7 files changed, 65 insertions(+), 17 deletions(-) diff --git a/cmake/install.inc b/cmake/install.inc index e9ad240a79..7ea2ba8da0 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/connector/jdbc/CMakeLists.txt b/src/connector/jdbc/CMakeLists.txt index e432dac1ce..1e5cede714 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 ef57198e78..7caf46848d 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 fbeeeb56d3..d79be3ac86 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 521a88b128..33d2560bcc 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 b427f296e9..79c540597c 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) { @@ -159,6 +151,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 */ 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 index 9b8ed386d4..fe51383a04 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SetConfigurationInJNITest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SetConfigurationInJNITest.java @@ -2,10 +2,61 @@ 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 { + TSDBJNIConnector.initImp(null); + TSDBJNIConnector.setOptions(0, null); + TSDBJNIConnector.setOptions(1, null); + TSDBJNIConnector.setOptions(2, null); + String tsCharset = TSDBJNIConnector.getTsCharset(); + System.out.println(tsCharset); + + 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 test() { + public void testMaxSQLLength() { } -} +} \ No newline at end of file -- GitLab