diff --git a/cmake/install.inc b/cmake/install.inc index a5b01f43cb7e8a302a9cf2d6d7ef48ddb8ed944e..2f0404334c06125e6ee8241ab91b22064ab20b89 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.17-dist.jar DESTINATION connector/jdbc) + INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.18-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/documentation20/webdocs/markdowndocs/connector-java-ch.md b/documentation20/webdocs/markdowndocs/connector-java-ch.md index b8390e7af50569b62f031c5a3af3020d43b6f98a..3d067ad206e56c5b886f869b67eff5e0b80cd0df 100644 --- a/documentation20/webdocs/markdowndocs/connector-java-ch.md +++ b/documentation20/webdocs/markdowndocs/connector-java-ch.md @@ -2,7 +2,7 @@ TDengine 提供了遵循 JDBC 标准(3.0)API 规范的 `taos-jdbcdriver` 实现,可在 maven 的中央仓库 [Sonatype Repository][1] 搜索下载。 -`taos-jdbcdriver` 的实现包括 2 种形式: JDBC-JNI 和 JDBC-RESTful(taos-jdbcdriver-2.0.17 开始支持 JDBC-RESTful)。 JDBC-JNI 通过调用客户端 libtaos.so(或 taos.dll )的本地方法实现, JDBC-RESTful 则在内部封装了 RESTful 接口实现。 +`taos-jdbcdriver` 的实现包括 2 种形式: JDBC-JNI 和 JDBC-RESTful(taos-jdbcdriver-2.0.18 开始支持 JDBC-RESTful)。 JDBC-JNI 通过调用客户端 libtaos.so(或 taos.dll )的本地方法实现, JDBC-RESTful 则在内部封装了 RESTful 接口实现。 ![tdengine-connector](../assets/tdengine-jdbc-connector.png) @@ -67,7 +67,7 @@ maven 项目中使用如下 pom.xml 配置即可: com.taosdata.jdbc taos-jdbcdriver - 2.0.17 + 2.0.18 ``` diff --git a/src/connector/jdbc/CMakeLists.txt b/src/connector/jdbc/CMakeLists.txt index b64161e2e4fd6fc00abb659118cfdcd50dfcf0a8..59b09c8695d59c1fd0584f73a7e4be1eb1ab1c0b 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.17-dist.jar ${LIBRARY_OUTPUT_PATH} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.18-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 1f03c3c6fe5e1d5f1d7d12a0df7babb6edb789f1..34b0a3c6d37530ad01600a455d426c1606613c23 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.17 + 2.0.18 jar JDBCDriver diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 1fb2c695243e12f8195c20e4724bb24c84980926..4756ac555fa3b32f1e261b3376d811f5e24bcc70 100755 --- 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.17 + 2.0.18 jar JDBCDriver https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java index da297810fe199770e354702f44476492e20491a9..4fb172ceb59040e2f531fd91b83c776cd7d89067 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java @@ -23,6 +23,8 @@ public abstract class TSDBConstants { public static final String DEFAULT_PORT = "6200"; public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!"; public static final String INVALID_VARIABLES = "invalid variables"; + public static final String RESULT_SET_IS_CLOSED = "resultSet is closed."; + public static Map DATATYPE_MAP = null; public static final long JNI_NULL_POINTER = 0L; @@ -75,7 +77,7 @@ public abstract class TSDBConstants { } static { - DATATYPE_MAP = new HashMap(); + DATATYPE_MAP = new HashMap<>(); DATATYPE_MAP.put(1, "BOOL"); DATATYPE_MAP.put(2, "TINYINT"); DATATYPE_MAP.put(3, "SMALLINT"); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java index a8a8b3ca876cf1d2cbc9363b49f0f49da7550b90..d06922c680ccec9c4ec6f53cdbe60cb530deae97 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java @@ -40,1060 +40,1070 @@ import java.util.List; import java.util.Map; public class TSDBResultSet implements ResultSet { - private TSDBJNIConnector jniConnector = null; - - private long resultSetPointer = 0L; - private List columnMetaDataList = new ArrayList(); - - private TSDBResultSetRowData rowData; - private TSDBResultSetBlockData blockData; - - private boolean batchFetch = false; - private boolean lastWasNull = false; - private final int COLUMN_INDEX_START_VALUE = 1; - - private int rowIndex = 0; - - public TSDBJNIConnector getJniConnector() { - return jniConnector; - } - - public void setJniConnector(TSDBJNIConnector jniConnector) { - this.jniConnector = jniConnector; - } - - public long getResultSetPointer() { - return resultSetPointer; - } - - public void setResultSetPointer(long resultSetPointer) { - this.resultSetPointer = resultSetPointer; - } - - public void setBatchFetch(boolean batchFetch) { - this.batchFetch = batchFetch; - } - - public Boolean getBatchFetch() { - return this.batchFetch; - } - - public List getColumnMetaDataList() { - return columnMetaDataList; - } - - public void setColumnMetaDataList(List columnMetaDataList) { - this.columnMetaDataList = columnMetaDataList; - } - - public TSDBResultSetRowData getRowData() { - return rowData; - } - - public void setRowData(TSDBResultSetRowData rowData) { - this.rowData = rowData; - } - - public boolean isLastWasNull() { - return lastWasNull; - } - - public void setLastWasNull(boolean lastWasNull) { - this.lastWasNull = lastWasNull; - } - - public TSDBResultSet() { - - } - - public TSDBResultSet(TSDBJNIConnector connector, long resultSetPointer) throws SQLException { - this.jniConnector = connector; - this.resultSetPointer = resultSetPointer; - int code = this.jniConnector.getSchemaMetaData(this.resultSetPointer, this.columnMetaDataList); - if (code == TSDBConstants.JNI_CONNECTION_NULL) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); - } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); - } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0)); - } - - this.rowData = new TSDBResultSetRowData(this.columnMetaDataList.size()); - this.blockData = new TSDBResultSetBlockData(this.columnMetaDataList, this.columnMetaDataList.size()); - } - - public T unwrap(Class iface) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean next() throws SQLException { - if (this.getBatchFetch()) { - if (this.blockData.forward()) { - return true; - } - - int code = this.jniConnector.fetchBlock(this.resultSetPointer, this.blockData); - this.blockData.reset(); - - if (code == TSDBConstants.JNI_CONNECTION_NULL) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); - } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); - } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0)); - } else if (code == TSDBConstants.JNI_FETCH_END) { - return false; - } - - return true; - } else { - if (rowData != null) { - this.rowData.clear(); - } - - int code = this.jniConnector.fetchRow(this.resultSetPointer, this.rowData); - if (code == TSDBConstants.JNI_CONNECTION_NULL) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); - } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); - } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0)); - } else if (code == TSDBConstants.JNI_FETCH_END) { - return false; - } else { - return true; - } - } - } - - public void close() throws SQLException { - if (this.jniConnector != null) { - int code = this.jniConnector.freeResultSet(this.resultSetPointer); - if (code == TSDBConstants.JNI_CONNECTION_NULL) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); - } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { - throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); - } - } - } - - public boolean wasNull() throws SQLException { - return this.lastWasNull; - } - - public String getString(int columnIndex) throws SQLException { - String res = null; - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - if (!lastWasNull) { - res = this.rowData.getString(colIndex, this.columnMetaDataList.get(colIndex).getColType()); - } - return res; - } else { - return this.blockData.getString(colIndex); - } - } - - public boolean getBoolean(int columnIndex) throws SQLException { - boolean res = false; - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - if (!lastWasNull) { - res = this.rowData.getBoolean(colIndex, this.columnMetaDataList.get(colIndex).getColType()); - } - } else { - return this.blockData.getBoolean(colIndex); - } - - return res; - } - - public byte getByte(int columnIndex) throws SQLException { - byte res = 0; - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - if (!lastWasNull) { - res = (byte) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType()); - } - return res; - } else { - return (byte) this.blockData.getInt(colIndex); - } - } - - public short getShort(int columnIndex) throws SQLException { - short res = 0; - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - if (!lastWasNull) { - res = (short) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType()); - } - return res; - } else { - return (short) this.blockData.getInt(colIndex); - } - } - - public int getInt(int columnIndex) throws SQLException { - int res = 0; - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - if (!lastWasNull) { - res = this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType()); - } - return res; - } else { - return this.blockData.getInt(colIndex); - } - - } - - public long getLong(int columnIndex) throws SQLException { - long res = 0l; - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - if (!lastWasNull) { - res = this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType()); - } - return res; - } else { - return this.blockData.getLong(colIndex); - } - } - - public float getFloat(int columnIndex) throws SQLException { - float res = 0; - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - if (!lastWasNull) { - res = this.rowData.getFloat(colIndex, this.columnMetaDataList.get(colIndex).getColType()); - } - return res; - } else { - return (float) this.blockData.getDouble(colIndex); - } - } - - public double getDouble(int columnIndex) throws SQLException { - double res = 0; - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - if (!lastWasNull) { - res = this.rowData.getDouble(colIndex, this.columnMetaDataList.get(colIndex).getColType()); - } - return res; - } else { - return this.blockData.getDouble(colIndex); - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getBigDecimal(int, int) - * - * @deprecated Use {@code getBigDecimal(int columnIndex)} or {@code - * getBigDecimal(String columnLabel)} - */ - @Deprecated - public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { - return new BigDecimal(getLong(columnIndex)); - } - - public byte[] getBytes(int columnIndex) throws SQLException { - return getString(columnIndex).getBytes(); - } - - public Date getDate(int columnIndex) throws SQLException { - int colIndex = getTrueColumnIndex(columnIndex); - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public Time getTime(int columnIndex) throws SQLException { - int colIndex = getTrueColumnIndex(columnIndex); - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public Timestamp getTimestamp(int columnIndex) throws SQLException { - Timestamp res = null; - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - if (!lastWasNull) { - res = this.rowData.getTimestamp(colIndex); - } - return res; - } else { - return this.blockData.getTimestamp(columnIndex); - } - } - - public InputStream getAsciiStream(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - /* - * (non-Javadoc) - * - * @see java.sql.ResultSet#getUnicodeStream(int) - * - * * @deprecated use getCharacterStream in place of - * getUnicodeStream - */ - @Deprecated - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public InputStream getBinaryStream(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public String getString(String columnLabel) throws SQLException { - return this.getString(this.findColumn(columnLabel)); - } - - public boolean getBoolean(String columnLabel) throws SQLException { - return this.getBoolean(this.findColumn(columnLabel)); - } - - public byte getByte(String columnLabel) throws SQLException { - return this.getByte(this.findColumn(columnLabel)); - } - - public short getShort(String columnLabel) throws SQLException { - return this.getShort(this.findColumn(columnLabel)); - } - - public int getInt(String columnLabel) throws SQLException { - return this.getInt(this.findColumn(columnLabel)); - } - - public long getLong(String columnLabel) throws SQLException { - return this.getLong(this.findColumn(columnLabel)); - } - - public float getFloat(String columnLabel) throws SQLException { - return this.getFloat(this.findColumn(columnLabel)); - } - - public double getDouble(String columnLabel) throws SQLException { - return this.getDouble(this.findColumn(columnLabel)); - } - - /* - * used by spark - */ - @Deprecated - public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { - return this.getBigDecimal(this.findColumn(columnLabel), scale); - } - - public byte[] getBytes(String columnLabel) throws SQLException { - return this.getBytes(this.findColumn(columnLabel)); - } - - public Date getDate(String columnLabel) throws SQLException { - return this.getDate(this.findColumn(columnLabel)); - } - - public Time getTime(String columnLabel) throws SQLException { - return this.getTime(this.findColumn(columnLabel)); - } - - public Timestamp getTimestamp(String columnLabel) throws SQLException { - return this.getTimestamp(this.findColumn(columnLabel)); - } - - public InputStream getAsciiStream(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - @Deprecated - public InputStream getUnicodeStream(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public InputStream getBinaryStream(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public SQLWarning getWarnings() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void clearWarnings() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public String getCursorName() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public ResultSetMetaData getMetaData() throws SQLException { - return new TSDBResultSetMetaData(this.columnMetaDataList); - } - - public Object getObject(int columnIndex) throws SQLException { - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - return this.rowData.get(colIndex); - } else { - return this.blockData.get(colIndex); - } - } - - public Object getObject(String columnLabel) throws SQLException { - return this.getObject(this.findColumn(columnLabel)); - } - - public int findColumn(String columnLabel) throws SQLException { - Iterator colMetaDataIt = this.columnMetaDataList.iterator(); - while (colMetaDataIt.hasNext()) { - ColumnMetaData colMetaData = colMetaDataIt.next(); - if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) { - return colMetaData.getColIndex() + 1; - } - } - throw new SQLException(TSDBConstants.INVALID_VARIABLES); - } - - public Reader getCharacterStream(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public Reader getCharacterStream(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - /* - * used by spark - */ - public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - int colIndex = getTrueColumnIndex(columnIndex); - - if (!this.getBatchFetch()) { - this.lastWasNull = this.rowData.wasNull(colIndex); - return new BigDecimal(this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType())); - } else { - return new BigDecimal(this.blockData.getLong(colIndex)); - } - } - - public BigDecimal getBigDecimal(String columnLabel) throws SQLException { - return this.getBigDecimal(this.findColumn(columnLabel)); - } - - public boolean isBeforeFirst() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean isAfterLast() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean isFirst() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean isLast() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void beforeFirst() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void afterLast() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean first() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean last() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public int getRow() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean absolute(int row) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean relative(int rows) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean previous() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void setFetchDirection(int direction) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public int getFetchDirection() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void setFetchSize(int rows) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public int getFetchSize() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public int getType() throws SQLException { - return ResultSet.TYPE_FORWARD_ONLY; - } - - public int getConcurrency() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean rowUpdated() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean rowInserted() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean rowDeleted() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateNull(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + private TSDBJNIConnector jniConnector = null; - public void updateBoolean(int columnIndex, boolean x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + private long resultSetPointer = 0L; + private List columnMetaDataList = new ArrayList(); + + private TSDBResultSetRowData rowData; + private TSDBResultSetBlockData blockData; + + private boolean batchFetch = false; + private boolean lastWasNull = false; + private final int COLUMN_INDEX_START_VALUE = 1; + + private int rowIndex = 0; + + public TSDBJNIConnector getJniConnector() { + return jniConnector; + } + + public void setJniConnector(TSDBJNIConnector jniConnector) { + this.jniConnector = jniConnector; + } + + public long getResultSetPointer() { + return resultSetPointer; + } + + public void setResultSetPointer(long resultSetPointer) { + this.resultSetPointer = resultSetPointer; + } + + public void setBatchFetch(boolean batchFetch) { + this.batchFetch = batchFetch; + } + + public Boolean getBatchFetch() { + return this.batchFetch; + } + + public List getColumnMetaDataList() { + return columnMetaDataList; + } + + public void setColumnMetaDataList(List columnMetaDataList) { + this.columnMetaDataList = columnMetaDataList; + } + + public TSDBResultSetRowData getRowData() { + return rowData; + } + + public void setRowData(TSDBResultSetRowData rowData) { + this.rowData = rowData; + } + + public boolean isLastWasNull() { + return lastWasNull; + } + + public void setLastWasNull(boolean lastWasNull) { + this.lastWasNull = lastWasNull; + } + + public TSDBResultSet() { + + } + + public TSDBResultSet(TSDBJNIConnector connector, long resultSetPointer) throws SQLException { + this.jniConnector = connector; + this.resultSetPointer = resultSetPointer; + int code = this.jniConnector.getSchemaMetaData(this.resultSetPointer, this.columnMetaDataList); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); + } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0)); + } + + this.rowData = new TSDBResultSetRowData(this.columnMetaDataList.size()); + this.blockData = new TSDBResultSetBlockData(this.columnMetaDataList, this.columnMetaDataList.size()); + } + + public T unwrap(Class iface) throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + + try { + return iface.cast(this); + } catch (ClassCastException cce) { + throw new SQLException("Unable to unwrap to " + iface.toString()); + } + } + + public boolean isWrapperFor(Class iface) throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + + return iface.isInstance(this); + } + + public boolean next() throws SQLException { + if (this.getBatchFetch()) { + if (this.blockData.forward()) { + return true; + } + + int code = this.jniConnector.fetchBlock(this.resultSetPointer, this.blockData); + this.blockData.reset(); + + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); + } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0)); + } else if (code == TSDBConstants.JNI_FETCH_END) { + return false; + } + + return true; + } else { + if (rowData != null) { + this.rowData.clear(); + } + + int code = this.jniConnector.fetchRow(this.resultSetPointer, this.rowData); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); + } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0)); + } else if (code == TSDBConstants.JNI_FETCH_END) { + return false; + } else { + return true; + } + } + } + + public void close() throws SQLException { + if (this.jniConnector != null) { + int code = this.jniConnector.freeResultSet(this.resultSetPointer); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); + } + } + } + + public boolean wasNull() throws SQLException { + return this.lastWasNull; + } + + public String getString(int columnIndex) throws SQLException { + String res = null; + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getString(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } else { + return this.blockData.getString(colIndex); + } + } + + public boolean getBoolean(int columnIndex) throws SQLException { + boolean res = false; + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getBoolean(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + } else { + return this.blockData.getBoolean(colIndex); + } + + return res; + } + + public byte getByte(int columnIndex) throws SQLException { + byte res = 0; + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = (byte) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } else { + return (byte) this.blockData.getInt(colIndex); + } + } + + public short getShort(int columnIndex) throws SQLException { + short res = 0; + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = (short) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } else { + return (short) this.blockData.getInt(colIndex); + } + } + + public int getInt(int columnIndex) throws SQLException { + int res = 0; + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } else { + return this.blockData.getInt(colIndex); + } + + } + + public long getLong(int columnIndex) throws SQLException { + long res = 0l; + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } else { + return this.blockData.getLong(colIndex); + } + } + + public float getFloat(int columnIndex) throws SQLException { + float res = 0; + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getFloat(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } else { + return (float) this.blockData.getDouble(colIndex); + } + } + + public double getDouble(int columnIndex) throws SQLException { + double res = 0; + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getDouble(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } else { + return this.blockData.getDouble(colIndex); + } + } + + /* + * (non-Javadoc) + * + * @see java.sql.ResultSet#getBigDecimal(int, int) + * + * @deprecated Use {@code getBigDecimal(int columnIndex)} or {@code + * getBigDecimal(String columnLabel)} + */ + @Deprecated + public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { + return new BigDecimal(getLong(columnIndex)); + } + + public byte[] getBytes(int columnIndex) throws SQLException { + return getString(columnIndex).getBytes(); + } + + public Date getDate(int columnIndex) throws SQLException { + int colIndex = getTrueColumnIndex(columnIndex); + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Time getTime(int columnIndex) throws SQLException { + int colIndex = getTrueColumnIndex(columnIndex); + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Timestamp getTimestamp(int columnIndex) throws SQLException { + Timestamp res = null; + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getTimestamp(colIndex); + } + return res; + } else { + return this.blockData.getTimestamp(columnIndex); + } + } + + public InputStream getAsciiStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + /* + * (non-Javadoc) + * + * @see java.sql.ResultSet#getUnicodeStream(int) + * + * * @deprecated use getCharacterStream in place of + * getUnicodeStream + */ + @Deprecated + public InputStream getUnicodeStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public InputStream getBinaryStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public String getString(String columnLabel) throws SQLException { + return this.getString(this.findColumn(columnLabel)); + } + + public boolean getBoolean(String columnLabel) throws SQLException { + return this.getBoolean(this.findColumn(columnLabel)); + } + + public byte getByte(String columnLabel) throws SQLException { + return this.getByte(this.findColumn(columnLabel)); + } + + public short getShort(String columnLabel) throws SQLException { + return this.getShort(this.findColumn(columnLabel)); + } + + public int getInt(String columnLabel) throws SQLException { + return this.getInt(this.findColumn(columnLabel)); + } + + public long getLong(String columnLabel) throws SQLException { + return this.getLong(this.findColumn(columnLabel)); + } + + public float getFloat(String columnLabel) throws SQLException { + return this.getFloat(this.findColumn(columnLabel)); + } + + public double getDouble(String columnLabel) throws SQLException { + return this.getDouble(this.findColumn(columnLabel)); + } + + /* + * used by spark + */ + @Deprecated + public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { + return this.getBigDecimal(this.findColumn(columnLabel), scale); + } + + public byte[] getBytes(String columnLabel) throws SQLException { + return this.getBytes(this.findColumn(columnLabel)); + } + + public Date getDate(String columnLabel) throws SQLException { + return this.getDate(this.findColumn(columnLabel)); + } + + public Time getTime(String columnLabel) throws SQLException { + return this.getTime(this.findColumn(columnLabel)); + } + + public Timestamp getTimestamp(String columnLabel) throws SQLException { + return this.getTimestamp(this.findColumn(columnLabel)); + } + + public InputStream getAsciiStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Deprecated + public InputStream getUnicodeStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public InputStream getBinaryStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public SQLWarning getWarnings() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void clearWarnings() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public String getCursorName() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public ResultSetMetaData getMetaData() throws SQLException { + return new TSDBResultSetMetaData(this.columnMetaDataList); + } + + public Object getObject(int columnIndex) throws SQLException { + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + return this.rowData.get(colIndex); + } else { + return this.blockData.get(colIndex); + } + } + + public Object getObject(String columnLabel) throws SQLException { + return this.getObject(this.findColumn(columnLabel)); + } + + public int findColumn(String columnLabel) throws SQLException { + Iterator colMetaDataIt = this.columnMetaDataList.iterator(); + while (colMetaDataIt.hasNext()) { + ColumnMetaData colMetaData = colMetaDataIt.next(); + if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) { + return colMetaData.getColIndex() + 1; + } + } + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + } + + public Reader getCharacterStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Reader getCharacterStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + /* + * used by spark + */ + public BigDecimal getBigDecimal(int columnIndex) throws SQLException { + int colIndex = getTrueColumnIndex(columnIndex); + + if (!this.getBatchFetch()) { + this.lastWasNull = this.rowData.wasNull(colIndex); + return new BigDecimal(this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType())); + } else { + return new BigDecimal(this.blockData.getLong(colIndex)); + } + } + + public BigDecimal getBigDecimal(String columnLabel) throws SQLException { + return this.getBigDecimal(this.findColumn(columnLabel)); + } + + public boolean isBeforeFirst() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isAfterLast() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isFirst() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isLast() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void beforeFirst() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void afterLast() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean first() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean last() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean absolute(int row) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean relative(int rows) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean previous() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setFetchDirection(int direction) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getFetchDirection() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setFetchSize(int rows) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getFetchSize() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getType() throws SQLException { + return ResultSet.TYPE_FORWARD_ONLY; + } + + public int getConcurrency() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean rowUpdated() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean rowInserted() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean rowDeleted() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNull(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateByte(int columnIndex, byte x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateBoolean(int columnIndex, boolean x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateShort(int columnIndex, short x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateByte(int columnIndex, byte x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateInt(int columnIndex, int x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateShort(int columnIndex, short x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateLong(int columnIndex, long x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateInt(int columnIndex, int x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateFloat(int columnIndex, float x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateLong(int columnIndex, long x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateDouble(int columnIndex, double x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateFloat(int columnIndex, float x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateDouble(int columnIndex, double x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateString(int columnIndex, String x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateBytes(int columnIndex, byte[] x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateString(int columnIndex, String x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateDate(int columnIndex, Date x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateBytes(int columnIndex, byte[] x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateTime(int columnIndex, Time x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateDate(int columnIndex, Date x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateTime(int columnIndex, Time x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateObject(int columnIndex, Object x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateNull(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateObject(int columnIndex, Object x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateBoolean(String columnLabel, boolean x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateNull(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateByte(String columnLabel, byte x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateBoolean(String columnLabel, boolean x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateShort(String columnLabel, short x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateByte(String columnLabel, byte x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateInt(String columnLabel, int x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateShort(String columnLabel, short x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateLong(String columnLabel, long x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateInt(String columnLabel, int x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateFloat(String columnLabel, float x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateLong(String columnLabel, long x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateDouble(String columnLabel, double x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateFloat(String columnLabel, float x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateDouble(String columnLabel, double x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateString(String columnLabel, String x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateBytes(String columnLabel, byte[] x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateString(String columnLabel, String x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateDate(String columnLabel, Date x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateBytes(String columnLabel, byte[] x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateTime(String columnLabel, Time x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateDate(String columnLabel, Date x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateTime(String columnLabel, Time x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateObject(String columnLabel, Object x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void insertRow() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateObject(String columnLabel, Object x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateRow() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void insertRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void deleteRow() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void refreshRow() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void deleteRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void cancelRowUpdates() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void refreshRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void moveToInsertRow() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void cancelRowUpdates() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void moveToCurrentRow() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void moveToInsertRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Statement getStatement() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void moveToCurrentRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Object getObject(int columnIndex, Map> map) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Statement getStatement() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Ref getRef(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Object getObject(int columnIndex, Map> map) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Blob getBlob(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Ref getRef(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Clob getClob(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Blob getBlob(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Array getArray(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Clob getClob(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Object getObject(String columnLabel, Map> map) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Array getArray(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Ref getRef(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Object getObject(String columnLabel, Map> map) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Blob getBlob(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Ref getRef(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Clob getClob(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Blob getBlob(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Array getArray(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Clob getClob(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Date getDate(int columnIndex, Calendar cal) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Array getArray(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Date getDate(String columnLabel, Calendar cal) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Time getTime(int columnIndex, Calendar cal) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Date getDate(String columnLabel, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Time getTime(String columnLabel, Calendar cal) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Time getTime(String columnLabel, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public URL getURL(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public URL getURL(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public URL getURL(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateRef(int columnIndex, Ref x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateRef(String columnLabel, Ref x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateBlob(int columnIndex, Blob x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateBlob(String columnLabel, Blob x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateClob(int columnIndex, Clob x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateClob(String columnLabel, Clob x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateArray(int columnIndex, Array x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateArray(String columnLabel, Array x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public RowId getRowId(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public RowId getRowId(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateRowId(int columnIndex, RowId x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateRowId(String columnLabel, RowId x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public int getHoldability() throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public boolean isClosed() throws SQLException { - boolean isClosed = true; - if (jniConnector != null) { - isClosed = jniConnector.isResultsetClosed(); - } - return isClosed; - } - - public void updateNString(int columnIndex, String nString) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateNString(String columnLabel, String nString) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateNClob(int columnIndex, NClob nClob) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateNClob(String columnLabel, NClob nClob) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public NClob getNClob(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public NClob getNClob(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public SQLXML getSQLXML(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public SQLXML getSQLXML(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public String getNString(int columnIndex) throws SQLException { - int colIndex = getTrueColumnIndex(columnIndex); - return (String) rowData.get(colIndex); - } - - public String getNString(String columnLabel) throws SQLException { - return (String) this.getString(columnLabel); - } - - public Reader getNCharacterStream(int columnIndex) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public Reader getNCharacterStream(String columnLabel) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public URL getURL(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateRef(int columnIndex, Ref x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateRef(String columnLabel, Ref x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBlob(int columnIndex, Blob x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBlob(String columnLabel, Blob x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateClob(int columnIndex, Clob x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateClob(String columnLabel, Clob x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateArray(int columnIndex, Array x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateArray(String columnLabel, Array x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public RowId getRowId(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public RowId getRowId(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateRowId(int columnIndex, RowId x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateRowId(String columnLabel, RowId x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getHoldability() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isClosed() throws SQLException { + boolean isClosed = true; + if (jniConnector != null) { + isClosed = jniConnector.isResultsetClosed(); + } + return isClosed; + } + + public void updateNString(int columnIndex, String nString) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNString(String columnLabel, String nString) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNClob(int columnIndex, NClob nClob) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNClob(String columnLabel, NClob nClob) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public NClob getNClob(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public NClob getNClob(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public SQLXML getSQLXML(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public SQLXML getSQLXML(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public String getNString(int columnIndex) throws SQLException { + int colIndex = getTrueColumnIndex(columnIndex); + return (String) rowData.get(colIndex); + } + + public String getNString(String columnLabel) throws SQLException { + return (String) this.getString(columnLabel); + } + + public Reader getNCharacterStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Reader getNCharacterStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateClob(int columnIndex, Reader reader) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateClob(String columnLabel, Reader reader) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateClob(int columnIndex, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateNClob(int columnIndex, Reader reader) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateClob(String columnLabel, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public void updateNClob(String columnLabel, Reader reader) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateNClob(int columnIndex, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public T getObject(int columnIndex, Class type) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public void updateNClob(String columnLabel, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - public T getObject(String columnLabel, Class type) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } + public T getObject(int columnIndex, Class type) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - private int getTrueColumnIndex(int columnIndex) throws SQLException { - if (columnIndex < this.COLUMN_INDEX_START_VALUE) { - throw new SQLException("Column Index out of range, " + columnIndex + " < " + this.COLUMN_INDEX_START_VALUE); - } - - int numOfCols = this.columnMetaDataList.size(); - if (columnIndex > numOfCols) { - throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols); - } + public T getObject(String columnLabel, Class type) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } - return columnIndex - 1; - } + private int getTrueColumnIndex(int columnIndex) throws SQLException { + if (columnIndex < this.COLUMN_INDEX_START_VALUE) { + throw new SQLException("Column Index out of range, " + columnIndex + " < " + this.COLUMN_INDEX_START_VALUE); + } + + int numOfCols = this.columnMetaDataList.size(); + if (columnIndex > numOfCols) { + throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols); + } + + return columnIndex - 1; + } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java index 1aa3d5b3cefe2524f0246b500af6687a79d6b20c..38d3f2b6aa21427647d108038fdd616927221520 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java @@ -15,28 +15,28 @@ import java.util.List; import java.util.Map; public class RestfulResultSet implements ResultSet { - private static final String RESULT_SET_IS_CLOSED = "resultSet is closed."; private volatile boolean isClosed; private int pos = -1; private final String database; private final Statement statement; // data - private ArrayList> resultSet; + private ArrayList> resultSet = new ArrayList<>(); // meta - private ArrayList columnNames; - private ArrayList columns; + private ArrayList columnNames = new ArrayList<>(); + private ArrayList columns = new ArrayList<>(); private RestfulResultSetMetaData metaData; /** - * 由一个result的Json构造结果集,对应执行show databases,show tables等这些语句,返回结果集,但无法获取结果集对应的meta,统一当成String处理 + * 由一个result的Json构造结果集,对应执行show databases, show tables等这些语句,返回结果集,但无法获取结果集对应的meta,统一当成String处理 + * + * @param resultJson: 包含data信息的结果集,有sql返回的结果集 ***/ public RestfulResultSet(String database, Statement statement, JSONObject resultJson) { this.database = database; this.statement = statement; // row data JSONArray data = resultJson.getJSONArray("data"); - resultSet = new ArrayList<>(); int columnIndex = 0; for (; columnIndex < data.size(); columnIndex++) { ArrayList oneRow = new ArrayList<>(); @@ -48,15 +48,13 @@ public class RestfulResultSet implements ResultSet { } // column only names - columnNames = new ArrayList<>(); - columns = new ArrayList<>(); JSONArray head = resultJson.getJSONArray("head"); for (int i = 0; i < head.size(); i++) { String name = head.getString(i); columnNames.add(name); columns.add(new Field(name, "", 0, "")); } - this.metaData = new RestfulResultSetMetaData(this.database, columns); + this.metaData = new RestfulResultSetMetaData(this.database, columns, this); } /** @@ -78,7 +76,7 @@ public class RestfulResultSet implements ResultSet { } } this.columns = newColumns; - this.metaData = new RestfulResultSetMetaData(this.database, this.columns); + this.metaData = new RestfulResultSetMetaData(this.database, this.columns, this); } public Field findField(String columnName, List fieldJsonList) { @@ -91,7 +89,6 @@ public class RestfulResultSet implements ResultSet { } } } - return null; } @@ -112,10 +109,9 @@ public class RestfulResultSet implements ResultSet { @Override public boolean next() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - if (pos < resultSet.size() - 1) { - pos++; + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + pos++; + if (pos <= resultSet.size() - 1) { return true; } return false; @@ -131,37 +127,38 @@ public class RestfulResultSet implements ResultSet { @Override public boolean wasNull() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); return resultSet.isEmpty(); } @Override public String getString(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); if (columnIndex > resultSet.get(pos).size()) { throw new SQLException(TSDBConstants.WrapErrMsg("Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size())); } - return resultSet.get(pos).get(columnIndex - 1).toString(); + + columnIndex = getTrueColumnIndex(columnIndex); + return resultSet.get(pos).get(columnIndex).toString(); } + @Override public boolean getBoolean(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); - String result = getString(columnIndex); - if (!(result.equals("true") || result.equals("false"))) { - throw new SQLException("not boolean value"); - } - return result.equals("true"); + columnIndex = getTrueColumnIndex(columnIndex); + int result = getInt(columnIndex); + return result == 0 ? false : true; } @Override public byte getByte(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -169,40 +166,55 @@ public class RestfulResultSet implements ResultSet { @Override public short getShort(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - return Short.parseShort(getString(columnIndex)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + columnIndex = getTrueColumnIndex(columnIndex); + return Short.parseShort(resultSet.get(pos).get(columnIndex).toString()); } @Override public int getInt(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - return Integer.parseInt(getString(columnIndex)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + columnIndex = getTrueColumnIndex(columnIndex); + return Integer.parseInt(resultSet.get(pos).get(columnIndex).toString()); } @Override public long getLong(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - return Long.parseLong(getString(columnIndex)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + columnIndex = getTrueColumnIndex(columnIndex); + return Long.parseLong(resultSet.get(pos).get(columnIndex).toString()); } @Override public float getFloat(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - return Float.parseFloat(getString(columnIndex)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + columnIndex = getTrueColumnIndex(columnIndex); + return Float.parseFloat(resultSet.get(pos).get(columnIndex).toString()); } @Override public double getDouble(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + + columnIndex = getTrueColumnIndex(columnIndex); + return Double.parseDouble(resultSet.get(pos).get(columnIndex).toString()); + } + + private int getTrueColumnIndex(int columnIndex) throws SQLException { + if (columnIndex < 1) { + throw new SQLException("Column Index out of range, " + columnIndex + " < 1"); + } + + int numOfCols = resultSet.get(pos).size(); + if (columnIndex > numOfCols) { + throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols); + } - return Double.parseDouble(getString(columnIndex)); + return columnIndex - 1; } /*******************************************************************************************************************/ @@ -210,7 +222,7 @@ public class RestfulResultSet implements ResultSet { @Override public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -218,7 +230,7 @@ public class RestfulResultSet implements ResultSet { @Override public byte[] getBytes(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -226,7 +238,7 @@ public class RestfulResultSet implements ResultSet { @Override public Date getDate(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -234,7 +246,7 @@ public class RestfulResultSet implements ResultSet { @Override public Time getTime(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -242,17 +254,18 @@ public class RestfulResultSet implements ResultSet { @Override public Timestamp getTimestamp(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); - String strDate = getString(columnIndex); - strDate = strDate.substring(1, strDate.length() - 1); + columnIndex = getTrueColumnIndex(columnIndex); + String strDate = resultSet.get(pos).get(columnIndex).toString(); +// strDate = strDate.substring(1, strDate.length() - 1); return Timestamp.valueOf(strDate); } @Override public InputStream getAsciiStream(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -260,7 +273,7 @@ public class RestfulResultSet implements ResultSet { @Override public InputStream getUnicodeStream(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -268,17 +281,16 @@ public class RestfulResultSet implements ResultSet { @Override public InputStream getBinaryStream(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } + /*************************************************************************************************************/ + @Override public String getString(String columnLabel) throws SQLException { - if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - return getString(findColumn(columnLabel) + 1); + return getString(findColumn(columnLabel)); } @Override @@ -338,53 +350,44 @@ public class RestfulResultSet implements ResultSet { @Override public Timestamp getTimestamp(String columnLabel) throws SQLException { - if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - return Timestamp.valueOf(getString(findColumn(columnLabel))); + return getTimestamp(findColumn(columnLabel)); } @Override public InputStream getAsciiStream(String columnLabel) throws SQLException { - if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return getAsciiStream(findColumn(columnLabel)); } @Override public InputStream getUnicodeStream(String columnLabel) throws SQLException { - if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return getUnicodeStream(findColumn(columnLabel)); } @Override public InputStream getBinaryStream(String columnLabel) throws SQLException { - if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return getBinaryStream(findColumn(columnLabel)); } + /*************************************************************************************************************/ + @Override public SQLWarning getWarnings() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); return null; } @Override public void clearWarnings() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); return; } @Override public String getCursorName() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -392,7 +395,7 @@ public class RestfulResultSet implements ResultSet { @Override public ResultSetMetaData getMetaData() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); return this.metaData; } @@ -400,7 +403,7 @@ public class RestfulResultSet implements ResultSet { @Override public Object getObject(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -413,15 +416,18 @@ public class RestfulResultSet implements ResultSet { @Override public int findColumn(String columnLabel) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); - return columnNames.indexOf(columnLabel); + int columnIndex = columnNames.indexOf(columnLabel); + if (columnIndex == -1) + throw new SQLException("cannot find Column in resultSet"); + return columnIndex + 1; } @Override public Reader getCharacterStream(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -429,7 +435,7 @@ public class RestfulResultSet implements ResultSet { @Override public Reader getCharacterStream(String columnLabel) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -437,7 +443,7 @@ public class RestfulResultSet implements ResultSet { @Override public BigDecimal getBigDecimal(int columnIndex) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -445,7 +451,7 @@ public class RestfulResultSet implements ResultSet { @Override public BigDecimal getBigDecimal(String columnLabel) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -453,78 +459,132 @@ public class RestfulResultSet implements ResultSet { @Override public boolean isBeforeFirst() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + return this.pos == -1 && this.resultSet.size() != 0; } @Override public boolean isAfterLast() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + + return this.pos >= resultSet.size() && this.resultSet.size() != 0; } @Override public boolean isFirst() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return this.pos == 0; } @Override public boolean isLast() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + if (this.resultSet.size() == 0) + return false; + return this.pos == (this.resultSet.size() - 1); } @Override public void beforeFirst() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + synchronized (this) { + if (this.resultSet.size() > 0) { + this.pos = -1; + } + } } @Override public void afterLast() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + synchronized (this) { + if (this.resultSet.size() > 0) { + this.pos = this.resultSet.size(); + } + } - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean first() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (this.resultSet.size() == 0) + return false; + + synchronized (this) { + this.pos = 0; + } + return true; } @Override public boolean last() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + if (this.resultSet.size() == 0) + return false; + synchronized (this) { + this.pos = this.resultSet.size() - 1; + } + return true; } @Override public int getRow() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + int row; + synchronized (this) { + if (this.pos < 0 || this.pos >= this.resultSet.size()) + return 0; + row = this.pos + 1; + } + return row; } @Override public boolean absolute(int row) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + +// if (this.resultSet.size() == 0) +// return false; +// +// if (row == 0) { +// beforeFirst(); +// return false; +// } else if (row == 1) { +// return first(); +// } else if (row == -1) { +// return last(); +// } else if (row > this.resultSet.size()) { +// afterLast(); +// return false; +// } else { +// if (row < 0) { +// // adjust to reflect after end of result set +// int newRowPosition = this.resultSet.size() + row + 1; +// if (newRowPosition <= 0) { +// beforeFirst(); +// return false; +// } else { +// return absolute(newRowPosition); +// } +// } else { +// row--; // adjust for index difference +// this.pos = row; +// return true; +// } +// } throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -532,7 +592,7 @@ public class RestfulResultSet implements ResultSet { @Override public boolean relative(int rows) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -540,7 +600,7 @@ public class RestfulResultSet implements ResultSet { @Override public boolean previous() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -548,17 +608,18 @@ public class RestfulResultSet implements ResultSet { @Override public void setFetchDirection(int direction) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); - if (direction != ResultSet.FETCH_REVERSE || direction != ResultSet.FETCH_REVERSE || direction != ResultSet.FETCH_UNKNOWN) + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + if ((direction != ResultSet.FETCH_FORWARD) && (direction != ResultSet.FETCH_REVERSE) && (direction != ResultSet.FETCH_UNKNOWN)) throw new SQLException(TSDBConstants.INVALID_VARIABLES); - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (!(getType() == ResultSet.TYPE_FORWARD_ONLY && direction == ResultSet.FETCH_FORWARD)) + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getFetchDirection() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); return ResultSet.FETCH_FORWARD; } @@ -566,17 +627,17 @@ public class RestfulResultSet implements ResultSet { @Override public void setFetchSize(int rows) throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); if (rows < 0) throw new SQLException(TSDBConstants.INVALID_VARIABLES); - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getFetchSize() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); return this.resultSet.size(); } @@ -834,7 +895,7 @@ public class RestfulResultSet implements ResultSet { @Override public Statement getStatement() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); return this.statement; } @@ -992,14 +1053,15 @@ public class RestfulResultSet implements ResultSet { @Override public int getHoldability() throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + return ResultSet.HOLD_CURSORS_OVER_COMMIT; } @Override public boolean isClosed() throws SQLException { - return false; - //TODO: SQLFeature Not Supported -// throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return isClosed; } @Override @@ -1224,11 +1286,21 @@ public class RestfulResultSet implements ResultSet { @Override public T unwrap(Class iface) throws SQLException { - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + + try { + return iface.cast(this); + } catch (ClassCastException cce) { + throw new SQLException("Unable to unwrap to " + iface.toString()); + } } @Override public boolean isWrapperFor(Class iface) throws SQLException { - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED)); + + return iface.isInstance(this); } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java index 1af3088b172f751ef40be5dd92b205949bc009d6..44a02f486b22063cabb8950c21d3a9f55bfc70c8 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java @@ -1,17 +1,22 @@ package com.taosdata.jdbc.rs; +import com.taosdata.jdbc.TSDBConstants; + import java.sql.ResultSetMetaData; import java.sql.SQLException; +import java.sql.Timestamp; import java.util.ArrayList; public class RestfulResultSetMetaData implements ResultSetMetaData { private final String database; private ArrayList fields; + private final RestfulResultSet resultSet; - public RestfulResultSetMetaData(String database, ArrayList fields) { + public RestfulResultSetMetaData(String database, ArrayList fields, RestfulResultSet resultSet) { this.database = database; this.fields = fields; + this.resultSet = resultSet; } @Override @@ -26,13 +31,12 @@ public class RestfulResultSetMetaData implements ResultSetMetaData { @Override public boolean isCaseSensitive(int column) throws SQLException { - //TODO return false; } @Override public boolean isSearchable(int column) throws SQLException { - return false; + return true; } @Override @@ -42,17 +46,30 @@ public class RestfulResultSetMetaData implements ResultSetMetaData { @Override public int isNullable(int column) throws SQLException { + if (column == 1) + return ResultSetMetaData.columnNoNulls; return ResultSetMetaData.columnNullable; } @Override public boolean isSigned(int column) throws SQLException { - return false; + String type = this.fields.get(column - 1).type.toUpperCase(); + switch (type) { + case "TINYINT": + case "SMALLINT": + case "INT": + case "BIGINT": + case "FLOAT": + case "DOUBLE": + return true; + default: + return false; + } } @Override public int getColumnDisplaySize(int column) throws SQLException { - return 0; + return this.fields.get(column - 1).length; } @Override @@ -62,27 +79,46 @@ public class RestfulResultSetMetaData implements ResultSetMetaData { @Override public String getColumnName(int column) throws SQLException { - return null; + return fields.get(column - 1).name; } @Override public String getSchemaName(int column) throws SQLException { - return this.database; + return ""; } @Override public int getPrecision(int column) throws SQLException { - return 0; + String type = this.fields.get(column - 1).type.toUpperCase(); + switch (type) { + case "FLOAT": + return 5; + case "DOUBLE": + return 9; + case "BINARY": + case "NCHAR": + return this.fields.get(column - 1).length; + default: + return 0; + } } @Override public int getScale(int column) throws SQLException { - return 0; + String type = this.fields.get(column - 1).type.toUpperCase(); + switch (type) { + case "FLOAT": + return 5; + case "DOUBLE": + return 9; + default: + return 0; + } } @Override public String getTableName(int column) throws SQLException { - return null; + return ""; } @Override @@ -92,17 +128,41 @@ public class RestfulResultSetMetaData implements ResultSetMetaData { @Override public int getColumnType(int column) throws SQLException { - return 0; + String type = this.fields.get(column - 1).type.toUpperCase(); + switch (type) { + case "BOOL": + return java.sql.Types.BOOLEAN; + case "TINYINT": + return java.sql.Types.TINYINT; + case "SMALLINT": + return java.sql.Types.SMALLINT; + case "INT": + return java.sql.Types.INTEGER; + case "BIGINT": + return java.sql.Types.BIGINT; + case "FLOAT": + return java.sql.Types.FLOAT; + case "DOUBLE": + return java.sql.Types.DOUBLE; + case "BINARY": + return java.sql.Types.BINARY; + case "TIMESTAMP": + return java.sql.Types.TIMESTAMP; + case "NCHAR": + return java.sql.Types.NCHAR; + } + throw new SQLException(TSDBConstants.INVALID_VARIABLES); } @Override public String getColumnTypeName(int column) throws SQLException { - return null; + String type = fields.get(column - 1).type; + return type.toUpperCase(); } @Override public boolean isReadOnly(int column) throws SQLException { - return false; + return true; } @Override @@ -117,16 +177,43 @@ public class RestfulResultSetMetaData implements ResultSetMetaData { @Override public String getColumnClassName(int column) throws SQLException { - return null; + String type = this.fields.get(column - 1).type; + String columnClassName = ""; + switch (type) { + case "BOOL": + return Boolean.class.getName(); + case "TINYINT": + case "SMALLINT": + return Short.class.getName(); + case "INT": + return Integer.class.getName(); + case "BIGINT": + return Long.class.getName(); + case "FLOAT": + return Float.class.getName(); + case "DOUBLE": + return Double.class.getName(); + case "TIMESTAMP": + return Timestamp.class.getName(); + case "BINARY": + case "NCHAR": + return String.class.getName(); + } + return columnClassName; } @Override public T unwrap(Class iface) throws SQLException { - return null; + try { + return iface.cast(this); + } catch (ClassCastException cce) { + throw new SQLException("Unable to unwrap to " + iface.toString()); + } } @Override public boolean isWrapperFor(Class iface) throws SQLException { - return false; + return iface.isInstance(this); } + } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index 93712875b334161410b27fe86791eac1c83c8671..14ea3180924a8b23055ff610a8f7db5a70522039 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -64,37 +64,18 @@ public class RestfulStatement implements Statement { public ResultSet executeQuery(String sql) throws SQLException { if (isClosed()) throw new SQLException("statement already closed"); - if (!SqlSyntaxValidator.isSelectSql(sql)) - throw new SQLException("not a select sql for executeQuery: " + sql); + if (!SqlSyntaxValidator.isValidForExecuteQuery(sql)) + throw new SQLException("not a valid sql for executeQuery: " + sql); final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; - // row data - String result = HttpClientPoolUtil.execute(url, sql); - JSONObject resultJson = JSON.parseObject(result); - if (resultJson.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code"))); + if (SqlSyntaxValidator.isDatabaseUnspecifiedQuery(sql)) { + return executeOneQuery(url, sql); } - // parse table name from sql - String[] tableIdentifiers = parseTableIdentifier(sql); - if (tableIdentifiers != null) { - List fieldJsonList = new ArrayList<>(); - for (String tableIdentifier : tableIdentifiers) { - // field meta - String fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + tableIdentifier); - JSONObject fieldJson = JSON.parseObject(fields); - if (fieldJson.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + fieldJson.getString("desc") + "\n" + "error code: " + fieldJson.getString("code"))); - } - fieldJsonList.add(fieldJson); - } - this.resultSet = new RestfulResultSet(database, this, resultJson, fieldJsonList); - } else { - this.resultSet = new RestfulResultSet(database, this, resultJson); - } - - this.affectedRows = 0; - return resultSet; + if (this.database == null || this.database.isEmpty()) + throw new SQLException("Database not specified or available"); + HttpClientPoolUtil.execute(url, "use " + this.database); + return executeOneQuery(url, sql); } @Override @@ -104,19 +85,15 @@ public class RestfulStatement implements Statement { if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql)) throw new SQLException("not a valid sql for executeUpdate: " + sql); - if (this.database == null) - throw new SQLException("Database not specified or available"); - - final String url = "http://" + conn.getHost().trim() + ":" + conn.getPort() + "/rest/sql"; -// HttpClientPoolUtil.execute(url, "use " + conn.getDatabase()); - String result = HttpClientPoolUtil.execute(url, sql); - JSONObject jsonObject = JSON.parseObject(result); - if (jsonObject.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonObject.getString("desc") + "\n" + "error code: " + jsonObject.getString("code"))); + final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; + if (SqlSyntaxValidator.isDatabaseUnspecifiedUpdate(sql)) { + return executeOneUpdate(url, sql); } - this.resultSet = null; - this.affectedRows = Integer.parseInt(jsonObject.getString("rows")); - return this.affectedRows; + + if (this.database == null || this.database.isEmpty()) + throw new SQLException("Database not specified or available"); + HttpClientPoolUtil.execute(url, "use " + this.database); + return executeOneUpdate(url, sql); } @Override @@ -208,35 +185,75 @@ public class RestfulStatement implements Statement { @Override public boolean execute(String sql) throws SQLException { - if (isClosed()) { + if (isClosed()) throw new SQLException("Invalid method call on a closed statement."); - } + if (!SqlSyntaxValidator.isValidForExecute(sql)) + throw new SQLException("not a valid sql for execute: " + sql); + //如果执行了use操作应该将当前Statement的catalog设置为新的database + final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; if (SqlSyntaxValidator.isUseSql(sql)) { + HttpClientPoolUtil.execute(url, sql); this.database = sql.trim().replace("use", "").trim(); this.conn.setCatalog(this.database); + } else if (SqlSyntaxValidator.isDatabaseUnspecifiedQuery(sql)) { + executeOneQuery(url, sql); + } else if (SqlSyntaxValidator.isDatabaseUnspecifiedUpdate(sql)) { + executeOneUpdate(url, sql); + } else { + if (SqlSyntaxValidator.isValidForExecuteQuery(sql)) { + executeQuery(sql); + } else { + executeUpdate(sql); + } } - if (this.database == null) - throw new SQLException("Database not specified or available"); - if (SqlSyntaxValidator.isSelectSql(sql)) { - executeQuery(sql); - } else if (SqlSyntaxValidator.isShowSql(sql) || SqlSyntaxValidator.isDescribeSql(sql)) { - final String url = "http://" + conn.getHost().trim() + ":" + conn.getPort() + "/rest/sql"; - if (!SqlSyntaxValidator.isShowDatabaseSql(sql)) { - HttpClientPoolUtil.execute(url, "use " + conn.getDatabase()); - } - String result = HttpClientPoolUtil.execute(url, sql); - JSONObject resultJson = JSON.parseObject(result); - if (resultJson.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code"))); + return true; + } + + private ResultSet executeOneQuery(String url, String sql) throws SQLException { + if (!SqlSyntaxValidator.isValidForExecuteQuery(sql)) + throw new SQLException("not a select sql for executeQuery: " + sql); + + // row data + String result = HttpClientPoolUtil.execute(url, sql); + JSONObject resultJson = JSON.parseObject(result); + if (resultJson.getString("status").equals("error")) { + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code"))); + } + // parse table name from sql + String[] tableIdentifiers = parseTableIdentifier(sql); + if (tableIdentifiers != null) { + List fieldJsonList = new ArrayList<>(); + for (String tableIdentifier : tableIdentifiers) { + // field meta + String fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + tableIdentifier); + JSONObject fieldJson = JSON.parseObject(fields); + if (fieldJson.getString("status").equals("error")) { + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + fieldJson.getString("desc") + "\n" + "error code: " + fieldJson.getString("code"))); + } + fieldJsonList.add(fieldJson); } - this.resultSet = new RestfulResultSet(database, this, resultJson); + this.resultSet = new RestfulResultSet(database, this, resultJson, fieldJsonList); } else { - executeUpdate(sql); + this.resultSet = new RestfulResultSet(database, this, resultJson); } + this.affectedRows = 0; + return resultSet; + } - return true; + private int executeOneUpdate(String url, String sql) throws SQLException { + if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql)) + throw new SQLException("not a valid sql for executeUpdate: " + sql); + + String result = HttpClientPoolUtil.execute(url, sql); + JSONObject jsonObject = JSON.parseObject(result); + if (jsonObject.getString("status").equals("error")) { + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonObject.getString("desc") + "\n" + "error code: " + jsonObject.getString("code"))); + } + this.resultSet = null; + this.affectedRows = Integer.parseInt(jsonObject.getString("rows")); + return this.affectedRows; } @Override diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java index f0d92346167411ca6da78015392ba8a21286e1cf..251ca2af013e2b1c9cb314b776621455c91d9384 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java @@ -20,8 +20,11 @@ import java.sql.Connection; public class SqlSyntaxValidator { - private static final String[] updateSQL = {"insert", "update", "delete", "create", "alter", "drop", "show", "describe", "use", "import"}; - private static final String[] querySQL = {"select"}; + private static final String[] SQL = {"select", "insert", "import", "create", "use", "alter", "drop", "set", "show", "describe"}; + private static final String[] updateSQL = {"insert", "import", "create", "use", "alter", "drop", "set"}; + private static final String[] querySQL = {"select", "show", "describe"}; + + private static final String[] databaseUnspecifiedShow = {"databases", "dnodes", "mnodes", "variables"}; private TSDBConnection tsdbConnection; @@ -37,8 +40,38 @@ public class SqlSyntaxValidator { return false; } + public static boolean isValidForExecuteQuery(String sql) { + for (String prefix : querySQL) { + if (sql.trim().toLowerCase().startsWith(prefix)) + return true; + } + return false; + } + + public static boolean isValidForExecute(String sql) { + for (String prefix : SQL) { + if (sql.trim().toLowerCase().startsWith(prefix)) + return true; + } + return false; + } + + public static boolean isDatabaseUnspecifiedQuery(String sql) { + for (String databaseObj : databaseUnspecifiedShow) { + if (sql.trim().toLowerCase().matches("show\\s+" + databaseObj + ".*")) + return true; + } + return false; + } + + public static boolean isDatabaseUnspecifiedUpdate(String sql) { + sql = sql.trim().toLowerCase(); + return sql.matches("create\\s+database.*") || sql.startsWith("set") || sql.matches("drop\\s+database.*"); + } + public static boolean isUseSql(String sql) { - return sql.trim().toLowerCase().startsWith("use") || sql.trim().toLowerCase().matches("create\\s*database.*") || sql.toLowerCase().toLowerCase().matches("drop\\s*database.*"); + return sql.trim().toLowerCase().startsWith("use"); +// || sql.trim().toLowerCase().matches("create\\s*database.*") || sql.toLowerCase().toLowerCase().matches("drop\\s*database.*"); } public static boolean isShowSql(String sql) { @@ -58,8 +91,9 @@ public class SqlSyntaxValidator { return sql.trim().toLowerCase().startsWith("select"); } - public static boolean isShowDatabaseSql(String sql) { return sql.trim().toLowerCase().matches("show\\s*databases"); } + + } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java index 918714da22d45df3e78af93c07423689f1baccc2..11d4a143535d7e116d92875a6eb52b5bf7a5b6e0 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/AuthenticationTest.java @@ -8,6 +8,7 @@ import java.sql.*; public class AuthenticationTest { private static final String host = "127.0.0.1"; + // private static final String host = "master"; private static final String user = "root"; private static final String password = "123456"; private Connection conn; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java index ee4b2ed4dd2944a5b09df9afb5d15638422d52cb..185c0306f5259206c96072b7f306f18a7a8a8f7e 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java @@ -10,23 +10,12 @@ import java.util.Random; public class RestfulJDBCTest { private static final String host = "127.0.0.1"; - private Connection connection; - - @Before - public void before() throws ClassNotFoundException, SQLException { - Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); - connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata"); - } - - @After - public void after() throws SQLException { - if (connection != null) - connection.close(); - } - + // private static final String host = "master"; + private static Connection connection; + private Random random = new Random(System.currentTimeMillis()); /** - * 查询所有log.log + * select * from log.log **/ @Test public void testCase001() { @@ -85,7 +74,6 @@ public class RestfulJDBCTest { } } - private Random random = new Random(System.currentTimeMillis()); @Test public void testCase005() { @@ -105,5 +93,50 @@ public class RestfulJDBCTest { } } + @Test + public void testCase006() { + try (Statement stmt = connection.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from weather"); + while (rs.next()) { + System.out.print("ts: " + rs.getTimestamp("ts")); + System.out.print(", temperature: " + rs.getString("temperature")); + System.out.print(", humidity: " + rs.getString("humidity")); + System.out.println(", location: " + rs.getString("location")); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Test + public void testCase007() { + try (Statement stmt = connection.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from weather"); + ResultSetMetaData meta = rs.getMetaData(); + while (rs.next()) { + int columnCount = meta.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + String columnLabel = meta.getColumnLabel(i); + String value = rs.getString(i); + System.out.print(columnLabel + ": " + value + "\t"); + } + System.out.println(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @BeforeClass + public static void before() throws ClassNotFoundException, SQLException { + Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); + connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata"); + } + + @AfterClass + public static void after() throws SQLException { + if (connection != null) + connection.close(); + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java new file mode 100644 index 0000000000000000000000000000000000000000..13973d8b6bf6c11ced27866724b91c0746a024d0 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java @@ -0,0 +1,221 @@ +package com.taosdata.jdbc.rs; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.*; + +public class RestfulResultSetMetaDataTest { + + private static final String host = "127.0.0.1"; +// private static final String host = "master"; + + private static Connection conn; + private static Statement stmt; + private static ResultSet rs; + private static ResultSetMetaData meta; + + @Test + public void getColumnCount() throws SQLException { + Assert.assertEquals(10, meta.getColumnCount()); + } + + @Test + public void isAutoIncrement() throws SQLException { + Assert.assertFalse(meta.isAutoIncrement(1)); + Assert.assertFalse(meta.isAutoIncrement(2)); + Assert.assertFalse(meta.isAutoIncrement(3)); + Assert.assertFalse(meta.isAutoIncrement(4)); + Assert.assertFalse(meta.isAutoIncrement(5)); + Assert.assertFalse(meta.isAutoIncrement(6)); + Assert.assertFalse(meta.isAutoIncrement(7)); + Assert.assertFalse(meta.isAutoIncrement(8)); + Assert.assertFalse(meta.isAutoIncrement(9)); + Assert.assertFalse(meta.isAutoIncrement(10)); + } + + @Test + public void isCaseSensitive() throws SQLException { + Assert.assertFalse(meta.isCaseSensitive(1)); + } + + @Test + public void isSearchable() throws SQLException { + Assert.assertTrue(meta.isSearchable(1)); + } + + @Test + public void isCurrency() throws SQLException { + Assert.assertFalse(meta.isCurrency(1)); + } + + @Test + public void isNullable() throws SQLException { + Assert.assertEquals(ResultSetMetaData.columnNoNulls, meta.isNullable(1)); + Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(2)); + Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(3)); + Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(4)); + Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(5)); + Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(6)); + Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(7)); + Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(8)); + Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(9)); + Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(10)); + } + + @Test + public void isSigned() throws SQLException { + Assert.assertFalse(meta.isSigned(1)); + } + + @Test + public void getColumnDisplaySize() throws SQLException { + Assert.assertEquals(64, meta.getColumnDisplaySize(10)); + } + + @Test + public void getColumnLabel() throws SQLException { + Assert.assertEquals("f1", meta.getColumnLabel(1)); + } + + @Test + public void getColumnName() throws SQLException { + Assert.assertEquals("f1", meta.getColumnName(1)); + } + + @Test + public void getSchemaName() throws SQLException { + Assert.assertEquals("", meta.getSchemaName(1)); + } + + @Test + public void getPrecision() throws SQLException { + Assert.assertEquals(0, meta.getPrecision(1)); + } + + @Test + public void getScale() throws SQLException { + Assert.assertEquals(0, meta.getScale(1)); + } + + @Test + public void getTableName() throws SQLException { + Assert.assertEquals("", meta.getTableName(1)); + } + + @Test + public void getCatalogName() throws SQLException { + Assert.assertEquals("restful_test", meta.getCatalogName(1)); + Assert.assertEquals("restful_test", meta.getCatalogName(2)); + Assert.assertEquals("restful_test", meta.getCatalogName(3)); + Assert.assertEquals("restful_test", meta.getCatalogName(4)); + Assert.assertEquals("restful_test", meta.getCatalogName(5)); + Assert.assertEquals("restful_test", meta.getCatalogName(6)); + Assert.assertEquals("restful_test", meta.getCatalogName(7)); + Assert.assertEquals("restful_test", meta.getCatalogName(8)); + Assert.assertEquals("restful_test", meta.getCatalogName(9)); + Assert.assertEquals("restful_test", meta.getCatalogName(10)); + } + + @Test + public void getColumnType() throws SQLException { + Assert.assertEquals(Types.TIMESTAMP, meta.getColumnType(1)); + Assert.assertEquals(Types.INTEGER, meta.getColumnType(2)); + Assert.assertEquals(Types.BIGINT, meta.getColumnType(3)); + Assert.assertEquals(Types.FLOAT, meta.getColumnType(4)); + Assert.assertEquals(Types.DOUBLE, meta.getColumnType(5)); + Assert.assertEquals(Types.BINARY, meta.getColumnType(6)); + Assert.assertEquals(Types.SMALLINT, meta.getColumnType(7)); + Assert.assertEquals(Types.TINYINT, meta.getColumnType(8)); + Assert.assertEquals(Types.BOOLEAN, meta.getColumnType(9)); + Assert.assertEquals(Types.NCHAR, meta.getColumnType(10)); + } + + @Test + public void getColumnTypeName() throws SQLException { + Assert.assertEquals("TIMESTAMP", meta.getColumnTypeName(1)); + Assert.assertEquals("INT", meta.getColumnTypeName(2)); + Assert.assertEquals("BIGINT", meta.getColumnTypeName(3)); + Assert.assertEquals("FLOAT", meta.getColumnTypeName(4)); + Assert.assertEquals("DOUBLE", meta.getColumnTypeName(5)); + Assert.assertEquals("BINARY", meta.getColumnTypeName(6)); + Assert.assertEquals("SMALLINT", meta.getColumnTypeName(7)); + Assert.assertEquals("TINYINT", meta.getColumnTypeName(8)); + Assert.assertEquals("BOOL", meta.getColumnTypeName(9)); + Assert.assertEquals("NCHAR", meta.getColumnTypeName(10)); + } + + @Test + public void isReadOnly() throws SQLException { + Assert.assertTrue(meta.isReadOnly(1)); + } + + @Test + public void isWritable() throws SQLException { + Assert.assertFalse(meta.isWritable(1)); + } + + @Test + public void isDefinitelyWritable() throws SQLException { + Assert.assertFalse(meta.isDefinitelyWritable(1)); + } + + @Test + public void getColumnClassName() throws SQLException { + Assert.assertEquals(Timestamp.class.getName(), meta.getColumnClassName(1)); + Assert.assertEquals(Integer.class.getName(), meta.getColumnClassName(2)); + Assert.assertEquals(Long.class.getName(), meta.getColumnClassName(3)); + Assert.assertEquals(Float.class.getName(), meta.getColumnClassName(4)); + Assert.assertEquals(Double.class.getName(), meta.getColumnClassName(5)); + Assert.assertEquals(String.class.getName(), meta.getColumnClassName(6)); + Assert.assertEquals(Short.class.getName(), meta.getColumnClassName(7)); + Assert.assertEquals(Short.class.getName(), meta.getColumnClassName(8)); + Assert.assertEquals(Boolean.class.getName(), meta.getColumnClassName(9)); + Assert.assertEquals(String.class.getName(), meta.getColumnClassName(10)); + } + + @Test + public void unwrap() throws SQLException { + Assert.assertNotNull(meta.unwrap(RestfulResultSetMetaData.class)); + } + + @Test + public void isWrapperFor() throws SQLException { + Assert.assertTrue(meta.isWrapperFor(RestfulResultSetMetaData.class)); + } + + @BeforeClass + public static void beforeClass() { + try { + Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); + conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata"); + stmt = conn.createStatement(); + stmt.execute("create database if not exists restful_test"); + stmt.execute("use restful_test"); + stmt.execute("drop table if exists weather"); + stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))"); + stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"); + rs = stmt.executeQuery("select * from restful_test.weather"); + rs.next(); + meta = rs.getMetaData(); + } catch (ClassNotFoundException | SQLException e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void afterClass() { + try { + if (rs != null) + rs.close(); + if (stmt != null) + stmt.close(); + if (conn != null) + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java new file mode 100644 index 0000000000000000000000000000000000000000..a14d09588d21f5d405cbb2456c9833d2a411ea96 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java @@ -0,0 +1,588 @@ +package com.taosdata.jdbc.rs; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.sql.*; + +public class RestfulResultSetTest { + + private static final String host = "127.0.0.1"; +// private static final String host = "master"; + + private static Connection conn; + private static Statement stmt; + private static ResultSet rs; + + @Test + public void wasNull() throws SQLException { + Assert.assertFalse(rs.wasNull()); + } + + @Test + public void getString() throws SQLException { + String f10 = rs.getString("f10"); + Assert.assertEquals("涛思数据", f10); + f10 = rs.getString(10); + Assert.assertEquals("涛思数据", f10); + } + + @Test + public void getBoolean() throws SQLException { + Boolean f9 = rs.getBoolean("f9"); + Assert.assertEquals(true, f9); + f9 = rs.getBoolean(9); + Assert.assertEquals(true, f9); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getByte() throws SQLException { + rs.getByte(1); + } + + @Test + public void getShort() throws SQLException { + short f7 = rs.getShort("f7"); + Assert.assertEquals(10, f7); + f7 = rs.getShort(7); + Assert.assertEquals(10, f7); + } + + @Test + public void getInt() throws SQLException { + int f2 = rs.getInt("f2"); + Assert.assertEquals(1, f2); + f2 = rs.getInt(2); + Assert.assertEquals(1, f2); + } + + @Test + public void getLong() throws SQLException { + long f3 = rs.getLong("f3"); + Assert.assertEquals(100, f3); + f3 = rs.getLong(3); + Assert.assertEquals(100, f3); + } + + @Test + public void getFloat() throws SQLException { + float f4 = rs.getFloat("f4"); + Assert.assertEquals(3.1415f, f4, 0f); + f4 = rs.getFloat(4); + Assert.assertEquals(3.1415f, f4, 0f); + } + + @Test + public void getDouble() throws SQLException { + double f5 = rs.getDouble("f5"); + Assert.assertEquals(3.1415926, f5, 0.0); + f5 = rs.getDouble(5); + Assert.assertEquals(3.1415926, f5, 0.0); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getBigDecimal() throws SQLException { + rs.getBigDecimal("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getBytes() throws SQLException { + rs.getBytes("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getDate() throws SQLException { + rs.getDate("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getTime() throws SQLException { + rs.getTime("f1"); + } + + @Test + public void getTimestamp() throws SQLException { + Timestamp f1 = rs.getTimestamp("f1"); + Assert.assertEquals("2021-01-01 00:00:00.0", f1.toString()); + f1 = rs.getTimestamp(1); + Assert.assertEquals("2021-01-01 00:00:00.0", f1.toString()); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getAsciiStream() throws SQLException { + rs.getAsciiStream("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getUnicodeStream() throws SQLException { + rs.getUnicodeStream("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getBinaryStream() throws SQLException { + rs.getBinaryStream("f1"); + } + + @Test + public void getWarnings() throws SQLException { + Assert.assertNull(rs.getWarnings()); + } + + @Test + public void clearWarnings() throws SQLException { + rs.clearWarnings(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getCursorName() throws SQLException { + rs.getCursorName(); + } + + @Test + public void getMetaData() throws SQLException { + ResultSetMetaData meta = rs.getMetaData(); + Assert.assertNotNull(meta); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getObject() throws SQLException { + rs.getObject("f1"); + } + + @Test(expected = SQLException.class) + public void findColumn() throws SQLException { + int columnIndex = rs.findColumn("f1"); + Assert.assertEquals(1, columnIndex); + columnIndex = rs.findColumn("f2"); + Assert.assertEquals(2, columnIndex); + columnIndex = rs.findColumn("f3"); + Assert.assertEquals(3, columnIndex); + columnIndex = rs.findColumn("f4"); + Assert.assertEquals(4, columnIndex); + columnIndex = rs.findColumn("f5"); + Assert.assertEquals(5, columnIndex); + columnIndex = rs.findColumn("f6"); + Assert.assertEquals(6, columnIndex); + columnIndex = rs.findColumn("f7"); + Assert.assertEquals(7, columnIndex); + columnIndex = rs.findColumn("f8"); + Assert.assertEquals(8, columnIndex); + columnIndex = rs.findColumn("f9"); + Assert.assertEquals(9, columnIndex); + columnIndex = rs.findColumn("f10"); + Assert.assertEquals(10, columnIndex); + + rs.findColumn("f11"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getCharacterStream() throws SQLException { + rs.getCharacterStream(1); + } + + @Test + public void isBeforeFirst() throws SQLException { + Assert.assertFalse(rs.isBeforeFirst()); + rs.beforeFirst(); + Assert.assertTrue(rs.isBeforeFirst()); + rs.next(); + } + + @Test + public void isAfterLast() throws SQLException { + Assert.assertFalse(rs.isAfterLast()); + } + + @Test + public void isFirst() throws SQLException { + Assert.assertTrue(rs.isFirst()); + } + + @Test + public void isLast() throws SQLException { + Assert.assertTrue(rs.isLast()); + } + + @Test + public void beforeFirst() throws SQLException { + rs.beforeFirst(); + Assert.assertTrue(rs.isBeforeFirst()); + rs.next(); + } + + @Test + public void afterLast() throws SQLException { + rs.afterLast(); + Assert.assertTrue(rs.isAfterLast()); + rs.first(); + } + + @Test + public void first() throws SQLException { + rs.first(); + Assert.assertEquals("2021-01-01 00:00:00.0", rs.getTimestamp("f1").toString()); + } + + @Test + public void last() throws SQLException { + rs.last(); + Assert.assertEquals("2021-01-01 00:00:00.0", rs.getTimestamp("f1").toString()); + } + + @Test + public void getRow() throws SQLException { + int row = rs.getRow(); + Assert.assertEquals(1, row); + rs.beforeFirst(); + row = rs.getRow(); + Assert.assertEquals(0, row); + rs.first(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void absolute() throws SQLException { + rs.absolute(-1); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void relative() throws SQLException { + rs.relative(-1); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void previous() throws SQLException { + rs.previous(); + } + + @Test(expected = SQLException.class) + public void setFetchDirection() throws SQLException { + rs.setFetchDirection(ResultSet.FETCH_FORWARD); + rs.setFetchDirection(ResultSet.FETCH_UNKNOWN); + } + + @Test + public void getFetchDirection() throws SQLException { + Assert.assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection()); + } + + @Test(expected = SQLException.class) + public void setFetchSize() throws SQLException { + rs.setFetchSize(0); + } + + @Test + public void getFetchSize() throws SQLException { + Assert.assertEquals(1, rs.getFetchSize()); + } + + @Test + public void getType() throws SQLException { + Assert.assertEquals(ResultSet.TYPE_FORWARD_ONLY, rs.getType()); + } + + @Test + public void getConcurrency() throws SQLException { + Assert.assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency()); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void rowUpdated() throws SQLException { + rs.rowUpdated(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void rowInserted() throws SQLException { + rs.rowInserted(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void rowDeleted() throws SQLException { + rs.rowDeleted(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateNull() throws SQLException { + rs.updateNull("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateBoolean() throws SQLException { + rs.updateBoolean(1, false); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateByte() throws SQLException { + rs.updateByte(1, new Byte("0")); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateShort() throws SQLException { + rs.updateShort(1, new Short("0")); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateInt() throws SQLException { + rs.updateInt(1, 1); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateLong() throws SQLException { + rs.updateLong(1, 1l); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateFloat() throws SQLException { + rs.updateFloat(1, 1f); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateDouble() throws SQLException { + rs.updateDouble(1, 1.0); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateBigDecimal() throws SQLException { + rs.updateBigDecimal(1, new BigDecimal(1)); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateString() throws SQLException { + rs.updateString(1, "abc"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateBytes() throws SQLException { + rs.updateBytes(1, new byte[]{}); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateDate() throws SQLException { + rs.updateDate(1, new Date(System.currentTimeMillis())); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateTime() throws SQLException { + rs.updateTime(1, new Time(System.currentTimeMillis())); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateTimestamp() throws SQLException { + rs.updateTimestamp(1, new Timestamp(System.currentTimeMillis())); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateAsciiStream() throws SQLException { + rs.updateAsciiStream(1, null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateBinaryStream() throws SQLException { + rs.updateBinaryStream(1, null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateCharacterStream() throws SQLException { + rs.updateCharacterStream(1, null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateObject() throws SQLException { + rs.updateObject(1, null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void insertRow() throws SQLException { + rs.insertRow(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateRow() throws SQLException { + rs.updateRow(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void deleteRow() throws SQLException { + rs.deleteRow(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void refreshRow() throws SQLException { + rs.refreshRow(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void cancelRowUpdates() throws SQLException { + rs.cancelRowUpdates(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void moveToInsertRow() throws SQLException { + rs.moveToInsertRow(); + } + + @Test + public void getStatement() throws SQLException { + Statement stmt = rs.getStatement(); + Assert.assertNotNull(stmt); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void moveToCurrentRow() throws SQLException { + rs.moveToCurrentRow(); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getRef() throws SQLException { + rs.getRef(1); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getBlob() throws SQLException { + rs.getBlob("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getClob() throws SQLException { + rs.getClob("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getArray() throws SQLException { + rs.getArray("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getURL() throws SQLException { + rs.getURL("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateRef() throws SQLException { + rs.updateRef("f1", null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateBlob() throws SQLException { + rs.updateBlob(1, (InputStream) null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateClob() throws SQLException { + rs.updateClob(1, (Reader) null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateArray() throws SQLException { + rs.updateArray(1, null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getRowId() throws SQLException { + rs.getRowId("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateRowId() throws SQLException { + rs.updateRowId(1, null); + } + + @Test + public void getHoldability() throws SQLException { + Assert.assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, rs.getHoldability()); + } + + @Test + public void isClosed() throws SQLException { + Assert.assertFalse(rs.isClosed()); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateNString() throws SQLException { + rs.updateNString(1, null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateNClob() throws SQLException { + rs.updateNClob(1, (Reader) null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getNClob() throws SQLException { + rs.getNClob("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getSQLXML() throws SQLException { + rs.getSQLXML("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateSQLXML() throws SQLException { + rs.updateSQLXML(1, null); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getNString() throws SQLException { + rs.getNString("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void getNCharacterStream() throws SQLException { + rs.getNCharacterStream("f1"); + } + + @Test(expected = SQLFeatureNotSupportedException.class) + public void updateNCharacterStream() throws SQLException { + rs.updateNCharacterStream(1, null); + } + + @Test + public void unwrap() throws SQLException { + RestfulResultSet unwrap = rs.unwrap(RestfulResultSet.class); + Assert.assertNotNull(unwrap); + } + + @Test + public void isWrapperFor() throws SQLException { + Assert.assertTrue(rs.isWrapperFor(RestfulResultSet.class)); + } + + @BeforeClass + public static void beforeClass() { + try { + Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); + conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata"); + stmt = conn.createStatement(); + stmt.execute("create database if not exists restful_test"); + stmt.execute("use restful_test"); + stmt.execute("drop table if exists weather"); + stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))"); + stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"); + rs = stmt.executeQuery("select * from restful_test.weather"); + rs.next(); + } catch (ClassNotFoundException | SQLException e) { + e.printStackTrace(); + } + + } + + @AfterClass + public static void afterClass() { + try { + if (rs != null) + rs.close(); + if (stmt != null) + stmt.close(); + if (conn != null) + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java index ad6ed43ac737429707ff4f086a320cb62336b020..313abfd27865ef37d8b522b38951b17902f5a486 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java @@ -1,5 +1,6 @@ package com.taosdata.jdbc.rs; +import com.taosdata.jdbc.utils.SQLExecutor; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.FixMethodOrder; @@ -11,378 +12,315 @@ import java.sql.*; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class SQLTest { private static final String host = "127.0.0.1"; - + // private static final String host = "master"; private static Connection connection; @Test public void testCase001() { String sql = "create database if not exists restful_test"; - execute(sql); + SQLExecutor.execute(connection, sql); } @Test public void testCase002() { String sql = "use restful_test"; - execute(sql); + SQLExecutor.execute(connection, sql); } @Test public void testCase003() { String sql = "show databases"; - executeWithResult(sql); + SQLExecutor.executeWithResult(connection, sql); } @Test public void testCase004() { String sql = "show tables"; - executeWithResult(sql); + SQLExecutor.executeWithResult(connection, sql); } @Test public void testCase005() { String sql = "show stables"; - executeWithResult(sql); + SQLExecutor.executeWithResult(connection, sql); } @Test public void testCase006() { String sql = "show dnodes"; - executeWithResult(sql); + SQLExecutor.executeWithResult(connection, sql); } @Test public void testCase007() { String sql = "show vgroups"; - executeWithResult(sql); + SQLExecutor.executeWithResult(connection, sql); } @Test public void testCase008() { String sql = "drop table if exists restful_test.weather"; - execute(sql); + SQLExecutor.execute(connection, sql); } @Test public void testCase009() { String sql = "create table if not exists restful_test.weather(ts timestamp, temperature float) tags(location nchar(64))"; - execute(sql); + SQLExecutor.execute(connection, sql); } @Test public void testCase010() { String sql = "create table t1 using restful_test.weather tags('北京')"; - execute(sql); + SQLExecutor.execute(connection, sql); } @Test public void testCase011() { String sql = "insert into restful_test.t1 values(now, 22.22)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase012() { String sql = "insert into restful_test.t1 values('2020-01-01 00:00:00.000', 22.22)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase013() { String sql = "insert into restful_test.t1 values('2020-01-01 00:01:00.000', 22.22),('2020-01-01 00:02:00.000', 22.22)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase014() { String sql = "insert into restful_test.t2 using weather tags('上海') values('2020-01-01 00:03:00.000', 22.22)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase015() { String sql = "insert into restful_test.t2 using weather tags('上海') values('2020-01-01 00:01:00.000', 22.22),('2020-01-01 00:02:00.000', 22.22)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase016() { String sql = "insert into t1 values('2020-01-01 01:0:00.000', 22.22),('2020-01-01 02:00:00.000', 22.22) t2 values('2020-01-01 01:0:00.000', 33.33),('2020-01-01 02:00:00.000', 33.33)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase017() { String sql = "Insert into t3 using weather tags('广东') values('2020-01-01 01:0:00.000', 22.22),('2020-01-01 02:00:00.000', 22.22) t4 using weather tags('天津') values('2020-01-01 01:0:00.000', 33.33),('2020-01-01 02:00:00.000', 33.33)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase018() { String sql = "select * from restful_test.t1"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase019() { String sql = "select * from restful_test.weather"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase020() { String sql = "select ts, temperature from restful_test.t1"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase021() { String sql = "select ts, temperature from restful_test.weather"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase022() { String sql = "select temperature, ts from restful_test.t1"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase023() { String sql = "select temperature, ts from restful_test.weather"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase024() { String sql = "import into restful_test.t5 using weather tags('石家庄') values('2020-01-01 00:01:00.000', 22.22)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase025() { String sql = "import into restful_test.t6 using weather tags('沈阳') values('2020-01-01 00:01:00.000', 22.22),('2020-01-01 00:02:00.000', 22.22)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase026() { String sql = "import into restful_test.t7 using weather tags('长沙') values('2020-01-01 00:01:00.000', 22.22) restful_test.t8 using weather tags('吉林') values('2020-01-01 00:01:00.000', 22.22)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase027() { String sql = "import into restful_test.t9 using weather tags('武汉') values('2020-01-01 00:01:00.000', 22.22) ,('2020-01-02 00:01:00.000', 22.22) restful_test.t10 using weather tags('哈尔滨') values('2020-01-01 00:01:00.000', 22.22),('2020-01-02 00:01:00.000', 22.22)"; - executeUpdate(sql); + SQLExecutor.executeUpdate(connection, sql); } @Test public void testCase028() { String sql = "select location, temperature, ts from restful_test.weather where temperature > 1"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase029() { String sql = "select location, temperature, ts from restful_test.weather where temperature < 1"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase030() { String sql = "select location, temperature, ts from restful_test.weather where ts > now"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase031() { String sql = "select location, temperature, ts from restful_test.weather where ts < now"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase032() { String sql = "select count(*) from restful_test.weather"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase033() { String sql = "select first(*) from restful_test.weather"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase034() { String sql = "select last(*) from restful_test.weather"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase035() { String sql = "select last_row(*) from restful_test.weather"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase036() { String sql = "select ts, ts as primary_key from restful_test.weather"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase037() { String sql = "select database()"; - execute("use restful_test"); - executeQuery(sql); + SQLExecutor.execute(connection, "use restful_test"); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase038() { String sql = "select client_version()"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase039() { String sql = "select server_status()"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase040() { String sql = "select server_status() as status"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase041() { String sql = "select tbname, location from restful_test.weather"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase042() { String sql = "select count(tbname) from restful_test.weather"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase043() { String sql = "select * from restful_test.weather where ts < now - 1h"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase044() { String sql = "select * from restful_test.weather where ts < now - 1h and location like '%'"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase045() { String sql = "select * from restful_test.weather where ts < now - 1h order by ts"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase046() { String sql = "select last(*) from restful_test.weather where ts < now - 1h group by tbname order by tbname"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase047() { String sql = "select * from restful_test.weather limit 2"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase048() { String sql = "select * from restful_test.weather limit 2 offset 5"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase049() { String sql = "select * from restful_test.t1, restful_test.t3 where t1.ts = t3.ts "; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase050() { String sql = "select * from restful_test.t1, restful_test.t3 where t1.ts = t3.ts and t1.location = t3.location"; - executeQuery(sql); + SQLExecutor.executeQuery(connection, sql); } @Test public void testCase051() { String sql = "select * from restful_test.t1 tt, restful_test.t3 yy where tt.ts = yy.ts"; - executeQuery(sql); - } - - private void executeUpdate(String sql) { - try (Statement statement = connection.createStatement()) { - long start = System.currentTimeMillis(); - int affectedRows = statement.executeUpdate(sql); - long end = System.currentTimeMillis(); - System.out.println("[ affected rows : " + affectedRows + " ] time cost: " + (end - start) + " ms, execute statement ====> " + sql); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - private void executeWithResult(String sql) { - try (Statement statement = connection.createStatement()) { - statement.execute(sql); - ResultSet resultSet = statement.getResultSet(); - printResult(resultSet); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - private void execute(String sql) { - try (Statement statement = connection.createStatement()) { - long start = System.currentTimeMillis(); - boolean execute = statement.execute(sql); - long end = System.currentTimeMillis(); - printSql(sql, execute, (end - start)); - } catch (SQLException e) { - System.out.println("ERROR execute SQL ===> " + sql); - e.printStackTrace(); - } - } - - private static void printSql(String sql, boolean succeed, long cost) { - System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql); - } - - private void executeQuery(String sql) { - try (Statement statement = connection.createStatement()) { - long start = System.currentTimeMillis(); - ResultSet resultSet = statement.executeQuery(sql); - long end = System.currentTimeMillis(); - printSql(sql, true, (end - start)); - printResult(resultSet); - } catch (SQLException e) { - System.out.println("ERROR execute SQL ===> " + sql); - e.printStackTrace(); - } - } - - private static void printResult(ResultSet resultSet) throws SQLException { - ResultSetMetaData metaData = resultSet.getMetaData(); - while (resultSet.next()) { - StringBuilder sb = new StringBuilder(); - for (int i = 1; i <= metaData.getColumnCount(); i++) { - String columnLabel = metaData.getColumnLabel(i); - String value = resultSet.getString(i); - sb.append(columnLabel + ": " + value + "\t"); - } - System.out.println(sb.toString()); - } + SQLExecutor.executeQuery(connection, sql); } @BeforeClass diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SQLExecutor.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SQLExecutor.java new file mode 100644 index 0000000000000000000000000000000000000000..bf034bf458bcb8eadaaacb5cf633f0905a8c1bd6 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SQLExecutor.java @@ -0,0 +1,74 @@ +package com.taosdata.jdbc.utils; + +import java.sql.*; + +public class SQLExecutor { + + // insert, import + public static void executeUpdate(Connection connection, String sql) { + try (Statement statement = connection.createStatement()) { + long start = System.currentTimeMillis(); + int affectedRows = statement.executeUpdate(sql); + long end = System.currentTimeMillis(); + System.out.println("[ affected rows : " + affectedRows + " ] time cost: " + (end - start) + " ms, execute statement ====> " + sql); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + // show databases, show tables, show stables + public static void executeWithResult(Connection connection, String sql) { + try (Statement statement = connection.createStatement()) { + statement.execute(sql); + ResultSet resultSet = statement.getResultSet(); + printResult(resultSet); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + // use database, create database, create table, drop table... + public static void execute(Connection connection, String sql) { + try (Statement statement = connection.createStatement()) { + long start = System.currentTimeMillis(); + boolean execute = statement.execute(sql); + long end = System.currentTimeMillis(); + printSql(sql, execute, (end - start)); + } catch (SQLException e) { + System.out.println("ERROR execute SQL ===> " + sql); + e.printStackTrace(); + } + } + + // select + public static void executeQuery(Connection connection, String sql) { + try (Statement statement = connection.createStatement()) { + long start = System.currentTimeMillis(); + ResultSet resultSet = statement.executeQuery(sql); + long end = System.currentTimeMillis(); + printSql(sql, true, (end - start)); + printResult(resultSet); + } catch (SQLException e) { + System.out.println("ERROR execute SQL ===> " + sql); + e.printStackTrace(); + } + } + + private static void printSql(String sql, boolean succeed, long cost) { + System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql); + } + + private static void printResult(ResultSet resultSet) throws SQLException { + ResultSetMetaData metaData = resultSet.getMetaData(); + while (resultSet.next()) { + StringBuilder sb = new StringBuilder(); + for (int i = 1; i <= metaData.getColumnCount(); i++) { + String columnLabel = metaData.getColumnLabel(i); + String value = resultSet.getString(i); + sb.append(columnLabel + ": " + value + "\t"); + } + System.out.println(sb.toString()); + } + } + +} diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 63b2f3ea158fc90a05ed9c7ea818dfbf674989d3..6140b9824c0688b423397682578c16fe872eb031 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6424,6 +6424,11 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, pMsg += pQueryMsg->tbnameCondLen; } + //skip ts buf + if ((pQueryMsg->tsOffset + pQueryMsg->tsLen) > 0) { + pMsg = (char *)pQueryMsg + pQueryMsg->tsOffset + pQueryMsg->tsLen; + } + *sql = strndup(pMsg, pQueryMsg->sqlstrLen); if (!validateQuerySourceCols(pQueryMsg, *pExpr, *tagCols)) { diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java index 880bcbfc6fcda29c7225090707d694b3d0f7d4ea..91639e85f3b488a5ded5e1253b429fa874b091e2 100644 --- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java @@ -14,13 +14,14 @@ public class JdbcRestfulDemo { String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; Properties properties = new Properties(); - properties.setProperty("charset", "UTF-8"); - properties.setProperty("locale", "en_US.UTF-8"); - properties.setProperty("timezone", "UTC-8"); +// properties.setProperty("charset", "UTF-8"); +// properties.setProperty("locale", "en_US.UTF-8"); +// properties.setProperty("timezone", "UTC-8"); Connection conn = DriverManager.getConnection(url, properties); Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists restful_test"); stmt.execute("create database if not exists restful_test"); stmt.execute("use restful_test"); stmt.execute("create table restful_test.weather(ts timestamp, temperature float) tags(location nchar(64))"); @@ -34,6 +35,7 @@ public class JdbcRestfulDemo { System.out.println(); } + rs.close(); stmt.close(); conn.close(); } catch (ClassNotFoundException e) { diff --git a/tests/examples/JDBC/connectionPools/pom.xml b/tests/examples/JDBC/connectionPools/pom.xml index 2793f0a83ddc88711796c133802c82979ae14be5..fbee256067dcc3dec5e5888384d5ca36d3b66066 100644 --- a/tests/examples/JDBC/connectionPools/pom.xml +++ b/tests/examples/JDBC/connectionPools/pom.xml @@ -12,7 +12,7 @@ com.taosdata.jdbc taos-jdbcdriver - 2.0.11 + 2.0.17 @@ -44,7 +44,6 @@ c3p0 0.9.5.4 - log4j