[TD-4480]<fix>: fix DatabaseMetaData get wrong column value (#6381)
* [TD-4480]<fix>: fix DatabaseMetaData has wrong column index bug * change * change * change * change * change * change * change * change * change * change * change * change * change * change test cases * change test cases * change * change * change * change * change * change jdbc version * change * change * change * change * change * change * change * change
This commit is contained in:
parent
efa03cb0f4
commit
04f1ffad9b
|
@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
|
||||||
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
|
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
|
||||||
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
|
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
|
||||||
IF (TD_MVN_INSTALLED)
|
IF (TD_MVN_INSTALLED)
|
||||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.29.jar DESTINATION connector/jdbc)
|
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.30.jar DESTINATION connector/jdbc)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
ELSEIF (TD_DARWIN)
|
ELSEIF (TD_DARWIN)
|
||||||
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
|
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
|
||||||
|
|
|
@ -8,10 +8,9 @@ IF (TD_MVN_INSTALLED)
|
||||||
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
|
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
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.29.jar ${LIBRARY_OUTPUT_PATH}
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.30.jar ${LIBRARY_OUTPUT_PATH}
|
||||||
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
||||||
COMMENT "build jdbc driver")
|
COMMENT "build jdbc driver")
|
||||||
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
|
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.29</version>
|
<version>2.0.30</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>JDBCDriver</name>
|
<name>JDBCDriver</name>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.29</version>
|
<version>2.0.30</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>JDBCDriver</name>
|
<name>JDBCDriver</name>
|
||||||
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,7 @@
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xpath.internal.operations.Bool;
|
||||||
|
|
||||||
import java.sql.ParameterMetaData;
|
import java.sql.ParameterMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
@ -49,6 +51,22 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P
|
||||||
if (param < 1 && param >= parameters.length)
|
if (param < 1 && param >= parameters.length)
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
|
||||||
|
|
||||||
|
if (parameters[param - 1] instanceof Boolean)
|
||||||
|
return TSDBConstants.BOOLEAN_PRECISION;
|
||||||
|
if (parameters[param - 1] instanceof Byte)
|
||||||
|
return TSDBConstants.TINYINT_PRECISION;
|
||||||
|
if (parameters[param - 1] instanceof Short)
|
||||||
|
return TSDBConstants.SMALLINT_PRECISION;
|
||||||
|
if (parameters[param - 1] instanceof Integer)
|
||||||
|
return TSDBConstants.INT_PRECISION;
|
||||||
|
if (parameters[param - 1] instanceof Long)
|
||||||
|
return TSDBConstants.BIGINT_PRECISION;
|
||||||
|
if (parameters[param - 1] instanceof Timestamp)
|
||||||
|
return TSDBConstants.TIMESTAMP_MS_PRECISION;
|
||||||
|
if (parameters[param - 1] instanceof Float)
|
||||||
|
return TSDBConstants.FLOAT_PRECISION;
|
||||||
|
if (parameters[param - 1] instanceof Double)
|
||||||
|
return TSDBConstants.DOUBLE_PRECISION;
|
||||||
if (parameters[param - 1] instanceof String)
|
if (parameters[param - 1] instanceof String)
|
||||||
return ((String) parameters[param - 1]).length();
|
return ((String) parameters[param - 1]).length();
|
||||||
if (parameters[param - 1] instanceof byte[])
|
if (parameters[param - 1] instanceof byte[])
|
||||||
|
@ -60,6 +78,11 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P
|
||||||
public int getScale(int param) throws SQLException {
|
public int getScale(int param) throws SQLException {
|
||||||
if (param < 1 && param >= parameters.length)
|
if (param < 1 && param >= parameters.length)
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
|
||||||
|
|
||||||
|
if (parameters[param - 1] instanceof Float)
|
||||||
|
return TSDBConstants.FLOAT_SCALE;
|
||||||
|
if (parameters[param - 1] instanceof Double)
|
||||||
|
return TSDBConstants.DOUBLE_SCALE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,10 +66,16 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet
|
||||||
public abstract byte[] getBytes(int columnIndex) throws SQLException;
|
public abstract byte[] getBytes(int columnIndex) throws SQLException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract Date getDate(int columnIndex) throws SQLException;
|
public Date getDate(int columnIndex) throws SQLException {
|
||||||
|
Timestamp timestamp = getTimestamp(columnIndex);
|
||||||
|
return timestamp == null ? null : new Date(timestamp.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract Time getTime(int columnIndex) throws SQLException;
|
public Time getTime(int columnIndex) throws SQLException {
|
||||||
|
Timestamp timestamp = getTimestamp(columnIndex);
|
||||||
|
return timestamp == null ? null : new Time(timestamp.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract Timestamp getTimestamp(int columnIndex) throws SQLException;
|
public abstract Timestamp getTimestamp(int columnIndex) throws SQLException;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -41,14 +41,14 @@ public abstract class TSDBConstants {
|
||||||
public static final int TSDB_DATA_TYPE_BINARY = 8;
|
public static final int TSDB_DATA_TYPE_BINARY = 8;
|
||||||
public static final int TSDB_DATA_TYPE_TIMESTAMP = 9;
|
public static final int TSDB_DATA_TYPE_TIMESTAMP = 9;
|
||||||
public static final int TSDB_DATA_TYPE_NCHAR = 10;
|
public static final int TSDB_DATA_TYPE_NCHAR = 10;
|
||||||
/*
|
/**
|
||||||
系统增加新的无符号数据类型,分别是:
|
* 系统增加新的无符号数据类型,分别是:
|
||||||
unsigned tinyint, 数值范围:0-254, NULL 为255
|
* unsigned tinyint, 数值范围:0-254, NULL 为255
|
||||||
unsigned smallint,数值范围: 0-65534, NULL 为65535
|
* unsigned smallint,数值范围: 0-65534, NULL 为65535
|
||||||
unsigned int,数值范围:0-4294967294,NULL 为4294967295u
|
* unsigned int,数值范围:0-4294967294,NULL 为4294967295u
|
||||||
unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u。
|
* unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u。
|
||||||
example:
|
* example:
|
||||||
create table tb(ts timestamp, a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned);
|
* create table tb(ts timestamp, a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned);
|
||||||
*/
|
*/
|
||||||
public static final int TSDB_DATA_TYPE_UTINYINT = 11; //unsigned tinyint
|
public static final int TSDB_DATA_TYPE_UTINYINT = 11; //unsigned tinyint
|
||||||
public static final int TSDB_DATA_TYPE_USMALLINT = 12; //unsigned smallint
|
public static final int TSDB_DATA_TYPE_USMALLINT = 12; //unsigned smallint
|
||||||
|
@ -57,6 +57,47 @@ public abstract class TSDBConstants {
|
||||||
// nchar column max length
|
// nchar column max length
|
||||||
public static final int maxFieldSize = 16 * 1024;
|
public static final int maxFieldSize = 16 * 1024;
|
||||||
|
|
||||||
|
// precision for data types
|
||||||
|
public static final int BOOLEAN_PRECISION = 1;
|
||||||
|
public static final int TINYINT_PRECISION = 4;
|
||||||
|
public static final int SMALLINT_PRECISION = 6;
|
||||||
|
public static final int INT_PRECISION = 11;
|
||||||
|
public static final int BIGINT_PRECISION = 20;
|
||||||
|
public static final int FLOAT_PRECISION = 12;
|
||||||
|
public static final int DOUBLE_PRECISION = 22;
|
||||||
|
public static final int TIMESTAMP_MS_PRECISION = 23;
|
||||||
|
public static final int TIMESTAMP_US_PRECISION = 26;
|
||||||
|
// scale for data types
|
||||||
|
public static final int FLOAT_SCALE = 31;
|
||||||
|
public static final int DOUBLE_SCALE = 31;
|
||||||
|
|
||||||
|
public static int typeName2JdbcType(String type) {
|
||||||
|
switch (type.toUpperCase()) {
|
||||||
|
case "TIMESTAMP":
|
||||||
|
return Types.TIMESTAMP;
|
||||||
|
case "INT":
|
||||||
|
return Types.INTEGER;
|
||||||
|
case "BIGINT":
|
||||||
|
return Types.BIGINT;
|
||||||
|
case "FLOAT":
|
||||||
|
return Types.FLOAT;
|
||||||
|
case "DOUBLE":
|
||||||
|
return Types.DOUBLE;
|
||||||
|
case "BINARY":
|
||||||
|
return Types.BINARY;
|
||||||
|
case "SMALLINT":
|
||||||
|
return Types.SMALLINT;
|
||||||
|
case "TINYINT":
|
||||||
|
return Types.TINYINT;
|
||||||
|
case "BOOL":
|
||||||
|
return Types.BOOLEAN;
|
||||||
|
case "NCHAR":
|
||||||
|
return Types.NCHAR;
|
||||||
|
default:
|
||||||
|
return Types.NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int taosType2JdbcType(int taosType) throws SQLException {
|
public static int taosType2JdbcType(int taosType) throws SQLException {
|
||||||
switch (taosType) {
|
switch (taosType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
|
import com.taosdata.jdbc.utils.TaosInfo;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.SQLWarning;
|
import java.sql.SQLWarning;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.taosdata.jdbc.utils.TaosInfo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JNI connector
|
* JNI connector
|
||||||
*/
|
*/
|
||||||
|
@ -194,7 +194,9 @@ public class TSDBJNIConnector {
|
||||||
* Get schema metadata
|
* Get schema metadata
|
||||||
*/
|
*/
|
||||||
public int getSchemaMetaData(long resultSet, List<ColumnMetaData> columnMetaData) {
|
public int getSchemaMetaData(long resultSet, List<ColumnMetaData> columnMetaData) {
|
||||||
return this.getSchemaMetaDataImp(this.taos, resultSet, columnMetaData);
|
int ret = this.getSchemaMetaDataImp(this.taos, resultSet, columnMetaData);
|
||||||
|
columnMetaData.stream().forEach(column -> column.setColIndex(column.getColIndex() + 1));
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native int getSchemaMetaDataImp(long connection, long resultSet, List<ColumnMetaData> columnMetaData);
|
private native int getSchemaMetaDataImp(long connection, long resultSet, List<ColumnMetaData> columnMetaData);
|
||||||
|
@ -276,14 +278,23 @@ public class TSDBJNIConnector {
|
||||||
private native int validateCreateTableSqlImp(long connection, byte[] sqlBytes);
|
private native int validateCreateTableSqlImp(long connection, byte[] sqlBytes);
|
||||||
|
|
||||||
public long prepareStmt(String sql) throws SQLException {
|
public long prepareStmt(String sql) throws SQLException {
|
||||||
Long stmt = prepareStmtImp(sql.getBytes(), this.taos);
|
Long stmt;
|
||||||
if (stmt == TSDBConstants.JNI_TDENGINE_ERROR) {
|
try {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_SQL);
|
stmt = prepareStmtImp(sql.getBytes(), this.taos);
|
||||||
} else if (stmt == TSDBConstants.JNI_CONNECTION_NULL) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stmt == TSDBConstants.JNI_CONNECTION_NULL) {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
} else if (stmt == TSDBConstants.JNI_SQL_NULL) {
|
}
|
||||||
|
|
||||||
|
if (stmt == TSDBConstants.JNI_SQL_NULL) {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_SQL_NULL);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_SQL_NULL);
|
||||||
} else if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) {
|
}
|
||||||
|
|
||||||
|
if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,9 +205,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
|
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
|
||||||
if (isClosed())
|
setObject(parameterIndex, x.doubleValue());
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,16 +220,12 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDate(int parameterIndex, Date x) throws SQLException {
|
public void setDate(int parameterIndex, Date x) throws SQLException {
|
||||||
if (isClosed())
|
setObject(parameterIndex, new Timestamp(x.getTime()));
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTime(int parameterIndex, Time x) throws SQLException {
|
public void setTime(int parameterIndex, Time x) throws SQLException {
|
||||||
if (isClosed())
|
setObject(parameterIndex, new Timestamp(x.getTime()));
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -283,7 +277,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
if (parameterIndex < 1 && parameterIndex >= parameters.length) {
|
if (parameterIndex < 1 && parameterIndex >= parameters.length) {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters[parameterIndex - 1] = x;
|
parameters[parameterIndex - 1] = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,9 +343,9 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSetMetaData getMetaData() throws SQLException {
|
public ResultSetMetaData getMetaData() throws SQLException {
|
||||||
if (isClosed())
|
if (this.getResultSet() == null)
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
return null;
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
return getResultSet().getMetaData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -396,10 +389,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
|
|
||||||
if (parameterMetaData == null) {
|
return new TSDBParameterMetaData(parameters);
|
||||||
this.parameterMetaData = new TSDBParameterMetaData(parameters);
|
|
||||||
}
|
|
||||||
return this.parameterMetaData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -411,9 +401,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNString(int parameterIndex, String value) throws SQLException {
|
public void setNString(int parameterIndex, String value) throws SQLException {
|
||||||
if (isClosed())
|
setString(parameterIndex, value);
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -563,12 +551,15 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
public boolean isTypeSet() {
|
public boolean isTypeSet() {
|
||||||
return this.typeIsSet;
|
return this.typeIsSet;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
private static class TableTagInfo {
|
private static class TableTagInfo {
|
||||||
private boolean isNull;
|
private boolean isNull;
|
||||||
private Object value;
|
private Object value;
|
||||||
private int type;
|
private int type;
|
||||||
|
|
||||||
public TableTagInfo(Object value, int type) {
|
public TableTagInfo(Object value, int type) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -579,7 +570,9 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
info.isNull = true;
|
info.isNull = true;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
public void setTableName(String name) {
|
public void setTableName(String name) {
|
||||||
this.tableName = name;
|
this.tableName = name;
|
||||||
|
@ -666,8 +659,8 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
public <T> void setValueImpl(int columnIndex, ArrayList<T> list, int type, int bytes) throws SQLException {
|
public <T> void setValueImpl(int columnIndex, ArrayList<T> list, int type, int bytes) throws SQLException {
|
||||||
if (this.colData.size() == 0) {
|
if (this.colData.size() == 0) {
|
||||||
this.colData.addAll(Collections.nCopies(this.parameters.length - 1 - this.tableTags.size(), null));
|
this.colData.addAll(Collections.nCopies(this.parameters.length - 1 - this.tableTags.size(), null));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnInfo col = (ColumnInfo) this.colData.get(columnIndex);
|
ColumnInfo col = (ColumnInfo) this.colData.get(columnIndex);
|
||||||
if (col == null) {
|
if (col == null) {
|
||||||
ColumnInfo p = new ColumnInfo();
|
ColumnInfo p = new ColumnInfo();
|
||||||
|
@ -994,7 +987,8 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types");
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types");
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
connector.bindColumnDataArray(this.nativeStmtHandle, colDataList, lengthList, isNullList, col1.type, col1.bytes, rows, i);
|
connector.bindColumnDataArray(this.nativeStmtHandle, colDataList, lengthList, isNullList, col1.type, col1.bytes, rows, i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,9 +133,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return this.blockData.getString(columnIndex - 1);
|
return this.blockData.getString(columnIndex - 1);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getString(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
|
res = this.rowData.getString(columnIndex, nativeType);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -147,9 +148,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return this.blockData.getBoolean(columnIndex - 1);
|
return this.blockData.getBoolean(columnIndex - 1);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getBoolean(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
|
res = this.rowData.getBoolean(columnIndex, nativeType);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -161,9 +163,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return (byte) this.blockData.getInt(columnIndex - 1);
|
return (byte) this.blockData.getInt(columnIndex - 1);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = (byte) this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
|
res = (byte) this.rowData.getInt(columnIndex, nativeType);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -175,9 +178,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return (short) this.blockData.getInt(columnIndex - 1);
|
return (short) this.blockData.getInt(columnIndex - 1);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = (short) this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
|
res = (short) this.rowData.getInt(columnIndex, nativeType);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -189,9 +193,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return this.blockData.getInt(columnIndex - 1);
|
return this.blockData.getInt(columnIndex - 1);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
|
res = this.rowData.getInt(columnIndex, nativeType);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -203,13 +209,15 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return this.blockData.getLong(columnIndex - 1);
|
return this.blockData.getLong(columnIndex - 1);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
Object value = this.rowData.get(columnIndex - 1);
|
Object value = this.rowData.getObject(columnIndex);
|
||||||
if (value instanceof Timestamp)
|
if (value instanceof Timestamp) {
|
||||||
res = ((Timestamp) value).getTime();
|
res = ((Timestamp) value).getTime();
|
||||||
else
|
} else {
|
||||||
res = this.rowData.getLong(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
|
res = this.rowData.getLong(columnIndex, nativeType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -221,9 +229,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return (float) this.blockData.getDouble(columnIndex - 1);
|
return (float) this.blockData.getDouble(columnIndex - 1);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
if (!lastWasNull)
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getFloat(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
|
res = this.rowData.getFloat(columnIndex, nativeType);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -235,9 +245,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return this.blockData.getDouble(columnIndex - 1);
|
return this.blockData.getDouble(columnIndex - 1);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getDouble(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
|
res = this.rowData.getDouble(columnIndex, nativeType);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -245,34 +256,27 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public byte[] getBytes(int columnIndex) throws SQLException {
|
public byte[] getBytes(int columnIndex) throws SQLException {
|
||||||
checkAvailability(columnIndex, this.columnMetaDataList.size());
|
checkAvailability(columnIndex, this.columnMetaDataList.size());
|
||||||
|
|
||||||
Object value = this.rowData.get(columnIndex - 1);
|
Object value = this.rowData.getObject(columnIndex);
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
int colType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
switch (colType) {
|
switch (nativeType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
return Longs.toByteArray((Long) value);
|
return Longs.toByteArray((long) value);
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
return Ints.toByteArray((int) value);
|
return Ints.toByteArray((int) value);
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
return Shorts.toByteArray((Short) value);
|
return Shorts.toByteArray((short) value);
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
return new byte[]{(byte) value};
|
return new byte[]{(byte) value};
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
return (byte[]) value;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
|
default:
|
||||||
return value.toString().getBytes();
|
return value.toString().getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Date getDate(int columnIndex) throws SQLException {
|
|
||||||
Timestamp timestamp = getTimestamp(columnIndex);
|
|
||||||
return timestamp == null ? null : new Date(timestamp.getTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Time getTime(int columnIndex) throws SQLException {
|
|
||||||
Timestamp timestamp = getTimestamp(columnIndex);
|
|
||||||
return timestamp == null ? null : new Time(timestamp.getTime());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp getTimestamp(int columnIndex) throws SQLException {
|
public Timestamp getTimestamp(int columnIndex) throws SQLException {
|
||||||
|
@ -282,9 +286,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return this.blockData.getTimestamp(columnIndex - 1);
|
return this.blockData.getTimestamp(columnIndex - 1);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
res = this.rowData.getTimestamp(columnIndex - 1);
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
|
res = this.rowData.getTimestamp(columnIndex, nativeType);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -304,13 +309,9 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return this.blockData.get(columnIndex - 1);
|
return this.blockData.get(columnIndex - 1);
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
int colType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
res = this.rowData.getObject(columnIndex);
|
||||||
if (colType == TSDBConstants.TSDB_DATA_TYPE_BINARY)
|
|
||||||
res = ((String) this.rowData.get(columnIndex - 1)).getBytes();
|
|
||||||
else
|
|
||||||
res = this.rowData.get(columnIndex - 1);
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -318,7 +319,7 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public int findColumn(String columnLabel) throws SQLException {
|
public int findColumn(String columnLabel) throws SQLException {
|
||||||
for (ColumnMetaData colMetaData : this.columnMetaDataList) {
|
for (ColumnMetaData colMetaData : this.columnMetaDataList) {
|
||||||
if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) {
|
if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) {
|
||||||
return colMetaData.getColIndex() + 1;
|
return colMetaData.getColIndex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||||
|
@ -329,25 +330,25 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (this.getBatchFetch())
|
if (this.getBatchFetch())
|
||||||
return new BigDecimal(this.blockData.getLong(columnIndex - 1));
|
return new BigDecimal(this.blockData.getLong(columnIndex - 1));
|
||||||
|
|
||||||
this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
|
this.lastWasNull = this.rowData.wasNull(columnIndex);
|
||||||
BigDecimal res = null;
|
BigDecimal res = null;
|
||||||
if (!lastWasNull) {
|
if (!lastWasNull) {
|
||||||
int colType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
|
||||||
switch (colType) {
|
switch (nativeType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
res = new BigDecimal(Long.valueOf(this.rowData.get(columnIndex - 1).toString()));
|
res = new BigDecimal(Long.valueOf(this.rowData.getObject(columnIndex).toString()));
|
||||||
break;
|
break;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
res = new BigDecimal(Double.valueOf(this.rowData.get(columnIndex - 1).toString()));
|
res = new BigDecimal(Double.valueOf(this.rowData.getObject(columnIndex).toString()));
|
||||||
break;
|
break;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
return new BigDecimal(((Timestamp) this.rowData.get(columnIndex - 1)).getTime());
|
return new BigDecimal(((Timestamp) this.rowData.getObject(columnIndex)).getTime());
|
||||||
default:
|
default:
|
||||||
res = new BigDecimal(this.rowData.get(columnIndex - 1).toString());
|
res = new BigDecimal(this.rowData.getObject(columnIndex).toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -113,6 +113,7 @@ public class TSDBResultSetMetaData extends WrapperImpl implements ResultSetMetaD
|
||||||
|
|
||||||
ColumnMetaData columnMetaData = this.colMetaDataList.get(column - 1);
|
ColumnMetaData columnMetaData = this.colMetaDataList.get(column - 1);
|
||||||
switch (columnMetaData.getColType()) {
|
switch (columnMetaData.getColType()) {
|
||||||
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
return 5;
|
return 5;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
|
import com.taosdata.jdbc.utils.NullType;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
@ -22,11 +24,13 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class TSDBResultSetRowData {
|
public class TSDBResultSetRowData {
|
||||||
|
|
||||||
private ArrayList<Object> data;
|
private ArrayList<Object> data;
|
||||||
private int colSize = 0;
|
private int colSize;
|
||||||
|
|
||||||
public TSDBResultSetRowData(int colSize) {
|
public TSDBResultSetRowData(int colSize) {
|
||||||
this.setColSize(colSize);
|
this.colSize = colSize;
|
||||||
|
this.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
@ -41,68 +45,104 @@ public class TSDBResultSetRowData {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean wasNull(int col) {
|
public boolean wasNull(int col) {
|
||||||
return data.get(col) == null;
|
return data.get(col - 1) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
|
||||||
|
*/
|
||||||
|
public void setBooleanValue(int col, boolean value) {
|
||||||
|
setBoolean(col - 1, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
|
||||||
|
*/
|
||||||
public void setBoolean(int col, boolean value) {
|
public void setBoolean(int col, boolean value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBoolean(int col, int srcType) throws SQLException {
|
public boolean getBoolean(int col, int nativeType) throws SQLException {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col - 1);
|
||||||
|
|
||||||
switch (srcType) {
|
switch (nativeType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
return (Boolean) obj;
|
return (Boolean) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
|
||||||
return ((Float) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
|
||||||
return ((Double) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
return ((Byte) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
return ((Byte) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
return ((Short) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
return ((Short) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
return ((Integer) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
return ((Integer) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
return ((Long) obj) == 1L ? Boolean.TRUE : Boolean.FALSE;
|
return ((Long) obj) == 1L ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
|
||||||
|
return obj.toString().contains("1");
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
|
||||||
|
*/
|
||||||
|
public void setByteValue(int colIndex, byte value) {
|
||||||
|
setByte(colIndex - 1, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
|
||||||
|
*/
|
||||||
public void setByte(int col, byte value) {
|
public void setByte(int col, byte value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
|
||||||
|
*/
|
||||||
|
public void setShortValue(int colIndex, short value) {
|
||||||
|
setShort(colIndex - 1, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
|
||||||
|
*/
|
||||||
public void setShort(int col, short value) {
|
public void setShort(int col, short value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
|
||||||
|
*/
|
||||||
|
public void setIntValue(int colIndex, int value) {
|
||||||
|
setInt(colIndex - 1, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
|
||||||
|
*/
|
||||||
public void setInt(int col, int value) {
|
public void setInt(int col, int value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
public int getInt(int col, int nativeType) throws SQLException {
|
||||||
public int getInt(int col, int srcType) throws SQLException {
|
Object obj = data.get(col - 1);
|
||||||
Object obj = data.get(col);
|
if (obj == null)
|
||||||
|
return NullType.getIntNull();
|
||||||
|
|
||||||
switch (srcType) {
|
switch (nativeType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
|
||||||
return ((Float) obj).intValue();
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
|
||||||
return ((Double) obj).intValue();
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
return (Byte) obj;
|
return (Byte) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
return (Short) obj;
|
return (Short) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
return (Integer) obj;
|
return (Integer) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
return ((Long) obj).intValue();
|
return ((Long) obj).intValue();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
@ -131,33 +171,46 @@ public class TSDBResultSetRowData {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
return Long.valueOf(value).intValue();
|
return Long.valueOf(value).intValue();
|
||||||
}
|
}
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
|
return ((Float) obj).intValue();
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
return ((Double) obj).intValue();
|
||||||
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
|
||||||
|
*/
|
||||||
|
public void setLongValue(int colIndex, long value) {
|
||||||
|
setLong(colIndex - 1, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
|
||||||
|
*/
|
||||||
public void setLong(int col, long value) {
|
public void setLong(int col, long value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLong(int col, int srcType) throws SQLException {
|
public long getLong(int col, int nativeType) throws SQLException {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col - 1);
|
||||||
|
if (obj == null) {
|
||||||
|
return NullType.getBigIntNull();
|
||||||
|
}
|
||||||
|
|
||||||
switch (srcType) {
|
switch (nativeType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
|
||||||
return ((Float) obj).longValue();
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
|
||||||
return ((Double) obj).longValue();
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
return (Byte) obj;
|
return (Byte) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
return (Short) obj;
|
return (Short) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
return (Integer) obj;
|
return (Integer) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
return (Long) obj;
|
return (Long) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
@ -186,19 +239,35 @@ public class TSDBResultSetRowData {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
|
return ((Float) obj).longValue();
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
return ((Double) obj).longValue();
|
||||||
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
|
||||||
|
*/
|
||||||
|
public void setFloatValue(int colIndex, float value) {
|
||||||
|
setFloat(colIndex - 1, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
|
||||||
|
*/
|
||||||
public void setFloat(int col, float value) {
|
public void setFloat(int col, float value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getFloat(int col, int srcType) {
|
public float getFloat(int col, int nativeType) {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col - 1);
|
||||||
|
if (obj == null)
|
||||||
|
return NullType.getFloatNull();
|
||||||
|
|
||||||
switch (srcType) {
|
switch (nativeType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
|
@ -214,19 +283,31 @@ public class TSDBResultSetRowData {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
return (Long) obj;
|
return (Long) obj;
|
||||||
|
default:
|
||||||
|
return NullType.getFloatNull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/**
|
||||||
|
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
|
||||||
|
*/
|
||||||
|
public void setDoubleValue(int colIndex, double value) {
|
||||||
|
setDouble(colIndex - 1, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
|
||||||
|
*/
|
||||||
public void setDouble(int col, double value) {
|
public void setDouble(int col, double value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDouble(int col, int srcType) {
|
public double getDouble(int col, int nativeType) {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col - 1);
|
||||||
|
if (obj == null)
|
||||||
|
return NullType.getDoubleNull();
|
||||||
|
|
||||||
switch (srcType) {
|
switch (nativeType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
|
@ -242,16 +323,46 @@ public class TSDBResultSetRowData {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
return (Long) obj;
|
return (Long) obj;
|
||||||
|
default:
|
||||||
|
return NullType.getDoubleNull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/**
|
||||||
|
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
|
||||||
|
*/
|
||||||
|
public void setStringValue(int colIndex, String value) {
|
||||||
|
data.set(colIndex - 1, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
|
||||||
|
*/
|
||||||
public void setString(int col, String value) {
|
public void setString(int col, String value) {
|
||||||
data.set(col, value);
|
// TODO:
|
||||||
|
// !!!NOTE!!!
|
||||||
|
// this is very confusing problem which related to JNI-method implementation,
|
||||||
|
// the JNI method return a String(encoded in UTF) for BINARY value, which means the JNI method will invoke
|
||||||
|
// this setString(int, String) to handle BINARY value, we need to build a byte[] with default charsetEncoding
|
||||||
|
data.set(col, value == null ? null : value.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
|
||||||
|
*/
|
||||||
|
public void setByteArrayValue(int colIndex, byte[] value) {
|
||||||
|
setByteArray(colIndex - 1, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
|
||||||
|
*/
|
||||||
public void setByteArray(int col, byte[] value) {
|
public void setByteArray(int col, byte[] value) {
|
||||||
|
// TODO:
|
||||||
|
// !!!NOTE!!!
|
||||||
|
// this is very confusing problem which related to JNI-method implementation,
|
||||||
|
// the JNI method return a byte[] for NCHAR value, which means the JNI method will invoke
|
||||||
|
// this setByteArr(int, byte[]) to handle NCHAR value, we need to build a String with charsetEncoding by TaosGlobalConfig
|
||||||
try {
|
try {
|
||||||
data.set(col, new String(value, TaosGlobalConfig.getCharset()));
|
data.set(col, new String(value, TaosGlobalConfig.getCharset()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -259,47 +370,56 @@ public class TSDBResultSetRowData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public String getString(int col, int nativeType) {
|
||||||
* The original type may not be a string type, but will be converted to by calling this method
|
Object obj = data.get(col - 1);
|
||||||
*
|
if (obj == null)
|
||||||
* @param col column index
|
return null;
|
||||||
* @return
|
|
||||||
*/
|
switch (nativeType) {
|
||||||
public String getString(int col, int srcType) {
|
|
||||||
switch (srcType) {
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
|
||||||
return (String) data.get(col);
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: {
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: {
|
||||||
Byte value = new Byte(String.valueOf(data.get(col)));
|
Byte value = new Byte(String.valueOf(obj));
|
||||||
if (value >= 0)
|
if (value >= 0)
|
||||||
return value.toString();
|
return value.toString();
|
||||||
return Integer.toString(value & 0xff);
|
return Integer.toString(value & 0xff);
|
||||||
}
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: {
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: {
|
||||||
Short value = new Short(String.valueOf(data.get(col)));
|
Short value = new Short(String.valueOf(obj));
|
||||||
if (value >= 0)
|
if (value >= 0)
|
||||||
return value.toString();
|
return value.toString();
|
||||||
return Integer.toString(value & 0xffff);
|
return Integer.toString(value & 0xffff);
|
||||||
}
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_UINT: {
|
case TSDBConstants.TSDB_DATA_TYPE_UINT: {
|
||||||
Integer value = new Integer(String.valueOf(data.get(col)));
|
Integer value = new Integer(String.valueOf(obj));
|
||||||
if (value >= 0)
|
if (value >= 0)
|
||||||
return value.toString();
|
return value.toString();
|
||||||
return Long.toString(value & 0xffffffffl);
|
return Long.toString(value & 0xffffffffl);
|
||||||
}
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
|
||||||
Long value = new Long(String.valueOf(data.get(col)));
|
Long value = new Long(String.valueOf(obj));
|
||||||
if (value >= 0)
|
if (value >= 0)
|
||||||
return value.toString();
|
return value.toString();
|
||||||
long lowValue = value & 0x7fffffffffffffffL;
|
long lowValue = value & 0x7fffffffffffffffL;
|
||||||
return BigDecimal.valueOf(lowValue).add(BigDecimal.valueOf(Long.MAX_VALUE)).add(BigDecimal.valueOf(1)).toString();
|
return BigDecimal.valueOf(lowValue).add(BigDecimal.valueOf(Long.MAX_VALUE)).add(BigDecimal.valueOf(1)).toString();
|
||||||
}
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
return new String((byte[]) obj);
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
|
return (String) obj;
|
||||||
default:
|
default:
|
||||||
return String.valueOf(data.get(col));
|
return String.valueOf(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
|
||||||
|
*/
|
||||||
|
public void setTimestampValue(int colIndex, long value) {
|
||||||
|
setTimestamp(colIndex - 1, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
|
||||||
|
*/
|
||||||
public void setTimestamp(int col, long ts) {
|
public void setTimestamp(int col, long ts) {
|
||||||
//TODO: this implementation contains logical error
|
//TODO: this implementation contains logical error
|
||||||
// when precision is us the (long ts) is 16 digital number
|
// when precision is us the (long ts) is 16 digital number
|
||||||
|
@ -316,28 +436,20 @@ public class TSDBResultSetRowData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp getTimestamp(int col) {
|
public Timestamp getTimestamp(int col, int nativeType) {
|
||||||
return (Timestamp) data.get(col);
|
Object obj = data.get(col - 1);
|
||||||
|
if (obj == null)
|
||||||
|
return null;
|
||||||
|
switch (nativeType) {
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return new Timestamp((Long) obj);
|
||||||
|
default:
|
||||||
|
return (Timestamp) obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(int col) {
|
public Object getObject(int col) {
|
||||||
return data.get(col);
|
return data.get(col - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColSize() {
|
|
||||||
return colSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setColSize(int colSize) {
|
|
||||||
this.colSize = colSize;
|
|
||||||
this.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Object> getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(ArrayList<Object> data) {
|
|
||||||
this.data = (ArrayList<Object>) data.clone();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,14 @@ public class TSDBStatement extends AbstractStatement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultSet executeQuery(String sql) throws SQLException {
|
public ResultSet executeQuery(String sql) throws SQLException {
|
||||||
// check if closed
|
|
||||||
if (isClosed()) {
|
if (isClosed()) {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
}
|
}
|
||||||
|
//TODO:
|
||||||
//TODO: 如果在executeQuery方法中执行insert语句,那么先执行了SQL,再通过pSql来检查是否为一个insert语句,但这个insert SQL已经执行成功了
|
// this is an unreasonable implementation, if the paratemer is a insert statement,
|
||||||
|
// the JNI connector will execute the sql at first and return a pointer: pSql,
|
||||||
|
// we use this pSql and invoke the isUpdateQuery(long pSql) method to decide .
|
||||||
|
// but the insert sql is already executed in database.
|
||||||
//execute query
|
//execute query
|
||||||
long pSql = this.connection.getConnector().executeQuery(sql);
|
long pSql = this.connection.getConnector().executeQuery(sql);
|
||||||
// if pSql is create/insert/update/delete/alter SQL
|
// if pSql is create/insert/update/delete/alter SQL
|
||||||
|
|
|
@ -95,16 +95,7 @@ public class Utils {
|
||||||
public static String getNativeSql(String rawSql, Object[] parameters) {
|
public static String getNativeSql(String rawSql, Object[] parameters) {
|
||||||
// toLowerCase
|
// toLowerCase
|
||||||
String preparedSql = rawSql.trim().toLowerCase();
|
String preparedSql = rawSql.trim().toLowerCase();
|
||||||
|
String[] clause = new String[]{"values\\s*\\(.*?\\)", "tags\\s*\\(.*?\\)", "where\\s*.*"};
|
||||||
String[] clause = new String[0];
|
|
||||||
if (SqlSyntaxValidator.isInsertSql(preparedSql)) {
|
|
||||||
// insert or import
|
|
||||||
clause = new String[]{"values\\s*\\(.*?\\)", "tags\\s*\\(.*?\\)"};
|
|
||||||
}
|
|
||||||
if (SqlSyntaxValidator.isSelectSql(preparedSql)) {
|
|
||||||
// select
|
|
||||||
clause = new String[]{"where\\s*.*"};
|
|
||||||
}
|
|
||||||
Map<Integer, Integer> placeholderPositions = new HashMap<>();
|
Map<Integer, Integer> placeholderPositions = new HashMap<>();
|
||||||
RangeSet<Integer> clauseRangeSet = TreeRangeSet.create();
|
RangeSet<Integer> clauseRangeSet = TreeRangeSet.create();
|
||||||
findPlaceholderPosition(preparedSql, placeholderPositions);
|
findPlaceholderPosition(preparedSql, placeholderPositions);
|
||||||
|
|
|
@ -32,20 +32,34 @@ public class TSDBConnectionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void subscribe() {
|
public void runSubscribe() {
|
||||||
try {
|
try {
|
||||||
|
// given
|
||||||
TSDBConnection unwrap = conn.unwrap(TSDBConnection.class);
|
TSDBConnection unwrap = conn.unwrap(TSDBConnection.class);
|
||||||
TSDBSubscribe subscribe = unwrap.subscribe("topic1", "select * from log.log", false);
|
TSDBSubscribe subscribe = unwrap.subscribe("topic1", "select * from log.log", false);
|
||||||
|
// when
|
||||||
TSDBResultSet rs = subscribe.consume();
|
TSDBResultSet rs = subscribe.consume();
|
||||||
ResultSetMetaData metaData = rs.getMetaData();
|
ResultSetMetaData metaData = rs.getMetaData();
|
||||||
for (int count = 0; count < 10 && rs.next(); count++) {
|
|
||||||
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
// then
|
||||||
String value = rs.getString(i);
|
|
||||||
System.out.print(metaData.getColumnLabel(i) + ":" + value + "\t");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
Assert.assertNotNull(rs);
|
Assert.assertNotNull(rs);
|
||||||
|
Assert.assertEquals(4, metaData.getColumnCount());
|
||||||
|
Assert.assertEquals("ts", metaData.getColumnLabel(1));
|
||||||
|
Assert.assertEquals("level", metaData.getColumnLabel(2));
|
||||||
|
Assert.assertEquals("content", metaData.getColumnLabel(3));
|
||||||
|
Assert.assertEquals("ipaddr", metaData.getColumnLabel(4));
|
||||||
|
rs.next();
|
||||||
|
// row 1
|
||||||
|
{
|
||||||
|
Assert.assertNotNull(rs.getTimestamp(1));
|
||||||
|
Assert.assertNotNull(rs.getTimestamp("ts"));
|
||||||
|
Assert.assertNotNull(rs.getByte(2));
|
||||||
|
Assert.assertNotNull(rs.getByte("level"));
|
||||||
|
Assert.assertNotNull(rs.getString(3));
|
||||||
|
Assert.assertNotNull(rs.getString("content"));
|
||||||
|
Assert.assertNotNull(rs.getString(4));
|
||||||
|
Assert.assertNotNull(rs.getString("ipaddr"));
|
||||||
|
}
|
||||||
subscribe.close(false);
|
subscribe.close(false);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -7,9 +7,11 @@ import java.util.Properties;
|
||||||
|
|
||||||
public class TSDBDatabaseMetaDataTest {
|
public class TSDBDatabaseMetaDataTest {
|
||||||
private static final String host = "127.0.0.1";
|
private static final String host = "127.0.0.1";
|
||||||
|
private static final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
|
||||||
private static Connection connection;
|
private static Connection connection;
|
||||||
private static TSDBDatabaseMetaData metaData;
|
private static TSDBDatabaseMetaData metaData;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unwrap() throws SQLException {
|
public void unwrap() throws SQLException {
|
||||||
TSDBDatabaseMetaData unwrap = metaData.unwrap(TSDBDatabaseMetaData.class);
|
TSDBDatabaseMetaData unwrap = metaData.unwrap(TSDBDatabaseMetaData.class);
|
||||||
|
@ -33,7 +35,7 @@ public class TSDBDatabaseMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getURL() throws SQLException {
|
public void getURL() throws SQLException {
|
||||||
Assert.assertEquals("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", metaData.getURL());
|
Assert.assertEquals(url, metaData.getURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -627,17 +629,32 @@ public class TSDBDatabaseMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTables() throws SQLException {
|
public void getTables() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
ResultSet rs = metaData.getTables("log", "", null, null);
|
||||||
ResultSet tables = metaData.getTables("log", "", null, null);
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
ResultSetMetaData metaData = tables.getMetaData();
|
Assert.assertNotNull(rs);
|
||||||
while (tables.next()) {
|
rs.next();
|
||||||
System.out.print(metaData.getColumnLabel(1) + ":" + tables.getString(1) + "\t");
|
{
|
||||||
System.out.print(metaData.getColumnLabel(3) + ":" + tables.getString(3) + "\t");
|
// TABLE_CAT
|
||||||
System.out.print(metaData.getColumnLabel(4) + ":" + tables.getString(4) + "\t");
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
System.out.print(metaData.getColumnLabel(5) + ":" + tables.getString(5) + "\n");
|
Assert.assertEquals("log", rs.getString(1));
|
||||||
|
Assert.assertEquals("log", rs.getString("TABLE_CAT"));
|
||||||
|
// TABLE_SCHEM
|
||||||
|
Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2));
|
||||||
|
Assert.assertEquals(null, rs.getString(2));
|
||||||
|
Assert.assertEquals(null, rs.getString("TABLE_SCHEM"));
|
||||||
|
// TABLE_NAME
|
||||||
|
Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3));
|
||||||
|
Assert.assertNotNull(rs.getString(3));
|
||||||
|
Assert.assertNotNull(rs.getString("TABLE_NAME"));
|
||||||
|
// TABLE_TYPE
|
||||||
|
Assert.assertEquals("TABLE_TYPE", meta.getColumnLabel(4));
|
||||||
|
Assert.assertEquals("TABLE", rs.getString(4));
|
||||||
|
Assert.assertEquals("TABLE", rs.getString("TABLE_TYPE"));
|
||||||
|
// REMARKS
|
||||||
|
Assert.assertEquals("REMARKS", meta.getColumnLabel(5));
|
||||||
|
Assert.assertEquals("", rs.getString(5));
|
||||||
|
Assert.assertEquals("", rs.getString("REMARKS"));
|
||||||
}
|
}
|
||||||
System.out.println();
|
|
||||||
Assert.assertNotNull(tables);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -647,46 +664,130 @@ public class TSDBDatabaseMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCatalogs() throws SQLException {
|
public void getCatalogs() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
ResultSet rs = metaData.getCatalogs();
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
ResultSet catalogs = metaData.getCatalogs();
|
rs.next();
|
||||||
ResultSetMetaData meta = catalogs.getMetaData();
|
{
|
||||||
while (catalogs.next()) {
|
// TABLE_CAT
|
||||||
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
System.out.print(meta.getColumnLabel(i) + ": " + catalogs.getString(i));
|
Assert.assertNotNull(rs.getString(1));
|
||||||
}
|
Assert.assertNotNull(rs.getString("TABLE_CAT"));
|
||||||
System.out.println();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTableTypes() throws SQLException {
|
public void getTableTypes() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
|
||||||
|
|
||||||
ResultSet tableTypes = metaData.getTableTypes();
|
ResultSet tableTypes = metaData.getTableTypes();
|
||||||
while (tableTypes.next()) {
|
tableTypes.next();
|
||||||
System.out.println(tableTypes.getString("TABLE_TYPE"));
|
// tableTypes: table
|
||||||
|
{
|
||||||
|
Assert.assertEquals("TABLE", tableTypes.getString(1));
|
||||||
|
Assert.assertEquals("TABLE", tableTypes.getString("TABLE_TYPE"));
|
||||||
|
}
|
||||||
|
tableTypes.next();
|
||||||
|
// tableTypes: stable
|
||||||
|
{
|
||||||
|
Assert.assertEquals("STABLE", tableTypes.getString(1));
|
||||||
|
Assert.assertEquals("STABLE", tableTypes.getString("TABLE_TYPE"));
|
||||||
}
|
}
|
||||||
Assert.assertNotNull(metaData.getTableTypes());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getColumns() throws SQLException {
|
public void getColumns() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
// when
|
||||||
|
|
||||||
ResultSet columns = metaData.getColumns("log", "", "dn", "");
|
ResultSet columns = metaData.getColumns("log", "", "dn", "");
|
||||||
|
// then
|
||||||
ResultSetMetaData meta = columns.getMetaData();
|
ResultSetMetaData meta = columns.getMetaData();
|
||||||
while (columns.next()) {
|
columns.next();
|
||||||
System.out.print(meta.getColumnLabel(1) + ": " + columns.getString(1) + "\t");
|
// column: 1
|
||||||
System.out.print(meta.getColumnLabel(3) + ": " + columns.getString(3) + "\t");
|
{
|
||||||
System.out.print(meta.getColumnLabel(4) + ": " + columns.getString(4) + "\t");
|
// TABLE_CAT
|
||||||
System.out.print(meta.getColumnLabel(5) + ": " + columns.getString(5) + "\t");
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
System.out.print(meta.getColumnLabel(6) + ": " + columns.getString(6) + "\t");
|
Assert.assertEquals("log", columns.getString(1));
|
||||||
System.out.print(meta.getColumnLabel(7) + ": " + columns.getString(7) + "\t");
|
Assert.assertEquals("log", columns.getString("TABLE_CAT"));
|
||||||
System.out.print(meta.getColumnLabel(9) + ": " + columns.getString(9) + "\t");
|
// TABLE_NAME
|
||||||
System.out.print(meta.getColumnLabel(10) + ": " + columns.getString(10) + "\t");
|
Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3));
|
||||||
System.out.print(meta.getColumnLabel(11) + ": " + columns.getString(11) + "\n");
|
Assert.assertEquals("dn", columns.getString(3));
|
||||||
System.out.print(meta.getColumnLabel(12) + ": " + columns.getString(12) + "\n");
|
Assert.assertEquals("dn", columns.getString("TABLE_NAME"));
|
||||||
|
// COLUMN_NAME
|
||||||
|
Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4));
|
||||||
|
Assert.assertEquals("ts", columns.getString(4));
|
||||||
|
Assert.assertEquals("ts", columns.getString("COLUMN_NAME"));
|
||||||
|
// DATA_TYPE
|
||||||
|
Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5));
|
||||||
|
Assert.assertEquals(Types.TIMESTAMP, columns.getInt(5));
|
||||||
|
Assert.assertEquals(Types.TIMESTAMP, columns.getInt("DATA_TYPE"));
|
||||||
|
// TYPE_NAME
|
||||||
|
Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6));
|
||||||
|
Assert.assertEquals("TIMESTAMP", columns.getString(6));
|
||||||
|
Assert.assertEquals("TIMESTAMP", columns.getString("TYPE_NAME"));
|
||||||
|
// COLUMN_SIZE
|
||||||
|
Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7));
|
||||||
|
Assert.assertEquals(26, columns.getInt(7));
|
||||||
|
Assert.assertEquals(26, columns.getInt("COLUMN_SIZE"));
|
||||||
|
// DECIMAL_DIGITS
|
||||||
|
Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9));
|
||||||
|
Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9));
|
||||||
|
Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS"));
|
||||||
|
Assert.assertEquals(null, columns.getString(9));
|
||||||
|
Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS"));
|
||||||
|
// NUM_PREC_RADIX
|
||||||
|
Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10));
|
||||||
|
Assert.assertEquals(10, columns.getInt(10));
|
||||||
|
Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX"));
|
||||||
|
// NULLABLE
|
||||||
|
Assert.assertEquals("NULLABLE", meta.getColumnLabel(11));
|
||||||
|
Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt(11));
|
||||||
|
Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt("NULLABLE"));
|
||||||
|
// REMARKS
|
||||||
|
Assert.assertEquals("REMARKS", meta.getColumnLabel(12));
|
||||||
|
Assert.assertEquals(null, columns.getString(12));
|
||||||
|
Assert.assertEquals(null, columns.getString("REMARKS"));
|
||||||
|
}
|
||||||
|
columns.next();
|
||||||
|
// column: 2
|
||||||
|
{
|
||||||
|
// TABLE_CAT
|
||||||
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
|
Assert.assertEquals("log", columns.getString(1));
|
||||||
|
Assert.assertEquals("log", columns.getString("TABLE_CAT"));
|
||||||
|
// TABLE_NAME
|
||||||
|
Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3));
|
||||||
|
Assert.assertEquals("dn", columns.getString(3));
|
||||||
|
Assert.assertEquals("dn", columns.getString("TABLE_NAME"));
|
||||||
|
// COLUMN_NAME
|
||||||
|
Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4));
|
||||||
|
Assert.assertEquals("cpu_taosd", columns.getString(4));
|
||||||
|
Assert.assertEquals("cpu_taosd", columns.getString("COLUMN_NAME"));
|
||||||
|
// DATA_TYPE
|
||||||
|
Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5));
|
||||||
|
Assert.assertEquals(Types.FLOAT, columns.getInt(5));
|
||||||
|
Assert.assertEquals(Types.FLOAT, columns.getInt("DATA_TYPE"));
|
||||||
|
// TYPE_NAME
|
||||||
|
Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6));
|
||||||
|
Assert.assertEquals("FLOAT", columns.getString(6));
|
||||||
|
Assert.assertEquals("FLOAT", columns.getString("TYPE_NAME"));
|
||||||
|
// COLUMN_SIZE
|
||||||
|
Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7));
|
||||||
|
Assert.assertEquals(12, columns.getInt(7));
|
||||||
|
Assert.assertEquals(12, columns.getInt("COLUMN_SIZE"));
|
||||||
|
// DECIMAL_DIGITS
|
||||||
|
Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9));
|
||||||
|
Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9));
|
||||||
|
Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS"));
|
||||||
|
Assert.assertEquals(null, columns.getString(9));
|
||||||
|
Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS"));
|
||||||
|
// NUM_PREC_RADIX
|
||||||
|
Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10));
|
||||||
|
Assert.assertEquals(10, columns.getInt(10));
|
||||||
|
Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX"));
|
||||||
|
// NULLABLE
|
||||||
|
Assert.assertEquals("NULLABLE", meta.getColumnLabel(11));
|
||||||
|
Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt(11));
|
||||||
|
Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt("NULLABLE"));
|
||||||
|
// REMARKS
|
||||||
|
Assert.assertEquals("REMARKS", meta.getColumnLabel(12));
|
||||||
|
Assert.assertEquals(null, columns.getString(12));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -712,17 +813,35 @@ public class TSDBDatabaseMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPrimaryKeys() throws SQLException {
|
public void getPrimaryKeys() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
|
||||||
|
|
||||||
ResultSet rs = metaData.getPrimaryKeys("log", "", "dn1");
|
ResultSet rs = metaData.getPrimaryKeys("log", "", "dn1");
|
||||||
while (rs.next()) {
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME"));
|
rs.next();
|
||||||
System.out.println("COLUMN_NAME: " + rs.getString("COLUMN_NAME"));
|
{
|
||||||
System.out.println("KEY_SEQ: " + rs.getString("KEY_SEQ"));
|
// TABLE_CAT
|
||||||
System.out.println("PK_NAME: " + rs.getString("PK_NAME"));
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
|
Assert.assertEquals("log", rs.getString(1));
|
||||||
|
Assert.assertEquals("log", rs.getString("TABLE_CAT"));
|
||||||
|
// TABLE_SCHEM
|
||||||
|
Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2));
|
||||||
|
Assert.assertEquals(null, rs.getString(2));
|
||||||
|
Assert.assertEquals(null, rs.getString("TABLE_SCHEM"));
|
||||||
|
// TABLE_NAME
|
||||||
|
Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3));
|
||||||
|
Assert.assertEquals("dn1", rs.getString(3));
|
||||||
|
Assert.assertEquals("dn1", rs.getString("TABLE_NAME"));
|
||||||
|
// COLUMN_NAME
|
||||||
|
Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4));
|
||||||
|
Assert.assertEquals("ts", rs.getString(4));
|
||||||
|
Assert.assertEquals("ts", rs.getString("COLUMN_NAME"));
|
||||||
|
// KEY_SEQ
|
||||||
|
Assert.assertEquals("KEY_SEQ", meta.getColumnLabel(5));
|
||||||
|
Assert.assertEquals(1, rs.getShort(5));
|
||||||
|
Assert.assertEquals(1, rs.getShort("KEY_SEQ"));
|
||||||
|
// DATA_TYPE
|
||||||
|
Assert.assertEquals("PK_NAME", meta.getColumnLabel(6));
|
||||||
|
Assert.assertEquals("ts", rs.getString(6));
|
||||||
|
Assert.assertEquals("ts", rs.getString("PK_NAME"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertNotNull(rs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -847,14 +966,27 @@ public class TSDBDatabaseMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSuperTables() throws SQLException {
|
public void getSuperTables() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
|
||||||
|
|
||||||
ResultSet rs = metaData.getSuperTables("log", "", "dn1");
|
ResultSet rs = metaData.getSuperTables("log", "", "dn1");
|
||||||
while (rs.next()) {
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME"));
|
rs.next();
|
||||||
System.out.println("SUPERTABLE_NAME: " + rs.getString("SUPERTABLE_NAME"));
|
{
|
||||||
|
// TABLE_CAT
|
||||||
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
|
Assert.assertEquals("log", rs.getString(1));
|
||||||
|
Assert.assertEquals("log", rs.getString("TABLE_CAT"));
|
||||||
|
// TABLE_CAT
|
||||||
|
Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2));
|
||||||
|
Assert.assertEquals(null, rs.getString(2));
|
||||||
|
Assert.assertEquals(null, rs.getString("TABLE_SCHEM"));
|
||||||
|
// TABLE_CAT
|
||||||
|
Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3));
|
||||||
|
Assert.assertEquals("dn1", rs.getString(3));
|
||||||
|
Assert.assertEquals("dn1", rs.getString("TABLE_NAME"));
|
||||||
|
// TABLE_CAT
|
||||||
|
Assert.assertEquals("SUPERTABLE_NAME", meta.getColumnLabel(4));
|
||||||
|
Assert.assertEquals("dn", rs.getString(4));
|
||||||
|
Assert.assertEquals("dn", rs.getString("SUPERTABLE_NAME"));
|
||||||
}
|
}
|
||||||
Assert.assertNotNull(rs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -951,15 +1083,12 @@ public class TSDBDatabaseMetaDataTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties);
|
connection = DriverManager.getConnection(url, properties);
|
||||||
metaData = connection.getMetaData().unwrap(TSDBDatabaseMetaData.class);
|
metaData = connection.getMetaData().unwrap(TSDBDatabaseMetaData.class);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,9 @@ public class TSDBJNIConnectorTest {
|
||||||
rowData = new TSDBResultSetRowData(columnSize);
|
rowData = new TSDBResultSetRowData(columnSize);
|
||||||
// iterate resultSet
|
// iterate resultSet
|
||||||
for (int i = 0; next(connector, pSql); i++) {
|
for (int i = 0; next(connector, pSql); i++) {
|
||||||
System.out.println("col[" + i + "] size: " + rowData.getColSize());
|
// System.out.println("col[" + i + "] size: " + rowData.getColSize());
|
||||||
rowData.getData().stream().forEach(col -> System.out.print(col + "\t"));
|
// rowData.getData().stream().forEach(col -> System.out.print(col + "\t"));
|
||||||
System.out.println();
|
// System.out.println();
|
||||||
}
|
}
|
||||||
// close resultSet
|
// close resultSet
|
||||||
code = connector.freeResultSet(pSql);
|
code = connector.freeResultSet(pSql);
|
||||||
|
|
|
@ -54,16 +54,17 @@ public class TSDBParameterMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPrecision() throws SQLException {
|
public void getPrecision() throws SQLException {
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(1));
|
//create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64))
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(2));
|
Assert.assertEquals(TSDBConstants.TIMESTAMP_MS_PRECISION, parameterMetaData_insert.getPrecision(1));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(3));
|
Assert.assertEquals(TSDBConstants.INT_PRECISION, parameterMetaData_insert.getPrecision(2));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(4));
|
Assert.assertEquals(TSDBConstants.BIGINT_PRECISION, parameterMetaData_insert.getPrecision(3));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(5));
|
Assert.assertEquals(TSDBConstants.FLOAT_PRECISION, parameterMetaData_insert.getPrecision(4));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(6));
|
Assert.assertEquals(TSDBConstants.DOUBLE_PRECISION, parameterMetaData_insert.getPrecision(5));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(7));
|
Assert.assertEquals(TSDBConstants.SMALLINT_PRECISION, parameterMetaData_insert.getPrecision(6));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(8));
|
Assert.assertEquals(TSDBConstants.TINYINT_PRECISION, parameterMetaData_insert.getPrecision(7));
|
||||||
Assert.assertEquals(5, parameterMetaData_insert.getPrecision(9));
|
Assert.assertEquals(TSDBConstants.BOOLEAN_PRECISION, parameterMetaData_insert.getPrecision(8));
|
||||||
Assert.assertEquals(5, parameterMetaData_insert.getPrecision(10));
|
Assert.assertEquals("hello".getBytes().length, parameterMetaData_insert.getPrecision(9));
|
||||||
|
Assert.assertEquals("涛思数据".length(), parameterMetaData_insert.getPrecision(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -71,8 +72,8 @@ public class TSDBParameterMetaDataTest {
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(1));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(1));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(2));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(2));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(3));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(3));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(4));
|
Assert.assertEquals(31, parameterMetaData_insert.getScale(4));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(5));
|
Assert.assertEquals(31, parameterMetaData_insert.getScale(5));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(6));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(6));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(7));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(7));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(8));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(8));
|
||||||
|
@ -124,10 +125,16 @@ public class TSDBParameterMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getParameterMode() throws SQLException {
|
public void getParameterMode() throws SQLException {
|
||||||
for (int i = 1; i <= parameterMetaData_insert.getParameterCount(); i++) {
|
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(1));
|
||||||
int parameterMode = parameterMetaData_insert.getParameterMode(i);
|
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(2));
|
||||||
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMode);
|
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(3));
|
||||||
}
|
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(4));
|
||||||
|
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(5));
|
||||||
|
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(6));
|
||||||
|
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(7));
|
||||||
|
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(8));
|
||||||
|
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(9));
|
||||||
|
Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -144,7 +151,6 @@ public class TSDBParameterMetaDataTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
|
||||||
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
|
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
|
||||||
try (Statement stmt = conn.createStatement()) {
|
try (Statement stmt = conn.createStatement()) {
|
||||||
stmt.execute("drop database if exists test_pstmt");
|
stmt.execute("drop database if exists test_pstmt");
|
||||||
|
@ -164,7 +170,7 @@ public class TSDBParameterMetaDataTest {
|
||||||
pstmt_insert.setObject(7, Byte.MAX_VALUE);
|
pstmt_insert.setObject(7, Byte.MAX_VALUE);
|
||||||
pstmt_insert.setObject(8, true);
|
pstmt_insert.setObject(8, true);
|
||||||
pstmt_insert.setObject(9, "hello".getBytes());
|
pstmt_insert.setObject(9, "hello".getBytes());
|
||||||
pstmt_insert.setObject(10, "Hello");
|
pstmt_insert.setObject(10, "涛思数据");
|
||||||
parameterMetaData_insert = pstmt_insert.getParameterMetaData();
|
parameterMetaData_insert = pstmt_insert.getParameterMetaData();
|
||||||
|
|
||||||
pstmt_select = conn.prepareStatement(sql_select);
|
pstmt_select = conn.prepareStatement(sql_select);
|
||||||
|
@ -173,7 +179,7 @@ public class TSDBParameterMetaDataTest {
|
||||||
pstmt_select.setInt(3, 0);
|
pstmt_select.setInt(3, 0);
|
||||||
parameterMetaData_select = pstmt_select.getParameterMetaData();
|
parameterMetaData_select = pstmt_select.getParameterMetaData();
|
||||||
|
|
||||||
} catch (ClassNotFoundException | SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,6 +14,7 @@ import java.math.BigDecimal;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class TSDBResultSetTest {
|
public class TSDBResultSetTest {
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ public class TSDBResultSetTest {
|
||||||
Assert.assertEquals(3.1415926, Double.valueOf(new String(f5)), 0.000000f);
|
Assert.assertEquals(3.1415926, Double.valueOf(new String(f5)), 0.000000f);
|
||||||
|
|
||||||
byte[] f6 = rs.getBytes("f6");
|
byte[] f6 = rs.getBytes("f6");
|
||||||
Assert.assertEquals("abc", new String(f6));
|
Assert.assertTrue(Arrays.equals("abc".getBytes(), f6));
|
||||||
|
|
||||||
byte[] f7 = rs.getBytes("f7");
|
byte[] f7 = rs.getBytes("f7");
|
||||||
Assert.assertEquals((short) 10, Shorts.fromByteArray(f7));
|
Assert.assertEquals((short) 10, Shorts.fromByteArray(f7));
|
||||||
|
@ -176,7 +177,6 @@ public class TSDBResultSetTest {
|
||||||
rs.getAsciiStream("f1");
|
rs.getAsciiStream("f1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||||
public void getUnicodeStream() throws SQLException {
|
public void getUnicodeStream() throws SQLException {
|
||||||
rs.getUnicodeStream("f1");
|
rs.getUnicodeStream("f1");
|
||||||
|
@ -646,7 +646,6 @@ public class TSDBResultSetTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
|
||||||
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
|
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
|
||||||
stmt = conn.createStatement();
|
stmt = conn.createStatement();
|
||||||
stmt.execute("create database if not exists restful_test");
|
stmt.execute("create database if not exists restful_test");
|
||||||
|
@ -656,10 +655,9 @@ public class TSDBResultSetTest {
|
||||||
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, '涛思数据')");
|
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 = stmt.executeQuery("select * from restful_test.weather");
|
||||||
rs.next();
|
rs.next();
|
||||||
} catch (ClassNotFoundException | SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
|
|
@ -387,15 +387,12 @@ public class TSDBStatementTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties);
|
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties);
|
||||||
stmt = conn.createStatement();
|
stmt = conn.createStatement();
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.sql.*;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class RestfulDatabaseMetaDataTest {
|
public class RestfulDatabaseMetaDataTest {
|
||||||
|
|
||||||
private static final String host = "127.0.0.1";
|
private static final String host = "127.0.0.1";
|
||||||
private static final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
private static final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
||||||
private static Connection connection;
|
private static Connection connection;
|
||||||
|
@ -632,17 +633,32 @@ public class RestfulDatabaseMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTables() throws SQLException {
|
public void getTables() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
ResultSet rs = metaData.getTables("log", "", null, null);
|
||||||
ResultSet tables = metaData.getTables("log", "", null, null);
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
ResultSetMetaData metaData = tables.getMetaData();
|
Assert.assertNotNull(rs);
|
||||||
while (tables.next()) {
|
rs.next();
|
||||||
System.out.print(metaData.getColumnLabel(1) + ":" + tables.getString(1) + "\t");
|
{
|
||||||
System.out.print(metaData.getColumnLabel(3) + ":" + tables.getString(3) + "\t");
|
// TABLE_CAT
|
||||||
System.out.print(metaData.getColumnLabel(4) + ":" + tables.getString(4) + "\t");
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
System.out.print(metaData.getColumnLabel(5) + ":" + tables.getString(5) + "\n");
|
Assert.assertEquals("log", rs.getString(1));
|
||||||
|
Assert.assertEquals("log", rs.getString("TABLE_CAT"));
|
||||||
|
// TABLE_SCHEM
|
||||||
|
Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2));
|
||||||
|
Assert.assertEquals(null, rs.getString(2));
|
||||||
|
Assert.assertEquals(null, rs.getString("TABLE_SCHEM"));
|
||||||
|
// TABLE_NAME
|
||||||
|
Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3));
|
||||||
|
Assert.assertNotNull(rs.getString(3));
|
||||||
|
Assert.assertNotNull(rs.getString("TABLE_NAME"));
|
||||||
|
// TABLE_TYPE
|
||||||
|
Assert.assertEquals("TABLE_TYPE", meta.getColumnLabel(4));
|
||||||
|
Assert.assertEquals("TABLE", rs.getString(4));
|
||||||
|
Assert.assertEquals("TABLE", rs.getString("TABLE_TYPE"));
|
||||||
|
// REMARKS
|
||||||
|
Assert.assertEquals("REMARKS", meta.getColumnLabel(5));
|
||||||
|
Assert.assertEquals("", rs.getString(5));
|
||||||
|
Assert.assertEquals("", rs.getString("REMARKS"));
|
||||||
}
|
}
|
||||||
System.out.println();
|
|
||||||
Assert.assertNotNull(tables);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -652,46 +668,130 @@ public class RestfulDatabaseMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCatalogs() throws SQLException {
|
public void getCatalogs() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
ResultSet rs = metaData.getCatalogs();
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
ResultSet catalogs = metaData.getCatalogs();
|
rs.next();
|
||||||
ResultSetMetaData meta = catalogs.getMetaData();
|
{
|
||||||
while (catalogs.next()) {
|
// TABLE_CAT
|
||||||
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
System.out.print(meta.getColumnLabel(i) + ": " + catalogs.getString(i));
|
Assert.assertNotNull(rs.getString(1));
|
||||||
}
|
Assert.assertNotNull(rs.getString("TABLE_CAT"));
|
||||||
System.out.println();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTableTypes() throws SQLException {
|
public void getTableTypes() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
|
||||||
|
|
||||||
ResultSet tableTypes = metaData.getTableTypes();
|
ResultSet tableTypes = metaData.getTableTypes();
|
||||||
while (tableTypes.next()) {
|
tableTypes.next();
|
||||||
System.out.println(tableTypes.getString("TABLE_TYPE"));
|
// tableTypes: table
|
||||||
|
{
|
||||||
|
Assert.assertEquals("TABLE", tableTypes.getString(1));
|
||||||
|
Assert.assertEquals("TABLE", tableTypes.getString("TABLE_TYPE"));
|
||||||
|
}
|
||||||
|
tableTypes.next();
|
||||||
|
// tableTypes: stable
|
||||||
|
{
|
||||||
|
Assert.assertEquals("STABLE", tableTypes.getString(1));
|
||||||
|
Assert.assertEquals("STABLE", tableTypes.getString("TABLE_TYPE"));
|
||||||
}
|
}
|
||||||
Assert.assertNotNull(metaData.getTableTypes());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getColumns() throws SQLException {
|
public void getColumns() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
// when
|
||||||
|
|
||||||
ResultSet columns = metaData.getColumns("log", "", "dn", "");
|
ResultSet columns = metaData.getColumns("log", "", "dn", "");
|
||||||
|
// then
|
||||||
ResultSetMetaData meta = columns.getMetaData();
|
ResultSetMetaData meta = columns.getMetaData();
|
||||||
while (columns.next()) {
|
columns.next();
|
||||||
System.out.print(meta.getColumnLabel(1) + ": " + columns.getString(1) + "\t");
|
// column: 1
|
||||||
System.out.print(meta.getColumnLabel(3) + ": " + columns.getString(3) + "\t");
|
{
|
||||||
System.out.print(meta.getColumnLabel(4) + ": " + columns.getString(4) + "\t");
|
// TABLE_CAT
|
||||||
System.out.print(meta.getColumnLabel(5) + ": " + columns.getString(5) + "\t");
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
System.out.print(meta.getColumnLabel(6) + ": " + columns.getString(6) + "\t");
|
Assert.assertEquals("log", columns.getString(1));
|
||||||
System.out.print(meta.getColumnLabel(7) + ": " + columns.getString(7) + "\t");
|
Assert.assertEquals("log", columns.getString("TABLE_CAT"));
|
||||||
System.out.print(meta.getColumnLabel(9) + ": " + columns.getString(9) + "\t");
|
// TABLE_NAME
|
||||||
System.out.print(meta.getColumnLabel(10) + ": " + columns.getString(10) + "\t");
|
Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3));
|
||||||
System.out.print(meta.getColumnLabel(11) + ": " + columns.getString(11) + "\n");
|
Assert.assertEquals("dn", columns.getString(3));
|
||||||
System.out.print(meta.getColumnLabel(12) + ": " + columns.getString(12) + "\n");
|
Assert.assertEquals("dn", columns.getString("TABLE_NAME"));
|
||||||
|
// COLUMN_NAME
|
||||||
|
Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4));
|
||||||
|
Assert.assertEquals("ts", columns.getString(4));
|
||||||
|
Assert.assertEquals("ts", columns.getString("COLUMN_NAME"));
|
||||||
|
// DATA_TYPE
|
||||||
|
Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5));
|
||||||
|
Assert.assertEquals(Types.TIMESTAMP, columns.getInt(5));
|
||||||
|
Assert.assertEquals(Types.TIMESTAMP, columns.getInt("DATA_TYPE"));
|
||||||
|
// TYPE_NAME
|
||||||
|
Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6));
|
||||||
|
Assert.assertEquals("TIMESTAMP", columns.getString(6));
|
||||||
|
Assert.assertEquals("TIMESTAMP", columns.getString("TYPE_NAME"));
|
||||||
|
// COLUMN_SIZE
|
||||||
|
Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7));
|
||||||
|
Assert.assertEquals(26, columns.getInt(7));
|
||||||
|
Assert.assertEquals(26, columns.getInt("COLUMN_SIZE"));
|
||||||
|
// DECIMAL_DIGITS
|
||||||
|
Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9));
|
||||||
|
Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9));
|
||||||
|
Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS"));
|
||||||
|
Assert.assertEquals(null, columns.getString(9));
|
||||||
|
Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS"));
|
||||||
|
// NUM_PREC_RADIX
|
||||||
|
Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10));
|
||||||
|
Assert.assertEquals(10, columns.getInt(10));
|
||||||
|
Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX"));
|
||||||
|
// NULLABLE
|
||||||
|
Assert.assertEquals("NULLABLE", meta.getColumnLabel(11));
|
||||||
|
Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt(11));
|
||||||
|
Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt("NULLABLE"));
|
||||||
|
// REMARKS
|
||||||
|
Assert.assertEquals("REMARKS", meta.getColumnLabel(12));
|
||||||
|
Assert.assertEquals(null, columns.getString(12));
|
||||||
|
Assert.assertEquals(null, columns.getString("REMARKS"));
|
||||||
|
}
|
||||||
|
columns.next();
|
||||||
|
// column: 2
|
||||||
|
{
|
||||||
|
// TABLE_CAT
|
||||||
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
|
Assert.assertEquals("log", columns.getString(1));
|
||||||
|
Assert.assertEquals("log", columns.getString("TABLE_CAT"));
|
||||||
|
// TABLE_NAME
|
||||||
|
Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3));
|
||||||
|
Assert.assertEquals("dn", columns.getString(3));
|
||||||
|
Assert.assertEquals("dn", columns.getString("TABLE_NAME"));
|
||||||
|
// COLUMN_NAME
|
||||||
|
Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4));
|
||||||
|
Assert.assertEquals("cpu_taosd", columns.getString(4));
|
||||||
|
Assert.assertEquals("cpu_taosd", columns.getString("COLUMN_NAME"));
|
||||||
|
// DATA_TYPE
|
||||||
|
Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5));
|
||||||
|
Assert.assertEquals(Types.FLOAT, columns.getInt(5));
|
||||||
|
Assert.assertEquals(Types.FLOAT, columns.getInt("DATA_TYPE"));
|
||||||
|
// TYPE_NAME
|
||||||
|
Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6));
|
||||||
|
Assert.assertEquals("FLOAT", columns.getString(6));
|
||||||
|
Assert.assertEquals("FLOAT", columns.getString("TYPE_NAME"));
|
||||||
|
// COLUMN_SIZE
|
||||||
|
Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7));
|
||||||
|
Assert.assertEquals(12, columns.getInt(7));
|
||||||
|
Assert.assertEquals(12, columns.getInt("COLUMN_SIZE"));
|
||||||
|
// DECIMAL_DIGITS
|
||||||
|
Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9));
|
||||||
|
Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9));
|
||||||
|
Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS"));
|
||||||
|
Assert.assertEquals(null, columns.getString(9));
|
||||||
|
Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS"));
|
||||||
|
// NUM_PREC_RADIX
|
||||||
|
Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10));
|
||||||
|
Assert.assertEquals(10, columns.getInt(10));
|
||||||
|
Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX"));
|
||||||
|
// NULLABLE
|
||||||
|
Assert.assertEquals("NULLABLE", meta.getColumnLabel(11));
|
||||||
|
Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt(11));
|
||||||
|
Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt("NULLABLE"));
|
||||||
|
// REMARKS
|
||||||
|
Assert.assertEquals("REMARKS", meta.getColumnLabel(12));
|
||||||
|
Assert.assertEquals(null, columns.getString(12));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,17 +817,35 @@ public class RestfulDatabaseMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPrimaryKeys() throws SQLException {
|
public void getPrimaryKeys() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
|
||||||
|
|
||||||
ResultSet rs = metaData.getPrimaryKeys("log", "", "dn1");
|
ResultSet rs = metaData.getPrimaryKeys("log", "", "dn1");
|
||||||
while (rs.next()) {
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME"));
|
rs.next();
|
||||||
System.out.println("COLUMN_NAME: " + rs.getString("COLUMN_NAME"));
|
{
|
||||||
System.out.println("KEY_SEQ: " + rs.getString("KEY_SEQ"));
|
// TABLE_CAT
|
||||||
System.out.println("PK_NAME: " + rs.getString("PK_NAME"));
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
|
Assert.assertEquals("log", rs.getString(1));
|
||||||
|
Assert.assertEquals("log", rs.getString("TABLE_CAT"));
|
||||||
|
// TABLE_SCHEM
|
||||||
|
Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2));
|
||||||
|
Assert.assertEquals(null, rs.getString(2));
|
||||||
|
Assert.assertEquals(null, rs.getString("TABLE_SCHEM"));
|
||||||
|
// TABLE_NAME
|
||||||
|
Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3));
|
||||||
|
Assert.assertEquals("dn1", rs.getString(3));
|
||||||
|
Assert.assertEquals("dn1", rs.getString("TABLE_NAME"));
|
||||||
|
// COLUMN_NAME
|
||||||
|
Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4));
|
||||||
|
Assert.assertEquals("ts", rs.getString(4));
|
||||||
|
Assert.assertEquals("ts", rs.getString("COLUMN_NAME"));
|
||||||
|
// KEY_SEQ
|
||||||
|
Assert.assertEquals("KEY_SEQ", meta.getColumnLabel(5));
|
||||||
|
Assert.assertEquals(1, rs.getShort(5));
|
||||||
|
Assert.assertEquals(1, rs.getShort("KEY_SEQ"));
|
||||||
|
// DATA_TYPE
|
||||||
|
Assert.assertEquals("PK_NAME", meta.getColumnLabel(6));
|
||||||
|
Assert.assertEquals("ts", rs.getString(6));
|
||||||
|
Assert.assertEquals("ts", rs.getString("PK_NAME"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertNotNull(rs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -852,14 +970,27 @@ public class RestfulDatabaseMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSuperTables() throws SQLException {
|
public void getSuperTables() throws SQLException {
|
||||||
System.out.println("****************************************************");
|
|
||||||
|
|
||||||
ResultSet rs = metaData.getSuperTables("log", "", "dn1");
|
ResultSet rs = metaData.getSuperTables("log", "", "dn1");
|
||||||
while (rs.next()) {
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME"));
|
rs.next();
|
||||||
System.out.println("SUPERTABLE_NAME: " + rs.getString("SUPERTABLE_NAME"));
|
{
|
||||||
|
// TABLE_CAT
|
||||||
|
Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1));
|
||||||
|
Assert.assertEquals("log", rs.getString(1));
|
||||||
|
Assert.assertEquals("log", rs.getString("TABLE_CAT"));
|
||||||
|
// TABLE_CAT
|
||||||
|
Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2));
|
||||||
|
Assert.assertEquals(null, rs.getString(2));
|
||||||
|
Assert.assertEquals(null, rs.getString("TABLE_SCHEM"));
|
||||||
|
// TABLE_CAT
|
||||||
|
Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3));
|
||||||
|
Assert.assertEquals("dn1", rs.getString(3));
|
||||||
|
Assert.assertEquals("dn1", rs.getString("TABLE_NAME"));
|
||||||
|
// TABLE_CAT
|
||||||
|
Assert.assertEquals("SUPERTABLE_NAME", meta.getColumnLabel(4));
|
||||||
|
Assert.assertEquals("dn", rs.getString(4));
|
||||||
|
Assert.assertEquals("dn", rs.getString("SUPERTABLE_NAME"));
|
||||||
}
|
}
|
||||||
Assert.assertNotNull(rs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -54,16 +54,17 @@ public class RestfulParameterMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPrecision() throws SQLException {
|
public void getPrecision() throws SQLException {
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(1));
|
//create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64))
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(2));
|
Assert.assertEquals(TSDBConstants.TIMESTAMP_MS_PRECISION, parameterMetaData_insert.getPrecision(1));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(3));
|
Assert.assertEquals(TSDBConstants.INT_PRECISION, parameterMetaData_insert.getPrecision(2));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(4));
|
Assert.assertEquals(TSDBConstants.BIGINT_PRECISION, parameterMetaData_insert.getPrecision(3));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(5));
|
Assert.assertEquals(TSDBConstants.FLOAT_PRECISION, parameterMetaData_insert.getPrecision(4));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(6));
|
Assert.assertEquals(TSDBConstants.DOUBLE_PRECISION, parameterMetaData_insert.getPrecision(5));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(7));
|
Assert.assertEquals(TSDBConstants.SMALLINT_PRECISION, parameterMetaData_insert.getPrecision(6));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getPrecision(8));
|
Assert.assertEquals(TSDBConstants.TINYINT_PRECISION, parameterMetaData_insert.getPrecision(7));
|
||||||
Assert.assertEquals(5, parameterMetaData_insert.getPrecision(9));
|
Assert.assertEquals(TSDBConstants.BOOLEAN_PRECISION, parameterMetaData_insert.getPrecision(8));
|
||||||
Assert.assertEquals(5, parameterMetaData_insert.getPrecision(10));
|
Assert.assertEquals("hello".getBytes().length, parameterMetaData_insert.getPrecision(9));
|
||||||
|
Assert.assertEquals("涛思数据".length(), parameterMetaData_insert.getPrecision(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -71,8 +72,8 @@ public class RestfulParameterMetaDataTest {
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(1));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(1));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(2));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(2));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(3));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(3));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(4));
|
Assert.assertEquals(31, parameterMetaData_insert.getScale(4));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(5));
|
Assert.assertEquals(31, parameterMetaData_insert.getScale(5));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(6));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(6));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(7));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(7));
|
||||||
Assert.assertEquals(0, parameterMetaData_insert.getScale(8));
|
Assert.assertEquals(0, parameterMetaData_insert.getScale(8));
|
||||||
|
@ -164,7 +165,7 @@ public class RestfulParameterMetaDataTest {
|
||||||
pstmt_insert.setObject(7, Byte.MAX_VALUE);
|
pstmt_insert.setObject(7, Byte.MAX_VALUE);
|
||||||
pstmt_insert.setObject(8, true);
|
pstmt_insert.setObject(8, true);
|
||||||
pstmt_insert.setObject(9, "hello".getBytes());
|
pstmt_insert.setObject(9, "hello".getBytes());
|
||||||
pstmt_insert.setObject(10, "Hello");
|
pstmt_insert.setObject(10, "涛思数据");
|
||||||
parameterMetaData_insert = pstmt_insert.getParameterMetaData();
|
parameterMetaData_insert = pstmt_insert.getParameterMetaData();
|
||||||
|
|
||||||
pstmt_select = conn.prepareStatement(sql_select);
|
pstmt_select = conn.prepareStatement(sql_select);
|
||||||
|
|
Loading…
Reference in New Issue