[TD-3082]<feature>: jdbc connector support unsigned tinyint, smallint, int, bigint (#5447)
* [TD-3082]<feature>: support unsigned number in JDBC connector * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change * change version * change * change
This commit is contained in:
parent
bbfde59f0a
commit
ac5d5316ac
|
@ -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.21-dist.jar DESTINATION connector/jdbc)
|
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.22-dist.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")
|
||||||
|
|
|
@ -481,15 +481,19 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
|
||||||
case TSDB_DATA_TYPE_BOOL:
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetBooleanFp, i, (jboolean)(*((char *)row[i]) == 1));
|
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetBooleanFp, i, (jboolean)(*((char *)row[i]) == 1));
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT:
|
||||||
case TSDB_DATA_TYPE_TINYINT:
|
case TSDB_DATA_TYPE_TINYINT:
|
||||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteFp, i, (jbyte) * ((int8_t *)row[i]));
|
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteFp, i, (jbyte) * ((int8_t *)row[i]));
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT:
|
||||||
case TSDB_DATA_TYPE_SMALLINT:
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetShortFp, i, (jshort) * ((int16_t *)row[i]));
|
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetShortFp, i, (jshort) * ((int16_t *)row[i]));
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UINT:
|
||||||
case TSDB_DATA_TYPE_INT:
|
case TSDB_DATA_TYPE_INT:
|
||||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetIntFp, i, (jint) * (int32_t *)row[i]);
|
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetIntFp, i, (jint) * (int32_t *)row[i]);
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UBIGINT:
|
||||||
case TSDB_DATA_TYPE_BIGINT:
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetLongFp, i, (jlong) * ((int64_t *)row[i]));
|
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetLongFp, i, (jlong) * ((int64_t *)row[i]));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -8,7 +8,7 @@ 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.21-dist.jar ${LIBRARY_OUTPUT_PATH}
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.22-dist.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})
|
||||||
|
|
|
@ -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.21</version>
|
<version>2.0.22</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.21</version>
|
<version>2.0.22</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>
|
||||||
|
@ -102,6 +102,8 @@
|
||||||
<include>**/*Test.java</include>
|
<include>**/*Test.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
<excludes>
|
<excludes>
|
||||||
|
<exclude>**/TSDBJNIConnectorTest.java</exclude>
|
||||||
|
<exclude>**/UnsignedNumberJniTest.java</exclude>
|
||||||
<exclude>**/DatetimeBefore1970Test.java</exclude>
|
<exclude>**/DatetimeBefore1970Test.java</exclude>
|
||||||
<exclude>**/AppMemoryLeakTest.java</exclude>
|
<exclude>**/AppMemoryLeakTest.java</exclude>
|
||||||
<exclude>**/AuthenticationTest.java</exclude>
|
<exclude>**/AuthenticationTest.java</exclude>
|
||||||
|
|
|
@ -12,7 +12,7 @@ public abstract class AbstractDriver implements Driver {
|
||||||
hostProp.required = false;
|
hostProp.required = false;
|
||||||
hostProp.description = "Hostname";
|
hostProp.description = "Hostname";
|
||||||
|
|
||||||
DriverPropertyInfo portProp = new DriverPropertyInfo(TSDBDriver.PROPERTY_KEY_PORT, info.getProperty(TSDBDriver.PROPERTY_KEY_PORT, TSDBConstants.DEFAULT_PORT));
|
DriverPropertyInfo portProp = new DriverPropertyInfo(TSDBDriver.PROPERTY_KEY_PORT, info.getProperty(TSDBDriver.PROPERTY_KEY_PORT));
|
||||||
portProp.required = false;
|
portProp.required = false;
|
||||||
portProp.description = "Port";
|
portProp.description = "Port";
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@ public abstract class AbstractDriver implements Driver {
|
||||||
protected Properties parseURL(String url, Properties defaults) {
|
protected Properties parseURL(String url, Properties defaults) {
|
||||||
Properties urlProps = (defaults != null) ? defaults : new Properties();
|
Properties urlProps = (defaults != null) ? defaults : new Properties();
|
||||||
|
|
||||||
// parse properties
|
// parse properties in url
|
||||||
int beginningOfSlashes = url.indexOf("//");
|
int beginningOfSlashes = url.indexOf("//");
|
||||||
int index = url.indexOf("?");
|
int index = url.indexOf("?");
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
String paramString = url.substring(index + 1, url.length());
|
String paramString = url.substring(index + 1);
|
||||||
url = url.substring(0, index);
|
url = url.substring(0, index);
|
||||||
StringTokenizer queryParams = new StringTokenizer(paramString, "&");
|
StringTokenizer queryParams = new StringTokenizer(paramString, "&");
|
||||||
while (queryParams.hasMoreElements()) {
|
while (queryParams.hasMoreElements()) {
|
||||||
|
@ -68,6 +68,7 @@ public abstract class AbstractDriver implements Driver {
|
||||||
String dbProductName = url.substring(0, beginningOfSlashes);
|
String dbProductName = url.substring(0, beginningOfSlashes);
|
||||||
dbProductName = dbProductName.substring(dbProductName.indexOf(":") + 1);
|
dbProductName = dbProductName.substring(dbProductName.indexOf(":") + 1);
|
||||||
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
|
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
|
||||||
|
urlProps.setProperty(TSDBDriver.PROPERTY_KEY_PRODUCT_NAME,dbProductName);
|
||||||
// parse dbname
|
// parse dbname
|
||||||
url = url.substring(beginningOfSlashes + 2);
|
url = url.substring(beginningOfSlashes + 2);
|
||||||
int indexOfSlash = url.indexOf("/");
|
int indexOfSlash = url.indexOf("/");
|
||||||
|
|
|
@ -29,12 +29,7 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet
|
||||||
public abstract boolean getBoolean(int columnIndex) throws SQLException;
|
public abstract boolean getBoolean(int columnIndex) throws SQLException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte getByte(int columnIndex) throws SQLException {
|
public abstract byte getByte(int columnIndex) throws SQLException;
|
||||||
if (isClosed())
|
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
|
||||||
|
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract short getShort(int columnIndex) throws SQLException;
|
public abstract short getShort(int columnIndex) throws SQLException;
|
||||||
|
@ -1205,6 +1200,7 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet
|
||||||
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
|
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); }
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,8 +122,7 @@ public class SavedPreparedStatement {
|
||||||
initPreparedParam = initDefaultParam(tableName, middleParamSize, valueListSize);
|
initPreparedParam = initDefaultParam(tableName, middleParamSize, valueListSize);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// not match
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_SQL);
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("the sql is not complete!"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -189,7 +188,7 @@ public class SavedPreparedStatement {
|
||||||
String errorMsg = String.format("the parameterIndex %s out of the range [1, %s]", parameterIndex, paramSize);
|
String errorMsg = String.format("the parameterIndex %s out of the range [1, %s]", parameterIndex, paramSize);
|
||||||
|
|
||||||
if (parameterIndex < 1 || parameterIndex > paramSize) {
|
if (parameterIndex < 1 || parameterIndex > paramSize) {
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg(errorMsg));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE,errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isAddBatch = false; //set isAddBatch to false
|
this.isAddBatch = false; //set isAddBatch to false
|
||||||
|
@ -212,7 +211,7 @@ public class SavedPreparedStatement {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg(errorMsg));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE,errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBatch() {
|
public void addBatch() {
|
||||||
|
|
|
@ -16,16 +16,11 @@ package com.taosdata.jdbc;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public abstract class TSDBConstants {
|
public abstract class TSDBConstants {
|
||||||
|
|
||||||
public static final String DEFAULT_PORT = "6200";
|
|
||||||
public static Map<Integer, String> DATATYPE_MAP = null;
|
|
||||||
|
|
||||||
public static final long JNI_NULL_POINTER = 0L;
|
public static final long JNI_NULL_POINTER = 0L;
|
||||||
|
// JNI_ERROR_NUMBER
|
||||||
public static final int JNI_SUCCESS = 0;
|
public static final int JNI_SUCCESS = 0;
|
||||||
public static final int JNI_TDENGINE_ERROR = -1;
|
public static final int JNI_TDENGINE_ERROR = -1;
|
||||||
public static final int JNI_CONNECTION_NULL = -2;
|
public static final int JNI_CONNECTION_NULL = -2;
|
||||||
|
@ -34,8 +29,7 @@ public abstract class TSDBConstants {
|
||||||
public static final int JNI_SQL_NULL = -5;
|
public static final int JNI_SQL_NULL = -5;
|
||||||
public static final int JNI_FETCH_END = -6;
|
public static final int JNI_FETCH_END = -6;
|
||||||
public static final int JNI_OUT_OF_MEMORY = -7;
|
public static final int JNI_OUT_OF_MEMORY = -7;
|
||||||
|
// TSDB Data Types
|
||||||
public static final int TSDB_DATA_TYPE_NULL = 0;
|
|
||||||
public static final int TSDB_DATA_TYPE_BOOL = 1;
|
public static final int TSDB_DATA_TYPE_BOOL = 1;
|
||||||
public static final int TSDB_DATA_TYPE_TINYINT = 2;
|
public static final int TSDB_DATA_TYPE_TINYINT = 2;
|
||||||
public static final int TSDB_DATA_TYPE_SMALLINT = 3;
|
public static final int TSDB_DATA_TYPE_SMALLINT = 3;
|
||||||
|
@ -46,46 +40,36 @@ 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;
|
||||||
|
/*
|
||||||
// nchar field's max length
|
系统增加新的无符号数据类型,分别是:
|
||||||
|
unsigned tinyint, 数值范围:0-254, NULL 为255
|
||||||
|
unsigned smallint,数值范围: 0-65534, NULL 为65535
|
||||||
|
unsigned int,数值范围:0-4294967294,NULL 为4294967295u
|
||||||
|
unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u。
|
||||||
|
example:
|
||||||
|
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_USMALLINT = 12; //unsigned smallint
|
||||||
|
public static final int TSDB_DATA_TYPE_UINT = 13; //unsigned int
|
||||||
|
public static final int TSDB_DATA_TYPE_UBIGINT = 14; //unsigned bigint
|
||||||
|
// nchar column max length
|
||||||
public static final int maxFieldSize = 16 * 1024;
|
public static final int maxFieldSize = 16 * 1024;
|
||||||
|
|
||||||
public static String WrapErrMsg(String msg) {
|
|
||||||
return "TDengine Error: " + msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String FixErrMsg(int code) {
|
|
||||||
switch (code) {
|
|
||||||
case JNI_TDENGINE_ERROR:
|
|
||||||
return WrapErrMsg("internal error of database!");
|
|
||||||
case JNI_CONNECTION_NULL:
|
|
||||||
return WrapErrMsg("invalid tdengine connection!");
|
|
||||||
case JNI_RESULT_SET_NULL:
|
|
||||||
return WrapErrMsg("invalid resultset pointer!");
|
|
||||||
case JNI_NUM_OF_FIELDS_0:
|
|
||||||
return WrapErrMsg("invalid num of fields!");
|
|
||||||
case JNI_SQL_NULL:
|
|
||||||
return WrapErrMsg("can't execute empty sql!");
|
|
||||||
case JNI_FETCH_END:
|
|
||||||
return WrapErrMsg("fetch to the end of resultset");
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return WrapErrMsg("unkown error!");
|
|
||||||
}
|
|
||||||
|
|
||||||
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_NULL:
|
|
||||||
return Types.NULL;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
return Types.BOOLEAN;
|
return Types.BOOLEAN;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
|
||||||
return Types.TINYINT;
|
return Types.TINYINT;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
return Types.SMALLINT;
|
return Types.SMALLINT;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
return Types.INTEGER;
|
return Types.INTEGER;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
return Types.BIGINT;
|
return Types.BIGINT;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
|
@ -99,13 +83,42 @@ public abstract class TSDBConstants {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
return Types.NCHAR;
|
return Types.NCHAR;
|
||||||
}
|
}
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String taosType2JdbcTypeName(int taosType) throws SQLException {
|
||||||
|
switch (taosType){
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
|
return "BOOL";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
|
return "TINYINT";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
return "SMALLINT";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return "INT";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return "BIGINT";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
|
return "FLOAT";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
return "DOUBLE";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
return "BINARY";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
return "TIMESTAMP";
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
|
return "NCHAR";
|
||||||
|
default:
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int jdbcType2TaosType(int jdbcType) throws SQLException {
|
public static int jdbcType2TaosType(int jdbcType) throws SQLException {
|
||||||
switch (jdbcType){
|
switch (jdbcType){
|
||||||
case Types.NULL:
|
|
||||||
return TSDBConstants.TSDB_DATA_TYPE_NULL;
|
|
||||||
case Types.BOOLEAN:
|
case Types.BOOLEAN:
|
||||||
return TSDBConstants.TSDB_DATA_TYPE_BOOL;
|
return TSDBConstants.TSDB_DATA_TYPE_BOOL;
|
||||||
case Types.TINYINT:
|
case Types.TINYINT:
|
||||||
|
@ -130,22 +143,31 @@ public abstract class TSDBConstants {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
public static String jdbcType2TaosTypeName(int jdbcType) throws SQLException {
|
||||||
DATATYPE_MAP = new HashMap<>();
|
switch (jdbcType){
|
||||||
DATATYPE_MAP.put(0, "NULL");
|
case Types.BOOLEAN:
|
||||||
DATATYPE_MAP.put(1, "BOOL");
|
return "BOOL";
|
||||||
DATATYPE_MAP.put(2, "TINYINT");
|
case Types.TINYINT:
|
||||||
DATATYPE_MAP.put(3, "SMALLINT");
|
return "TINYINT";
|
||||||
DATATYPE_MAP.put(4, "INT");
|
case Types.SMALLINT:
|
||||||
DATATYPE_MAP.put(5, "BIGINT");
|
return "SMALLINT";
|
||||||
DATATYPE_MAP.put(6, "FLOAT");
|
case Types.INTEGER:
|
||||||
DATATYPE_MAP.put(7, "DOUBLE");
|
return "INT";
|
||||||
DATATYPE_MAP.put(8, "BINARY");
|
case Types.BIGINT:
|
||||||
DATATYPE_MAP.put(9, "TIMESTAMP");
|
return "BIGINT";
|
||||||
DATATYPE_MAP.put(10, "NCHAR");
|
case Types.FLOAT:
|
||||||
|
return "FLOAT";
|
||||||
|
case Types.DOUBLE:
|
||||||
|
return "DOUBLE";
|
||||||
|
case Types.BINARY:
|
||||||
|
return "BINARY";
|
||||||
|
case Types.TIMESTAMP:
|
||||||
|
return "TIMESTAMP";
|
||||||
|
case Types.NCHAR:
|
||||||
|
return "NCHAR";
|
||||||
|
default:
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String jdbcType2TaosTypeName(int type) throws SQLException {
|
|
||||||
return DATATYPE_MAP.get(jdbcType2TaosType(type));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,10 @@ public class TSDBDriver extends AbstractDriver {
|
||||||
|
|
||||||
private static final String URL_PREFIX = "jdbc:TAOS://";
|
private static final String URL_PREFIX = "jdbc:TAOS://";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PRODUCT_NAME
|
||||||
|
*/
|
||||||
|
public static final String PROPERTY_KEY_PRODUCT_NAME = "productName";
|
||||||
/**
|
/**
|
||||||
* Key used to retrieve the host value from the properties instance passed to
|
* Key used to retrieve the host value from the properties instance passed to
|
||||||
* the driver.
|
* the driver.
|
||||||
|
@ -96,38 +100,34 @@ public class TSDBDriver extends AbstractDriver {
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
java.sql.DriverManager.registerDriver(new TSDBDriver());
|
java.sql.DriverManager.registerDriver(new TSDBDriver());
|
||||||
} catch (SQLException E) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(TSDBConstants.WrapErrMsg("can't register tdengine jdbc driver!"));
|
throw TSDBError.createRuntimeException(TSDBErrorNumbers.ERROR_CANNOT_REGISTER_JNI_DRIVER, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Connection connect(String url, Properties info) throws SQLException {
|
public Connection connect(String url, Properties info) throws SQLException {
|
||||||
if (url == null)
|
if (url == null)
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is not set!"));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||||
|
|
||||||
if (!acceptsURL(url))
|
if (!acceptsURL(url))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Properties props = null;
|
Properties props = parseURL(url, info);
|
||||||
if ((props = parseURL(url, info)) == null) {
|
if (props == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR), (String) props.get(PROPERTY_KEY_LOCALE),
|
TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR), (String) props.get(PROPERTY_KEY_LOCALE),
|
||||||
(String) props.get(PROPERTY_KEY_CHARSET), (String) props.get(PROPERTY_KEY_TIME_ZONE));
|
(String) props.get(PROPERTY_KEY_CHARSET), (String) props.get(PROPERTY_KEY_TIME_ZONE));
|
||||||
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
return new TSDBConnection(props, this.dbMetaData);
|
||||||
return newConn;
|
|
||||||
} catch (SQLWarning sqlWarning) {
|
} catch (SQLWarning sqlWarning) {
|
||||||
sqlWarning.printStackTrace();
|
sqlWarning.printStackTrace();
|
||||||
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
return new TSDBConnection(props, this.dbMetaData);
|
||||||
return newConn;
|
|
||||||
} catch (SQLException sqlEx) {
|
} catch (SQLException sqlEx) {
|
||||||
throw sqlEx;
|
throw sqlEx;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
SQLException sqlEx = new SQLException("SQLException:" + ex.toString());
|
throw new SQLException("SQLException:" + ex.toString(), ex);
|
||||||
sqlEx.initCause(ex);
|
|
||||||
throw sqlEx;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +139,8 @@ public class TSDBDriver extends AbstractDriver {
|
||||||
*/
|
*/
|
||||||
public boolean acceptsURL(String url) throws SQLException {
|
public boolean acceptsURL(String url) throws SQLException {
|
||||||
if (url == null)
|
if (url == null)
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is null"));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||||
return (url != null && url.length() > 0 && url.trim().length() > 0) && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1));
|
return url.length() > 0 && url.trim().length() > 0 && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.taosdata.jdbc;
|
||||||
import java.sql.SQLClientInfoException;
|
import java.sql.SQLClientInfoException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.SQLFeatureNotSupportedException;
|
import java.sql.SQLFeatureNotSupportedException;
|
||||||
|
import java.sql.SQLWarning;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -18,18 +19,25 @@ public class TSDBError {
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY, "Batch is empty!");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY, "Batch is empty!");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY, "Can not issue data manipulation statements with executeQuery()");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY, "Can not issue data manipulation statements with executeQuery()");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEUPDATE, "Can not issue SELECT via executeUpdate()");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEUPDATE, "Can not issue SELECT via executeUpdate()");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "not a valid sql for executeQuery: (?)");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "invalid sql for executeQuery: (?)");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE, "Database not specified or available");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE, "Database not specified or available");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: (?)");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "invalid sql for executeUpdate: (?)");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: (?)");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "invalid sql for execute: (?)");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "parameter index out of range");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "parameter index out of range");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED, "connection already closed");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED, "connection already closed");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE, "unknown sql type in tdengine");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_CANNOT_REGISTER_JNI_DRIVER, "can't register JDBC-JNI driver");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_CANNOT_REGISTER_RESTFUL_DRIVER, "can't register JDBC-RESTful driver");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_URL_NOT_SET, "url is not set");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_SQL, "invalid sql");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE, "numeric value out of range");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE, "unknown taos type in tdengine");
|
||||||
|
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error");
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SUBSCRIBE_FAILED, "failed to create subscription");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SUBSCRIBE_FAILED, "failed to create subscription");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING, "Unsupported encoding");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING, "Unsupported encoding");
|
||||||
|
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_TDENGINE_ERROR, "internal error of database");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_TDENGINE_ERROR, "internal error of database");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, "JNI connection is NULL");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, "JNI connection is NULL");
|
||||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL, "JNI result set is NULL");
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL, "JNI result set is NULL");
|
||||||
|
@ -65,4 +73,12 @@ public class TSDBError {
|
||||||
return new SQLException("TDengine ERROR (" + Integer.toHexString(errorCode) + "): " + message, "", errorCode);
|
return new SQLException("TDengine ERROR (" + Integer.toHexString(errorCode) + "): " + message, "", errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public static RuntimeException createRuntimeException(int errorCode, Throwable t) {
|
||||||
|
String message = TSDBErrorMap.get(errorCode);
|
||||||
|
return new RuntimeException("ERROR (" + Integer.toHexString(errorCode) + "): " + message, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SQLWarning createSQLWarning(String message) {
|
||||||
|
return new SQLWarning(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,15 +16,20 @@ public class TSDBErrorNumbers {
|
||||||
public static final int ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE = 0x230a; //Database not specified or available
|
public static final int ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE = 0x230a; //Database not specified or available
|
||||||
public static final int ERROR_INVALID_FOR_EXECUTE_UPDATE = 0x230b; //not a valid sql for executeUpdate: (SQL)
|
public static final int ERROR_INVALID_FOR_EXECUTE_UPDATE = 0x230b; //not a valid sql for executeUpdate: (SQL)
|
||||||
public static final int ERROR_INVALID_FOR_EXECUTE = 0x230c; //not a valid sql for execute: (SQL)
|
public static final int ERROR_INVALID_FOR_EXECUTE = 0x230c; //not a valid sql for execute: (SQL)
|
||||||
public static final int ERROR_PARAMETER_INDEX_OUT_RANGE = 0x230d; // parameter index out of range
|
public static final int ERROR_PARAMETER_INDEX_OUT_RANGE = 0x230d; // parameter index out of range
|
||||||
public static final int ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED = 0x230e; // connection already closed
|
public static final int ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED = 0x230e; // connection already closed
|
||||||
public static final int ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE = 0x230f; //unknown sql type in tdengine
|
public static final int ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE = 0x230f; //unknown sql type in tdengine
|
||||||
|
public static final int ERROR_CANNOT_REGISTER_JNI_DRIVER = 0x2310; // can't register JDBC-JNI driver
|
||||||
|
public static final int ERROR_CANNOT_REGISTER_RESTFUL_DRIVER = 0x2311; // can't register JDBC-RESTful driver
|
||||||
|
public static final int ERROR_URL_NOT_SET = 0x2312; // url is not set
|
||||||
|
public static final int ERROR_INVALID_SQL = 0x2313; // invalid sql
|
||||||
|
public static final int ERROR_NUMERIC_VALUE_OUT_OF_RANGE = 0x2314; // numeric value out of range
|
||||||
|
public static final int ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE = 0x2315; //unknown taos type in tdengine
|
||||||
|
|
||||||
public static final int ERROR_UNKNOWN = 0x2350; //unknown error
|
public static final int ERROR_UNKNOWN = 0x2350; //unknown error
|
||||||
|
|
||||||
public static final int ERROR_SUBSCRIBE_FAILED = 0x2351; // failed to create subscription
|
public static final int ERROR_SUBSCRIBE_FAILED = 0x2351; // failed to create subscription
|
||||||
public static final int ERROR_UNSUPPORTED_ENCODING = 0x2352; // Unsupported encoding
|
public static final int ERROR_UNSUPPORTED_ENCODING = 0x2352; // Unsupported encoding
|
||||||
|
|
||||||
public static final int ERROR_JNI_TDENGINE_ERROR = 0x2353; // internal error of database
|
public static final int ERROR_JNI_TDENGINE_ERROR = 0x2353; // internal error of database
|
||||||
public static final int ERROR_JNI_CONNECTION_NULL = 0x2354; // JNI connection is NULL
|
public static final int ERROR_JNI_CONNECTION_NULL = 0x2354; // JNI connection is NULL
|
||||||
public static final int ERROR_JNI_RESULT_SET_NULL = 0x2355; // invalid JNI result set
|
public static final int ERROR_JNI_RESULT_SET_NULL = 0x2355; // invalid JNI result set
|
||||||
|
@ -51,11 +56,16 @@ public class TSDBErrorNumbers {
|
||||||
errorNumbers.add(ERROR_PARAMETER_INDEX_OUT_RANGE);
|
errorNumbers.add(ERROR_PARAMETER_INDEX_OUT_RANGE);
|
||||||
errorNumbers.add(ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED);
|
errorNumbers.add(ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED);
|
||||||
errorNumbers.add(ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
errorNumbers.add(ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
|
||||||
|
errorNumbers.add(ERROR_CANNOT_REGISTER_JNI_DRIVER);
|
||||||
|
errorNumbers.add(ERROR_CANNOT_REGISTER_RESTFUL_DRIVER);
|
||||||
|
errorNumbers.add(ERROR_URL_NOT_SET);
|
||||||
|
errorNumbers.add(ERROR_INVALID_SQL);
|
||||||
|
errorNumbers.add(ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
errorNumbers.add(ERROR_UNKNOWN_TAOS_TYPE_IN_TDENGINE);
|
||||||
|
|
||||||
/*****************************************************/
|
/*****************************************************/
|
||||||
errorNumbers.add(ERROR_SUBSCRIBE_FAILED);
|
errorNumbers.add(ERROR_SUBSCRIBE_FAILED);
|
||||||
errorNumbers.add(ERROR_UNSUPPORTED_ENCODING);
|
errorNumbers.add(ERROR_UNSUPPORTED_ENCODING);
|
||||||
|
|
||||||
errorNumbers.add(ERROR_JNI_TDENGINE_ERROR);
|
errorNumbers.add(ERROR_JNI_TDENGINE_ERROR);
|
||||||
errorNumbers.add(ERROR_JNI_CONNECTION_NULL);
|
errorNumbers.add(ERROR_JNI_CONNECTION_NULL);
|
||||||
errorNumbers.add(ERROR_JNI_RESULT_SET_NULL);
|
errorNumbers.add(ERROR_JNI_RESULT_SET_NULL);
|
||||||
|
@ -63,7 +73,6 @@ public class TSDBErrorNumbers {
|
||||||
errorNumbers.add(ERROR_JNI_SQL_NULL);
|
errorNumbers.add(ERROR_JNI_SQL_NULL);
|
||||||
errorNumbers.add(ERROR_JNI_FETCH_END);
|
errorNumbers.add(ERROR_JNI_FETCH_END);
|
||||||
errorNumbers.add(ERROR_JNI_OUT_OF_MEMORY);
|
errorNumbers.add(ERROR_JNI_OUT_OF_MEMORY);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TSDBErrorNumbers() {
|
private TSDBErrorNumbers() {
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
/**
|
/**
|
||||||
* *************************************************************************
|
* *************************************************************************
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
*
|
* <p>
|
||||||
* This program is free software: you can use, redistribute, and/or modify
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License, version 3
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
*
|
* <p>
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*
|
* <p>
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
**************************************************************************** */
|
* ***************************************************************************
|
||||||
|
*/
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
import com.taosdata.jdbc.utils.TaosInfo;
|
import com.taosdata.jdbc.utils.TaosInfo;
|
||||||
|
@ -23,7 +24,7 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JNI connector
|
* JNI connector
|
||||||
* */
|
*/
|
||||||
public class TSDBJNIConnector {
|
public class TSDBJNIConnector {
|
||||||
private static volatile Boolean isInitialized = false;
|
private static volatile Boolean isInitialized = false;
|
||||||
|
|
||||||
|
@ -72,13 +73,13 @@ public class TSDBJNIConnector {
|
||||||
if (!isInitialized) {
|
if (!isInitialized) {
|
||||||
initImp(configDir);
|
initImp(configDir);
|
||||||
if (setOptions(0, locale) < 0) {
|
if (setOptions(0, locale) < 0) {
|
||||||
throw new SQLWarning(TSDBConstants.WrapErrMsg("Failed to set locale: " + locale + ". System default will be used."));
|
throw TSDBError.createSQLWarning("Failed to set locale: " + locale + ". System default will be used.");
|
||||||
}
|
}
|
||||||
if (setOptions(1, charset) < 0) {
|
if (setOptions(1, charset) < 0) {
|
||||||
throw new SQLWarning(TSDBConstants.WrapErrMsg("Failed to set charset: " + charset + ". System default will be used."));
|
throw TSDBError.createSQLWarning("Failed to set charset: " + charset + ". System default will be used.");
|
||||||
}
|
}
|
||||||
if (setOptions(2, timezone) < 0) {
|
if (setOptions(2, timezone) < 0) {
|
||||||
throw new SQLWarning(TSDBConstants.WrapErrMsg("Failed to set timezone: " + timezone + ". System default will be used."));
|
throw TSDBError.createSQLWarning("Failed to set timezone: " + timezone + ". System default will be used.");
|
||||||
}
|
}
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
TaosGlobalConfig.setCharset(getTsCharset());
|
TaosGlobalConfig.setCharset(getTsCharset());
|
||||||
|
|
|
@ -27,8 +27,8 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
private final TSDBResultSetRowData rowData;
|
private final TSDBResultSetRowData rowData;
|
||||||
private final TSDBResultSetBlockData blockData;
|
private final TSDBResultSetBlockData blockData;
|
||||||
|
|
||||||
private boolean batchFetch = false;
|
private boolean batchFetch;
|
||||||
private boolean lastWasNull = false;
|
private boolean lastWasNull;
|
||||||
private boolean isClosed;
|
private boolean isClosed;
|
||||||
|
|
||||||
public void setBatchFetch(boolean batchFetch) {
|
public void setBatchFetch(boolean batchFetch) {
|
||||||
|
@ -86,7 +86,6 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
if (rowData != null) {
|
if (rowData != null) {
|
||||||
this.rowData.clear();
|
this.rowData.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = this.jniConnector.fetchRow(this.resultSetPointer, this.rowData);
|
int code = this.jniConnector.fetchRow(this.resultSetPointer, this.rowData);
|
||||||
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
|
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
|
@ -124,30 +123,27 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
String res = null;
|
String res = null;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
if (!lastWasNull) {
|
|
||||||
res = this.rowData.getString(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
return this.blockData.getString(colIndex);
|
return this.blockData.getString(colIndex);
|
||||||
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
if (!lastWasNull) {
|
||||||
|
res = this.rowData.getString(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBoolean(int columnIndex) throws SQLException {
|
public boolean getBoolean(int columnIndex) throws SQLException {
|
||||||
boolean res = false;
|
boolean res = false;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
if (!lastWasNull) {
|
|
||||||
res = this.rowData.getBoolean(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return this.blockData.getBoolean(colIndex);
|
return this.blockData.getBoolean(colIndex);
|
||||||
}
|
|
||||||
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
if (!lastWasNull) {
|
||||||
|
res = this.rowData.getBoolean(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,91 +151,84 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
byte res = 0;
|
byte res = 0;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
if (!lastWasNull) {
|
|
||||||
res = (byte) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
return (byte) this.blockData.getInt(colIndex);
|
return (byte) this.blockData.getInt(colIndex);
|
||||||
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
if (!lastWasNull) {
|
||||||
|
res = (byte) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getShort(int columnIndex) throws SQLException {
|
public short getShort(int columnIndex) throws SQLException {
|
||||||
short res = 0;
|
short res = 0;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
if (!lastWasNull) {
|
|
||||||
res = (short) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
return (short) this.blockData.getInt(colIndex);
|
return (short) this.blockData.getInt(colIndex);
|
||||||
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
if (!lastWasNull) {
|
||||||
|
res = (short) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInt(int columnIndex) throws SQLException {
|
public int getInt(int columnIndex) throws SQLException {
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
if (!lastWasNull) {
|
|
||||||
res = this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
return this.blockData.getInt(colIndex);
|
return this.blockData.getInt(colIndex);
|
||||||
}
|
|
||||||
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
if (!lastWasNull) {
|
||||||
|
res = this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLong(int columnIndex) throws SQLException {
|
public long getLong(int columnIndex) throws SQLException {
|
||||||
long res = 0L;
|
long res = 0L;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
if (!lastWasNull) {
|
|
||||||
res = this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
return this.blockData.getLong(colIndex);
|
return this.blockData.getLong(colIndex);
|
||||||
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
if (!lastWasNull) {
|
||||||
|
res = this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getFloat(int columnIndex) throws SQLException {
|
public float getFloat(int columnIndex) throws SQLException {
|
||||||
float res = 0;
|
float res = 0;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
if (!lastWasNull) {
|
|
||||||
res = this.rowData.getFloat(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
return (float) this.blockData.getDouble(colIndex);
|
return (float) this.blockData.getDouble(colIndex);
|
||||||
}
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
if (!lastWasNull)
|
||||||
|
res = this.rowData.getFloat(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDouble(int columnIndex) throws SQLException {
|
public double getDouble(int columnIndex) throws SQLException {
|
||||||
double res = 0;
|
double res = 0;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
if (!lastWasNull) {
|
|
||||||
res = this.rowData.getDouble(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
return this.blockData.getDouble(colIndex);
|
return this.blockData.getDouble(colIndex);
|
||||||
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
if (!lastWasNull) {
|
||||||
|
res = this.rowData.getDouble(colIndex, this.columnMetaDataList.get(colIndex).getColType());
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -255,15 +244,14 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
Timestamp res = null;
|
Timestamp res = null;
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
if (!lastWasNull) {
|
|
||||||
res = this.rowData.getTimestamp(colIndex);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
return this.blockData.getTimestamp(columnIndex);
|
return this.blockData.getTimestamp(columnIndex);
|
||||||
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
if (!lastWasNull) {
|
||||||
|
res = this.rowData.getTimestamp(colIndex);
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultSetMetaData getMetaData() throws SQLException {
|
public ResultSetMetaData getMetaData() throws SQLException {
|
||||||
|
@ -274,12 +262,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public Object getObject(int columnIndex) throws SQLException {
|
public Object getObject(int columnIndex) throws SQLException {
|
||||||
int colIndex = getTrueColumnIndex(columnIndex);
|
int colIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
|
||||||
if (!this.getBatchFetch()) {
|
if (this.getBatchFetch())
|
||||||
this.lastWasNull = this.rowData.wasNull(colIndex);
|
|
||||||
return this.rowData.get(colIndex);
|
|
||||||
} else {
|
|
||||||
return this.blockData.get(colIndex);
|
return this.blockData.get(colIndex);
|
||||||
}
|
|
||||||
|
this.lastWasNull = this.rowData.wasNull(colIndex);
|
||||||
|
return this.rowData.get(colIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,468 +30,472 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TSDBResultSetBlockData {
|
public class TSDBResultSetBlockData {
|
||||||
private int numOfRows = 0;
|
private int numOfRows = 0;
|
||||||
private int rowIndex = 0;
|
private int rowIndex = 0;
|
||||||
|
|
||||||
private List<ColumnMetaData> columnMetaDataList;
|
private List<ColumnMetaData> columnMetaDataList;
|
||||||
private ArrayList<Object> colData = null;
|
private ArrayList<Object> colData = null;
|
||||||
|
|
||||||
public TSDBResultSetBlockData(List<ColumnMetaData> colMeta, int numOfCols) {
|
public TSDBResultSetBlockData(List<ColumnMetaData> colMeta, int numOfCols) {
|
||||||
this.columnMetaDataList = colMeta;
|
this.columnMetaDataList = colMeta;
|
||||||
this.colData = new ArrayList<Object>(numOfCols);
|
this.colData = new ArrayList<Object>(numOfCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TSDBResultSetBlockData() {
|
public TSDBResultSetBlockData() {
|
||||||
this.colData = new ArrayList<Object>();
|
this.colData = new ArrayList<Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
int size = this.colData.size();
|
int size = this.colData.size();
|
||||||
if (this.colData != null) {
|
if (this.colData != null) {
|
||||||
this.colData.clear();
|
this.colData.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
setNumOfCols(size);
|
setNumOfCols(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumOfRows() {
|
public int getNumOfRows() {
|
||||||
return this.numOfRows;
|
return this.numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumOfRows(int numOfRows) {
|
public void setNumOfRows(int numOfRows) {
|
||||||
this.numOfRows = numOfRows;
|
this.numOfRows = numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumOfCols() {
|
public int getNumOfCols() {
|
||||||
return this.colData.size();
|
return this.colData.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumOfCols(int numOfCols) {
|
public void setNumOfCols(int numOfCols) {
|
||||||
this.colData = new ArrayList<Object>(numOfCols);
|
this.colData = new ArrayList<Object>(numOfCols);
|
||||||
this.colData.addAll(Collections.nCopies(numOfCols, null));
|
this.colData.addAll(Collections.nCopies(numOfCols, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMore() {
|
public boolean hasMore() {
|
||||||
return this.rowIndex < this.numOfRows;
|
return this.rowIndex < this.numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean forward() {
|
public boolean forward() {
|
||||||
if (this.rowIndex > this.numOfRows) {
|
if (this.rowIndex > this.numOfRows) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((++this.rowIndex) < this.numOfRows);
|
return ((++this.rowIndex) < this.numOfRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
this.rowIndex = 0;
|
this.rowIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoolean(int col, boolean value) {
|
public void setBoolean(int col, boolean value) {
|
||||||
colData.set(col, value);
|
colData.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setByteArray(int col, int length, byte[] value) {
|
public void setByteArray(int col, int length, byte[] value) {
|
||||||
try {
|
try {
|
||||||
switch (this.columnMetaDataList.get(col).getColType()) {
|
switch (this.columnMetaDataList.get(col).getColType()) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN).asCharBuffer();
|
buf.order(ByteOrder.LITTLE_ENDIAN).asCharBuffer();
|
||||||
this.colData.set(col, buf);
|
this.colData.set(col, buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
this.colData.set(col, buf);
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
break;
|
this.colData.set(col, buf);
|
||||||
}
|
break;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
|
}
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
|
||||||
ShortBuffer sb = buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
|
||||||
this.colData.set(col, sb);
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
break;
|
ShortBuffer sb = buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
|
||||||
}
|
this.colData.set(col, sb);
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
break;
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
}
|
||||||
IntBuffer ib = buf.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
|
case TSDBConstants.TSDB_DATA_TYPE_UINT:
|
||||||
this.colData.set(col, ib);
|
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||||
break;
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
}
|
IntBuffer ib = buf.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
|
this.colData.set(col, ib);
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
break;
|
||||||
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
|
}
|
||||||
this.colData.set(col, lb);
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT:
|
||||||
break;
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
|
||||||
}
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
|
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
this.colData.set(col, lb);
|
||||||
FloatBuffer fb = buf.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
|
break;
|
||||||
this.colData.set(col, fb);
|
}
|
||||||
break;
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
|
||||||
}
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
FloatBuffer fb = buf.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
this.colData.set(col, fb);
|
||||||
DoubleBuffer db = buf.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer();
|
break;
|
||||||
this.colData.set(col, db);
|
}
|
||||||
break;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||||
}
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
DoubleBuffer db = buf.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer();
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
this.colData.set(col, db);
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
break;
|
||||||
this.colData.set(col, buf);
|
}
|
||||||
break;
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||||
}
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
this.colData.set(col, buf);
|
||||||
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
|
break;
|
||||||
this.colData.set(col, lb);
|
}
|
||||||
break;
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||||
}
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
|
LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
|
||||||
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
this.colData.set(col, lb);
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
break;
|
||||||
this.colData.set(col, buf);
|
}
|
||||||
break;
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
|
||||||
}
|
ByteBuffer buf = ByteBuffer.wrap(value, 0, length);
|
||||||
}
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
} catch (Exception e) {
|
this.colData.set(col, buf);
|
||||||
e.printStackTrace();
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
private static class NullType {
|
e.printStackTrace();
|
||||||
private static final byte NULL_BOOL_VAL = 0x2;
|
}
|
||||||
private static final String NULL_STR = "null";
|
}
|
||||||
|
|
||||||
public String toString() {
|
private static class NullType {
|
||||||
return NullType.NULL_STR;
|
private static final byte NULL_BOOL_VAL = 0x2;
|
||||||
}
|
private static final String NULL_STR = "null";
|
||||||
|
|
||||||
public static boolean isBooleanNull(byte val) {
|
public String toString() {
|
||||||
return val == NullType.NULL_BOOL_VAL;
|
return NullType.NULL_STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isTinyIntNull(byte val) {
|
public static boolean isBooleanNull(byte val) {
|
||||||
return val == Byte.MIN_VALUE;
|
return val == NullType.NULL_BOOL_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isSmallIntNull(short val) {
|
private static boolean isTinyIntNull(byte val) {
|
||||||
return val == Short.MIN_VALUE;
|
return val == Byte.MIN_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isIntNull(int val) {
|
private static boolean isSmallIntNull(short val) {
|
||||||
return val == Integer.MIN_VALUE;
|
return val == Short.MIN_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isBigIntNull(long val) {
|
private static boolean isIntNull(int val) {
|
||||||
return val == Long.MIN_VALUE;
|
return val == Integer.MIN_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isFloatNull(float val) {
|
private static boolean isBigIntNull(long val) {
|
||||||
return Float.isNaN(val);
|
return val == Long.MIN_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isDoubleNull(double val) {
|
private static boolean isFloatNull(float val) {
|
||||||
return Double.isNaN(val);
|
return Float.isNaN(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isBinaryNull(byte[] val, int length) {
|
private static boolean isDoubleNull(double val) {
|
||||||
if (length != Byte.BYTES) {
|
return Double.isNaN(val);
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
private static boolean isBinaryNull(byte[] val, int length) {
|
||||||
return val[0] == 0xFF;
|
if (length != Byte.BYTES) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
private static boolean isNcharNull(byte[] val, int length) {
|
|
||||||
if (length != Integer.BYTES) {
|
return val[0] == 0xFF;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
private static boolean isNcharNull(byte[] val, int length) {
|
||||||
return (val[0] & val[1] & val[2] & val[3]) == 0xFF;
|
if (length != Integer.BYTES) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
return (val[0] & val[1] & val[2] & val[3]) == 0xFF;
|
||||||
/**
|
}
|
||||||
* The original type may not be a string type, but will be converted to by
|
|
||||||
* calling this method
|
}
|
||||||
*
|
|
||||||
* @param col column index
|
/**
|
||||||
* @return
|
* The original type may not be a string type, but will be converted to by
|
||||||
* @throws SQLException
|
* calling this method
|
||||||
*/
|
*
|
||||||
public String getString(int col) throws SQLException {
|
* @param col column index
|
||||||
Object obj = get(col);
|
* @return
|
||||||
if (obj == null) {
|
* @throws SQLException
|
||||||
return new NullType().toString();
|
*/
|
||||||
}
|
public String getString(int col) throws SQLException {
|
||||||
|
Object obj = get(col);
|
||||||
return obj.toString();
|
if (obj == null) {
|
||||||
}
|
return new NullType().toString();
|
||||||
|
}
|
||||||
public int getInt(int col) {
|
|
||||||
Object obj = get(col);
|
return obj.toString();
|
||||||
if (obj == null) {
|
}
|
||||||
return 0;
|
|
||||||
}
|
public int getInt(int col) {
|
||||||
|
Object obj = get(col);
|
||||||
int type = this.columnMetaDataList.get(col).getColType();
|
if (obj == null) {
|
||||||
switch (type) {
|
return 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
int type = this.columnMetaDataList.get(col).getColType();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
switch (type) {
|
||||||
return (int) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||||
return ((Long) obj).intValue();
|
return (int) obj;
|
||||||
}
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
return ((Long) obj).intValue();
|
||||||
return ((Double) obj).intValue();
|
}
|
||||||
}
|
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
return ((Double) obj).intValue();
|
||||||
return Integer.parseInt((String) obj);
|
}
|
||||||
}
|
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||||
return 0;
|
return Integer.parseInt((String) obj);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public boolean getBoolean(int col) throws SQLException {
|
|
||||||
Object obj = get(col);
|
return 0;
|
||||||
if (obj == null) {
|
}
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
public boolean getBoolean(int col) throws SQLException {
|
||||||
|
Object obj = get(col);
|
||||||
int type = this.columnMetaDataList.get(col).getColType();
|
if (obj == null) {
|
||||||
switch (type) {
|
return Boolean.FALSE;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
int type = this.columnMetaDataList.get(col).getColType();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
switch (type) {
|
||||||
return ((int) obj == 0L) ? Boolean.FALSE : Boolean.TRUE;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||||
return (((Long) obj) == 0L) ? Boolean.FALSE : Boolean.TRUE;
|
return ((int) obj == 0L) ? Boolean.FALSE : Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
return (((Long) obj) == 0L) ? Boolean.FALSE : Boolean.TRUE;
|
||||||
return (((Double) obj) == 0) ? Boolean.FALSE : Boolean.TRUE;
|
}
|
||||||
}
|
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
return (((Double) obj) == 0) ? Boolean.FALSE : Boolean.TRUE;
|
||||||
if ("TRUE".compareToIgnoreCase((String) obj) == 0) {
|
}
|
||||||
return Boolean.TRUE;
|
|
||||||
} else if ("FALSE".compareToIgnoreCase((String) obj) == 0) {
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
return Boolean.TRUE;
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||||
} else {
|
if ("TRUE".compareToIgnoreCase((String) obj) == 0) {
|
||||||
throw new SQLDataException();
|
return Boolean.TRUE;
|
||||||
}
|
} else if ("FALSE".compareToIgnoreCase((String) obj) == 0) {
|
||||||
}
|
return Boolean.TRUE;
|
||||||
}
|
} else {
|
||||||
|
throw new SQLDataException();
|
||||||
return Boolean.FALSE;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public long getLong(int col) throws SQLException {
|
|
||||||
Object obj = get(col);
|
return Boolean.FALSE;
|
||||||
if (obj == null) {
|
}
|
||||||
return 0;
|
|
||||||
}
|
public long getLong(int col) throws SQLException {
|
||||||
|
Object obj = get(col);
|
||||||
int type = this.columnMetaDataList.get(col).getColType();
|
if (obj == null) {
|
||||||
switch (type) {
|
return 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
int type = this.columnMetaDataList.get(col).getColType();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
switch (type) {
|
||||||
return (int) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||||
return (long) obj;
|
return (int) obj;
|
||||||
}
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
return (long) obj;
|
||||||
return ((Double) obj).longValue();
|
}
|
||||||
}
|
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
return ((Double) obj).longValue();
|
||||||
return Long.parseLong((String) obj);
|
}
|
||||||
}
|
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||||
return 0;
|
return Long.parseLong((String) obj);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public Timestamp getTimestamp(int col) {
|
|
||||||
try {
|
return 0;
|
||||||
return new Timestamp(getLong(col));
|
}
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
public Timestamp getTimestamp(int col) {
|
||||||
}
|
try {
|
||||||
|
return new Timestamp(getLong(col));
|
||||||
return null;
|
} catch (SQLException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
|
}
|
||||||
public double getDouble(int col) {
|
|
||||||
Object obj = get(col);
|
return null;
|
||||||
if (obj == null) {
|
}
|
||||||
return 0;
|
|
||||||
}
|
public double getDouble(int col) {
|
||||||
|
Object obj = get(col);
|
||||||
int type = this.columnMetaDataList.get(col).getColType();
|
if (obj == null) {
|
||||||
switch (type) {
|
return 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
int type = this.columnMetaDataList.get(col).getColType();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
switch (type) {
|
||||||
return (int) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||||
return (long) obj;
|
return (int) obj;
|
||||||
}
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
return (long) obj;
|
||||||
return (double) obj;
|
}
|
||||||
}
|
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
return (double) obj;
|
||||||
return Double.parseDouble((String) obj);
|
}
|
||||||
}
|
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||||
return 0;
|
return Double.parseDouble((String) obj);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public Object get(int col) {
|
|
||||||
int fieldSize = this.columnMetaDataList.get(col).getColSize();
|
return 0;
|
||||||
|
}
|
||||||
switch (this.columnMetaDataList.get(col).getColType()) {
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
|
public Object get(int col) {
|
||||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
int fieldSize = this.columnMetaDataList.get(col).getColSize();
|
||||||
|
|
||||||
byte val = bb.get(this.rowIndex);
|
switch (this.columnMetaDataList.get(col).getColType()) {
|
||||||
if (NullType.isBooleanNull(val)) {
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
|
||||||
return null;
|
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||||
}
|
|
||||||
|
byte val = bb.get(this.rowIndex);
|
||||||
return (val == 0x0) ? Boolean.FALSE : Boolean.TRUE;
|
if (NullType.isBooleanNull(val)) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
|
|
||||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
return (val == 0x0) ? Boolean.FALSE : Boolean.TRUE;
|
||||||
|
}
|
||||||
byte val = bb.get(this.rowIndex);
|
|
||||||
if (NullType.isTinyIntNull(val)) {
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
|
||||||
return null;
|
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||||
}
|
|
||||||
|
byte val = bb.get(this.rowIndex);
|
||||||
return val;
|
if (NullType.isTinyIntNull(val)) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
|
|
||||||
ShortBuffer sb = (ShortBuffer) this.colData.get(col);
|
return val;
|
||||||
short val = sb.get(this.rowIndex);
|
}
|
||||||
if (NullType.isSmallIntNull(val)) {
|
|
||||||
return null;
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
|
||||||
}
|
ShortBuffer sb = (ShortBuffer) this.colData.get(col);
|
||||||
|
short val = sb.get(this.rowIndex);
|
||||||
return val;
|
if (NullType.isSmallIntNull(val)) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
|
||||||
IntBuffer ib = (IntBuffer) this.colData.get(col);
|
return val;
|
||||||
int val = ib.get(this.rowIndex);
|
}
|
||||||
if (NullType.isIntNull(val)) {
|
|
||||||
return null;
|
case TSDBConstants.TSDB_DATA_TYPE_INT: {
|
||||||
}
|
IntBuffer ib = (IntBuffer) this.colData.get(col);
|
||||||
|
int val = ib.get(this.rowIndex);
|
||||||
return val;
|
if (NullType.isIntNull(val)) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
|
return val;
|
||||||
LongBuffer lb = (LongBuffer) this.colData.get(col);
|
}
|
||||||
long val = lb.get(this.rowIndex);
|
|
||||||
if (NullType.isBigIntNull(val)) {
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
return null;
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
|
||||||
}
|
LongBuffer lb = (LongBuffer) this.colData.get(col);
|
||||||
|
long val = lb.get(this.rowIndex);
|
||||||
return (long) val;
|
if (NullType.isBigIntNull(val)) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
|
|
||||||
FloatBuffer fb = (FloatBuffer) this.colData.get(col);
|
return (long) val;
|
||||||
float val = fb.get(this.rowIndex);
|
}
|
||||||
if (NullType.isFloatNull(val)) {
|
|
||||||
return null;
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
|
||||||
}
|
FloatBuffer fb = (FloatBuffer) this.colData.get(col);
|
||||||
|
float val = fb.get(this.rowIndex);
|
||||||
return val;
|
if (NullType.isFloatNull(val)) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
|
||||||
DoubleBuffer lb = (DoubleBuffer) this.colData.get(col);
|
return val;
|
||||||
double val = lb.get(this.rowIndex);
|
}
|
||||||
if (NullType.isDoubleNull(val)) {
|
|
||||||
return null;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
|
||||||
}
|
DoubleBuffer lb = (DoubleBuffer) this.colData.get(col);
|
||||||
|
double val = lb.get(this.rowIndex);
|
||||||
return val;
|
if (NullType.isDoubleNull(val)) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
|
||||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
return val;
|
||||||
bb.position(fieldSize * this.rowIndex);
|
}
|
||||||
|
|
||||||
int length = bb.getShort();
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
|
||||||
|
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||||
byte[] dest = new byte[length];
|
bb.position(fieldSize * this.rowIndex);
|
||||||
bb.get(dest, 0, length);
|
|
||||||
if (NullType.isBinaryNull(dest, length)) {
|
int length = bb.getShort();
|
||||||
return null;
|
|
||||||
}
|
byte[] dest = new byte[length];
|
||||||
|
bb.get(dest, 0, length);
|
||||||
return new String(dest);
|
if (NullType.isBinaryNull(dest, length)) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
|
|
||||||
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
return new String(dest);
|
||||||
bb.position(fieldSize * this.rowIndex);
|
}
|
||||||
|
|
||||||
int length = bb.getShort();
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR: {
|
||||||
|
ByteBuffer bb = (ByteBuffer) this.colData.get(col);
|
||||||
byte[] dest = new byte[length];
|
bb.position(fieldSize * this.rowIndex);
|
||||||
bb.get(dest, 0, length);
|
|
||||||
if (NullType.isNcharNull(dest, length)) {
|
int length = bb.getShort();
|
||||||
return null;
|
|
||||||
}
|
byte[] dest = new byte[length];
|
||||||
|
bb.get(dest, 0, length);
|
||||||
try {
|
if (NullType.isNcharNull(dest, length)) {
|
||||||
String ss = TaosGlobalConfig.getCharset();
|
return null;
|
||||||
return new String(dest, ss);
|
}
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
e.printStackTrace();
|
try {
|
||||||
}
|
String ss = TaosGlobalConfig.getCharset();
|
||||||
}
|
return new String(dest, ss);
|
||||||
}
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
return 0;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,34 +126,12 @@ public class TSDBResultSetMetaData extends WrapperImpl implements ResultSetMetaD
|
||||||
|
|
||||||
public int getColumnType(int column) throws SQLException {
|
public int getColumnType(int column) throws SQLException {
|
||||||
ColumnMetaData meta = this.colMetaDataList.get(column - 1);
|
ColumnMetaData meta = this.colMetaDataList.get(column - 1);
|
||||||
switch (meta.getColType()) {
|
return TSDBConstants.taosType2JdbcType(meta.getColType());
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
|
||||||
return Types.BOOLEAN;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
|
||||||
return java.sql.Types.TINYINT;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
|
||||||
return java.sql.Types.SMALLINT;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
|
||||||
return java.sql.Types.INTEGER;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
|
||||||
return java.sql.Types.BIGINT;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
|
||||||
return java.sql.Types.FLOAT;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
|
||||||
return java.sql.Types.DOUBLE;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
|
||||||
return Types.BINARY;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
|
||||||
return java.sql.Types.TIMESTAMP;
|
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
|
||||||
return Types.NCHAR;
|
|
||||||
}
|
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnTypeName(int column) throws SQLException {
|
public String getColumnTypeName(int column) throws SQLException {
|
||||||
ColumnMetaData meta = this.colMetaDataList.get(column - 1);
|
ColumnMetaData meta = this.colMetaDataList.get(column - 1);
|
||||||
return TSDBConstants.DATATYPE_MAP.get(meta.getColType());
|
return TSDBConstants.taosType2JdbcTypeName(meta.getColType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReadOnly(int column) throws SQLException {
|
public boolean isReadOnly(int column) throws SQLException {
|
||||||
|
|
|
@ -14,208 +14,322 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class TSDBResultSetRowData {
|
public class TSDBResultSetRowData {
|
||||||
private ArrayList<Object> data = null;
|
private ArrayList<Object> data = null;
|
||||||
private int colSize = 0;
|
private int colSize = 0;
|
||||||
|
|
||||||
public TSDBResultSetRowData(int colSize) {
|
public TSDBResultSetRowData(int colSize) {
|
||||||
this.setColSize(colSize);
|
this.setColSize(colSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TSDBResultSetRowData() {
|
public TSDBResultSetRowData() {
|
||||||
this.data = new ArrayList<>();
|
this.data = new ArrayList<>();
|
||||||
this.setColSize(0);
|
this.setColSize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
if(this.data != null) {
|
if (this.data != null) {
|
||||||
this.data.clear();
|
this.data.clear();
|
||||||
}
|
}
|
||||||
if (this.colSize == 0) {
|
if (this.colSize == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.data = new ArrayList<>(colSize);
|
this.data = new ArrayList<>(colSize);
|
||||||
this.data.addAll(Collections.nCopies(this.colSize, null));
|
this.data.addAll(Collections.nCopies(this.colSize, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean wasNull(int col) {
|
public boolean wasNull(int col) {
|
||||||
return data.get(col) == null;
|
return data.get(col) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 srcType) throws SQLException {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col);
|
||||||
|
|
||||||
switch(srcType) {
|
switch (srcType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return (Boolean) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj) == 1.0? Boolean.TRUE:Boolean.FALSE;
|
return (Boolean) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double) obj) == 1.0? Boolean.TRUE:Boolean.FALSE;
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return ((Byte) obj) == 1? Boolean.TRUE:Boolean.FALSE;
|
return ((Float) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return ((Short)obj) == 1? Boolean.TRUE:Boolean.FALSE;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: return ((Integer)obj) == 1? Boolean.TRUE:Boolean.FALSE;
|
return ((Double) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj) == 1L? Boolean.TRUE:Boolean.FALSE;
|
return ((Byte) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
return ((Short) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return ((Integer) obj) == 1 ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return ((Long) obj) == 1L ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setByte(int col, byte value) {
|
public void setByte(int col, byte value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShort(int col, short value) {
|
public void setShort(int col, short value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInt(int col, int value) {
|
public void setInt(int col, int value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInt(int col, int srcType) throws SQLException {
|
public int getInt(int col, int srcType) throws SQLException {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col);
|
||||||
|
|
||||||
switch(srcType) {
|
switch (srcType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).intValue();
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double)obj).intValue();
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj;
|
return ((Float) obj).intValue();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj;
|
return ((Double) obj).intValue();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj).intValue();
|
return (Byte) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Integer.parseInt((String) obj);
|
return (Short) obj;
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return (Integer) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return ((Long) obj).intValue();
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
return Integer.parseInt((String) obj);
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: {
|
||||||
|
Byte value = (byte) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: {
|
||||||
|
short value = (short) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT: {
|
||||||
|
int value = (int) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
|
||||||
|
long value = (long) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return new Long(value).intValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 srcType) throws SQLException {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col);
|
||||||
|
|
||||||
switch(srcType) {
|
switch (srcType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).longValue();
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double) obj).longValue();
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj;
|
return ((Float) obj).longValue();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj;
|
return ((Double) obj).longValue();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj;
|
return (Byte) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Long.parseLong((String) obj);
|
return (Short) obj;
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return (Integer) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return (Long) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
|
return Long.parseLong((String) obj);
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: {
|
||||||
|
Byte value = (byte) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: {
|
||||||
|
short value = (short) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT: {
|
||||||
|
int value = (int) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
|
||||||
|
long value = (long) obj;
|
||||||
|
if (value < 0)
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) throws SQLException {
|
public float getFloat(int col, int srcType) throws SQLException {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col);
|
||||||
|
|
||||||
switch(srcType) {
|
switch (srcType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return (Float) obj;
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double) obj).floatValue();
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj;
|
return (Float) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: return (Short) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj;
|
return ((Double) obj).floatValue();
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj;
|
return (Byte) obj;
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
return (Short) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return (Integer) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return (Long) obj;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) throws SQLException {
|
public double getDouble(int col, int srcType) throws SQLException {
|
||||||
Object obj = data.get(col);
|
Object obj = data.get(col);
|
||||||
|
|
||||||
switch(srcType) {
|
switch (srcType) {
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0;
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return (Float) obj;
|
return Boolean.TRUE.equals(obj) ? 1 : 0;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return (Double) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj;
|
return (Float) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj;
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj;
|
return (Double) obj;
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj;
|
return (Byte) obj;
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
return (Short) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
|
return (Integer) obj;
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return (Long) obj;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setString(int col, String value) {
|
public void setString(int col, String value) {
|
||||||
data.set(col, value);
|
data.set(col, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setByteArray(int col, byte[] value) {
|
public void setByteArray(int col, byte[] value) {
|
||||||
try {
|
try {
|
||||||
data.set(col, new String(value, TaosGlobalConfig.getCharset()));
|
data.set(col, new String(value, TaosGlobalConfig.getCharset()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The original type may not be a string type, but will be converted to by calling this method
|
* The original type may not be a string type, but will be converted to by calling this method
|
||||||
* @param col column index
|
*
|
||||||
* @return
|
* @param col column index
|
||||||
* @throws SQLException
|
* @return
|
||||||
*/
|
* @throws SQLException
|
||||||
public String getString(int col, int srcType) throws SQLException {
|
*/
|
||||||
if (srcType == TSDBConstants.TSDB_DATA_TYPE_BINARY || srcType == TSDBConstants.TSDB_DATA_TYPE_NCHAR) {
|
public String getString(int col, int srcType) throws SQLException {
|
||||||
return (String) data.get(col);
|
switch (srcType) {
|
||||||
} else {
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
return String.valueOf(data.get(col));
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
}
|
return (String) data.get(col);
|
||||||
}
|
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: {
|
||||||
|
Byte value = new Byte(String.valueOf(data.get(col)));
|
||||||
|
if (value >= 0)
|
||||||
|
return value.toString();
|
||||||
|
return Integer.toString(value & 0xff);
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: {
|
||||||
|
Short value = new Short(String.valueOf(data.get(col)));
|
||||||
|
if (value >= 0)
|
||||||
|
return value.toString();
|
||||||
|
return Integer.toString(value & 0xffff);
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UINT: {
|
||||||
|
Integer value = new Integer(String.valueOf(data.get(col)));
|
||||||
|
if (value >= 0)
|
||||||
|
return value.toString();
|
||||||
|
return Long.toString(value & 0xffffffffl);
|
||||||
|
}
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
|
||||||
|
Long value = new Long(String.valueOf(data.get(col)));
|
||||||
|
if (value >= 0)
|
||||||
|
return value.toString();
|
||||||
|
long lowValue = value & 0x7fffffffffffffffL;
|
||||||
|
return BigDecimal.valueOf(lowValue).add(BigDecimal.valueOf(Long.MAX_VALUE)).add(BigDecimal.valueOf(1)).toString();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return String.valueOf(data.get(col));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setTimestamp(int col, long ts) {
|
public void setTimestamp(int col, long ts) {
|
||||||
data.set(col, ts);
|
data.set(col, ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp getTimestamp(int col) {
|
public Timestamp getTimestamp(int col) {
|
||||||
return new Timestamp((Long) data.get(col));
|
return new Timestamp((Long) data.get(col));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(int col) {
|
public Object get(int col) {
|
||||||
return data.get(col);
|
return data.get(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColSize() {
|
public int getColSize() {
|
||||||
return colSize;
|
return colSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColSize(int colSize) {
|
public void setColSize(int colSize) {
|
||||||
this.colSize = colSize;
|
this.colSize = colSize;
|
||||||
this.clear();
|
this.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Object> getData() {
|
public ArrayList<Object> getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(ArrayList<Object> data) {
|
public void setData(ArrayList<Object> data) {
|
||||||
this.data = (ArrayList<Object>) data.clone();
|
this.data = (ArrayList<Object>) data.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,6 @@ public class TSDBStatement extends AbstractStatement {
|
||||||
this.connector.freeResultSet(pSql);
|
this.connector.freeResultSet(pSql);
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBResultSet res = new TSDBResultSet(this, this.connector, pSql);
|
TSDBResultSet res = new TSDBResultSet(this, this.connector, pSql);
|
||||||
res.setBatchFetch(this.connection.getBatchFetch());
|
res.setBatchFetch(this.connection.getBatchFetch());
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -21,27 +21,23 @@ public class TSDBSubscribe {
|
||||||
private final long id;
|
private final long id;
|
||||||
|
|
||||||
TSDBSubscribe(TSDBJNIConnector connecter, long id) throws SQLException {
|
TSDBSubscribe(TSDBJNIConnector connecter, long id) throws SQLException {
|
||||||
if (null != connecter) {
|
if (connecter == null)
|
||||||
this.connecter = connecter;
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
this.id = id;
|
|
||||||
} else {
|
this.connecter = connecter;
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
this.id = id;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* consume
|
* consume
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public TSDBResultSet consume() throws SQLException {
|
public TSDBResultSet consume() throws SQLException {
|
||||||
if (this.connecter.isClosed()) {
|
if (this.connecter.isClosed())
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
}
|
|
||||||
|
|
||||||
long resultSetPointer = this.connecter.consume(this.id);
|
long resultSetPointer = this.connecter.consume(this.id);
|
||||||
|
|
||||||
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
|
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
|
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,9 +52,9 @@ public class TSDBSubscribe {
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public void close(boolean keepProgress) throws SQLException {
|
public void close(boolean keepProgress) throws SQLException {
|
||||||
if (this.connecter.isClosed()) {
|
if (this.connecter.isClosed())
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
}
|
|
||||||
this.connecter.unsubscribe(this.id, keepProgress);
|
this.connecter.unsubscribe(this.id, keepProgress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ public class RestfulConnection extends AbstractConnection {
|
||||||
public Statement createStatement() throws SQLException {
|
public Statement createStatement() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
;
|
|
||||||
|
|
||||||
return new RestfulStatement(this, database);
|
return new RestfulStatement(this, database);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,7 @@ package com.taosdata.jdbc.rs;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.taosdata.jdbc.AbstractDriver;
|
import com.taosdata.jdbc.*;
|
||||||
import com.taosdata.jdbc.TSDBConstants;
|
|
||||||
import com.taosdata.jdbc.TSDBDriver;
|
|
||||||
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
@ -21,15 +19,16 @@ public class RestfulDriver extends AbstractDriver {
|
||||||
try {
|
try {
|
||||||
DriverManager.registerDriver(new RestfulDriver());
|
DriverManager.registerDriver(new RestfulDriver());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(TSDBConstants.WrapErrMsg("can not register Restful JDBC driver"), e);
|
throw TSDBError.createRuntimeException(TSDBErrorNumbers.ERROR_URL_NOT_SET, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection connect(String url, Properties info) throws SQLException {
|
public Connection connect(String url, Properties info) throws SQLException {
|
||||||
// throw SQLException if url is null
|
// throw SQLException if url is null
|
||||||
if (url == null)
|
if (url == null || url.trim().isEmpty() || url.trim().replaceAll("\\s", "").isEmpty())
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is not set!"));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||||
|
|
||||||
// return null if url is not be accepted
|
// return null if url is not be accepted
|
||||||
if (!acceptsURL(url))
|
if (!acceptsURL(url))
|
||||||
return null;
|
return null;
|
||||||
|
@ -61,14 +60,20 @@ public class RestfulDriver extends AbstractDriver {
|
||||||
throw new SQLException(jsonResult.getString("desc"));
|
throw new SQLException(jsonResult.getString("desc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RestfulConnection(host, port, props, database, url);
|
RestfulConnection conn = new RestfulConnection(host, port, props, database, url);
|
||||||
|
if (database != null && !database.trim().replaceAll("\\s", "").isEmpty()) {
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
stmt.execute("use " + database);
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptsURL(String url) throws SQLException {
|
public boolean acceptsURL(String url) throws SQLException {
|
||||||
if (url == null)
|
if (url == null)
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is null"));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
|
||||||
return (url != null && url.length() > 0 && url.trim().length() > 0) && url.startsWith(URL_PREFIX);
|
return url.length() > 0 && url.trim().length() > 0 && url.startsWith(URL_PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -9,7 +9,6 @@ import com.taosdata.jdbc.TSDBErrorNumbers;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
private volatile boolean isClosed;
|
private volatile boolean isClosed;
|
||||||
|
@ -17,8 +16,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
|
|
||||||
private final String database;
|
private final String database;
|
||||||
private final Statement statement;
|
private final Statement statement;
|
||||||
|
// private final JSONObject resultJson;
|
||||||
// data
|
// data
|
||||||
private ArrayList<ArrayList<Object>> resultSet;
|
private final ArrayList<ArrayList<Object>> resultSet;
|
||||||
// meta
|
// meta
|
||||||
private ArrayList<String> columnNames;
|
private ArrayList<String> columnNames;
|
||||||
private ArrayList<Field> columns;
|
private ArrayList<Field> columns;
|
||||||
|
@ -32,6 +32,8 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public RestfulResultSet(String database, Statement statement, JSONObject resultJson) throws SQLException {
|
public RestfulResultSet(String database, Statement statement, JSONObject resultJson) throws SQLException {
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.statement = statement;
|
this.statement = statement;
|
||||||
|
// this.resultJson = resultJson;
|
||||||
|
|
||||||
// column metadata
|
// column metadata
|
||||||
JSONArray columnMeta = resultJson.getJSONArray("column_meta");
|
JSONArray columnMeta = resultJson.getJSONArray("column_meta");
|
||||||
columnNames = new ArrayList<>();
|
columnNames = new ArrayList<>();
|
||||||
|
@ -39,10 +41,11 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
for (int colIndex = 0; colIndex < columnMeta.size(); colIndex++) {
|
for (int colIndex = 0; colIndex < columnMeta.size(); colIndex++) {
|
||||||
JSONArray col = columnMeta.getJSONArray(colIndex);
|
JSONArray col = columnMeta.getJSONArray(colIndex);
|
||||||
String col_name = col.getString(0);
|
String col_name = col.getString(0);
|
||||||
int col_type = TSDBConstants.taosType2JdbcType(col.getInteger(1));
|
int taos_type = col.getInteger(1);
|
||||||
|
int col_type = TSDBConstants.taosType2JdbcType(taos_type);
|
||||||
int col_length = col.getInteger(2);
|
int col_length = col.getInteger(2);
|
||||||
columnNames.add(col_name);
|
columnNames.add(col_name);
|
||||||
columns.add(new Field(col_name, col_type, col_length, ""));
|
columns.add(new Field(col_name, col_type, col_length, "", taos_type));
|
||||||
}
|
}
|
||||||
this.metaData = new RestfulResultSetMetaData(this.database, columns, this);
|
this.metaData = new RestfulResultSetMetaData(this.database, columns, this);
|
||||||
|
|
||||||
|
@ -53,105 +56,50 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
ArrayList row = new ArrayList();
|
ArrayList row = new ArrayList();
|
||||||
JSONArray jsonRow = data.getJSONArray(rowIndex);
|
JSONArray jsonRow = data.getJSONArray(rowIndex);
|
||||||
for (int colIndex = 0; colIndex < jsonRow.size(); colIndex++) {
|
for (int colIndex = 0; colIndex < jsonRow.size(); colIndex++) {
|
||||||
row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).type));
|
row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).taos_type));
|
||||||
}
|
}
|
||||||
resultSet.add(row);
|
resultSet.add(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int columnIndex = 0;
|
|
||||||
for (; columnIndex < data.size(); columnIndex++) {
|
|
||||||
ArrayList oneRow = new ArrayList<>();
|
|
||||||
JSONArray one = data.getJSONArray(columnIndex);
|
|
||||||
for (int j = 0; j < one.size(); j++) {
|
|
||||||
oneRow.add(one.getString(j));
|
|
||||||
}
|
|
||||||
resultSet.add(oneRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
// column only names
|
|
||||||
JSONArray head = resultJson.getJSONArray("head");
|
|
||||||
for (int i = 0; i < head.size(); i++) {
|
|
||||||
String name = head.getString(i);
|
|
||||||
columnNames.add(name);
|
|
||||||
columns.add(new Field(name, "", 0, ""));
|
|
||||||
}
|
|
||||||
this.metaData = new RestfulResultSetMetaData(this.database, columns, this);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object parseColumnData(JSONArray row, int colIndex, int sqlType) {
|
private Object parseColumnData(JSONArray row, int colIndex, int taosType) {
|
||||||
switch (sqlType) {
|
switch (taosType) {
|
||||||
case Types.NULL:
|
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
|
||||||
return null;
|
|
||||||
case Types.BOOLEAN:
|
|
||||||
return row.getBoolean(colIndex);
|
return row.getBoolean(colIndex);
|
||||||
case Types.TINYINT:
|
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
|
||||||
case Types.SMALLINT:
|
return row.getByte(colIndex);
|
||||||
|
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
|
||||||
return row.getShort(colIndex);
|
return row.getShort(colIndex);
|
||||||
case Types.INTEGER:
|
case TSDBConstants.TSDB_DATA_TYPE_INT:
|
||||||
return row.getInteger(colIndex);
|
return row.getInteger(colIndex);
|
||||||
case Types.BIGINT:
|
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
|
||||||
return row.getBigInteger(colIndex);
|
return row.getBigInteger(colIndex);
|
||||||
case Types.FLOAT:
|
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
|
||||||
return row.getFloat(colIndex);
|
return row.getFloat(colIndex);
|
||||||
case Types.DOUBLE:
|
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
|
||||||
return row.getDouble(colIndex);
|
return row.getDouble(colIndex);
|
||||||
case Types.TIMESTAMP:
|
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
return new Timestamp(row.getDate(colIndex).getTime());
|
return new Timestamp(row.getDate(colIndex).getTime());
|
||||||
case Types.BINARY:
|
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
|
||||||
case Types.NCHAR:
|
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
|
||||||
default:
|
default:
|
||||||
return row.getString(colIndex);
|
return row.getString(colIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 由多个resultSet的JSON构造结果集
|
|
||||||
// *
|
|
||||||
// * @param resultJson: 包含data信息的结果集,有sql返回的结果集
|
|
||||||
// * @param fieldJson: 包含多个(最多2个)meta信息的结果集,有describe xxx
|
|
||||||
// **/
|
|
||||||
// public RestfulResultSet(String database, Statement statement, JSONObject resultJson, List<JSONObject> fieldJson) throws SQLException {
|
|
||||||
// this(database, statement, resultJson);
|
|
||||||
// ArrayList<Field> newColumns = new ArrayList<>();
|
|
||||||
//
|
|
||||||
// for (Field column : columns) {
|
|
||||||
// Field field = findField(column.name, fieldJson);
|
|
||||||
// if (field != null) {
|
|
||||||
// newColumns.add(field);
|
|
||||||
// } else {
|
|
||||||
// newColumns.add(column);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// this.columns = newColumns;
|
|
||||||
// this.metaData = new RestfulResultSetMetaData(this.database, this.columns, this);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public Field findField(String columnName, List<JSONObject> fieldJsonList) {
|
|
||||||
// for (JSONObject fieldJSON : fieldJsonList) {
|
|
||||||
// JSONArray fieldDataJson = fieldJSON.getJSONArray("data");
|
|
||||||
// for (int i = 0; i < fieldDataJson.size(); i++) {
|
|
||||||
// JSONArray field = fieldDataJson.getJSONArray(i);
|
|
||||||
// if (columnName.equalsIgnoreCase(field.getString(0))) {
|
|
||||||
// return new Field(field.getString(0), field.getString(1), field.getInteger(2), field.getString(3));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public class Field {
|
public class Field {
|
||||||
String name;
|
String name;
|
||||||
int type;
|
int type;
|
||||||
int length;
|
int length;
|
||||||
String note;
|
String note;
|
||||||
|
int taos_type;
|
||||||
|
|
||||||
public Field(String name, int type, int length, String note) {
|
public Field(String name, int type, int length, String note, int taos_type) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.note = note;
|
this.note = note;
|
||||||
|
this.taos_type = taos_type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,10 +132,8 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public String getString(int columnIndex) throws SQLException {
|
public String getString(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
if (columnIndex > resultSet.get(pos).size()) {
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return resultSet.get(pos).get(columnIndex).toString();
|
return resultSet.get(pos).get(columnIndex).toString();
|
||||||
|
@ -197,40 +143,107 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public boolean getBoolean(int columnIndex) throws SQLException {
|
public boolean getBoolean(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
int result = getInt(columnIndex);
|
int result = getInt(columnIndex);
|
||||||
return result == 0 ? false : true;
|
return result == 0 ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getByte(int columnIndex) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
|
Object value = resultSet.get(pos).get(columnIndex);
|
||||||
|
if (value == null)
|
||||||
|
return 0;
|
||||||
|
long valueAsLong = Long.parseLong(value.toString());
|
||||||
|
if (valueAsLong == Byte.MIN_VALUE)
|
||||||
|
return 0;
|
||||||
|
if (valueAsLong < Byte.MIN_VALUE || valueAsLong > Byte.MAX_VALUE)
|
||||||
|
throwRangeException(value.toString(), columnIndex, Types.TINYINT);
|
||||||
|
|
||||||
|
return (byte) valueAsLong;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void throwRangeException(String valueAsString, int columnIndex, int jdbcType) throws SQLException {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE,
|
||||||
|
"'" + valueAsString + "' in column '" + columnIndex + "' is outside valid range for the jdbcType " + TSDBConstants.jdbcType2TaosTypeName(jdbcType));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short getShort(int columnIndex) throws SQLException {
|
public short getShort(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return Short.parseShort(resultSet.get(pos).get(columnIndex).toString());
|
Object value = resultSet.get(pos).get(columnIndex);
|
||||||
|
if (value == null)
|
||||||
|
return 0;
|
||||||
|
long valueAsLong = Long.parseLong(value.toString());
|
||||||
|
if (valueAsLong == Short.MIN_VALUE)
|
||||||
|
return 0;
|
||||||
|
if (valueAsLong < Short.MIN_VALUE || valueAsLong > Short.MAX_VALUE)
|
||||||
|
throwRangeException(value.toString(), columnIndex, Types.SMALLINT);
|
||||||
|
return (short) valueAsLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInt(int columnIndex) throws SQLException {
|
public int getInt(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return Integer.parseInt(resultSet.get(pos).get(columnIndex).toString());
|
Object value = resultSet.get(pos).get(columnIndex);
|
||||||
|
if (value == null)
|
||||||
|
return 0;
|
||||||
|
long valueAsLong = Long.parseLong(value.toString());
|
||||||
|
if (valueAsLong == Integer.MIN_VALUE)
|
||||||
|
return 0;
|
||||||
|
if (valueAsLong < Integer.MIN_VALUE || valueAsLong > Integer.MAX_VALUE)
|
||||||
|
throwRangeException(value.toString(), columnIndex, Types.INTEGER);
|
||||||
|
return (int) valueAsLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLong(int columnIndex) throws SQLException {
|
public long getLong(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return Long.parseLong(resultSet.get(pos).get(columnIndex).toString());
|
Object value = resultSet.get(pos).get(columnIndex);
|
||||||
|
if (value == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
long valueAsLong = 0;
|
||||||
|
try {
|
||||||
|
valueAsLong = Long.parseLong(value.toString());
|
||||||
|
if (valueAsLong == Long.MIN_VALUE)
|
||||||
|
return 0;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throwRangeException(value.toString(), columnIndex, Types.BIGINT);
|
||||||
|
}
|
||||||
|
return valueAsLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getFloat(int columnIndex) throws SQLException {
|
public float getFloat(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return Float.parseFloat(resultSet.get(pos).get(columnIndex).toString());
|
return Float.parseFloat(resultSet.get(pos).get(columnIndex).toString());
|
||||||
}
|
}
|
||||||
|
@ -239,6 +252,8 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
public double getDouble(int columnIndex) throws SQLException {
|
public double getDouble(int columnIndex) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
|
||||||
|
if (columnIndex > resultSet.get(pos).size())
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size());
|
||||||
|
|
||||||
columnIndex = getTrueColumnIndex(columnIndex);
|
columnIndex = getTrueColumnIndex(columnIndex);
|
||||||
return Double.parseDouble(resultSet.get(pos).get(columnIndex).toString());
|
return Double.parseDouble(resultSet.get(pos).get(columnIndex).toString());
|
||||||
|
@ -246,12 +261,14 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
|
||||||
|
|
||||||
private int getTrueColumnIndex(int columnIndex) throws SQLException {
|
private int getTrueColumnIndex(int columnIndex) throws SQLException {
|
||||||
if (columnIndex < 1) {
|
if (columnIndex < 1) {
|
||||||
throw new SQLException("Column Index out of range, " + columnIndex + " < 1");
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE
|
||||||
|
, "Column Index out of range, " + columnIndex + " < 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
int numOfCols = resultSet.get(pos).size();
|
int numOfCols = resultSet.get(pos).size();
|
||||||
if (columnIndex > numOfCols) {
|
if (columnIndex > numOfCols) {
|
||||||
throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE
|
||||||
|
, "Column Index out of range, " + columnIndex + " > " + numOfCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
return columnIndex - 1;
|
return columnIndex - 1;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.taosdata.jdbc.rs;
|
package com.taosdata.jdbc.rs;
|
||||||
|
|
||||||
import com.taosdata.jdbc.TSDBConstants;
|
import com.taosdata.jdbc.TSDBConstants;
|
||||||
|
import com.taosdata.jdbc.WrapperImpl;
|
||||||
|
|
||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -8,7 +9,7 @@ import java.sql.Timestamp;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class RestfulResultSetMetaData implements ResultSetMetaData {
|
public class RestfulResultSetMetaData extends WrapperImpl implements ResultSetMetaData {
|
||||||
|
|
||||||
private final String database;
|
private final String database;
|
||||||
private ArrayList<RestfulResultSet.Field> fields;
|
private ArrayList<RestfulResultSet.Field> fields;
|
||||||
|
@ -20,6 +21,10 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<RestfulResultSet.Field> getFields() {
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColumnCount() throws SQLException {
|
public int getColumnCount() throws SQLException {
|
||||||
return fields.size();
|
return fields.size();
|
||||||
|
@ -134,8 +139,8 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getColumnTypeName(int column) throws SQLException {
|
public String getColumnTypeName(int column) throws SQLException {
|
||||||
int type = fields.get(column - 1).type;
|
int taos_type = fields.get(column - 1).taos_type;
|
||||||
return TSDBConstants.jdbcType2TaosTypeName(type);
|
return TSDBConstants.taosType2JdbcTypeName(taos_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -180,18 +185,4 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
return columnClassName;
|
return columnClassName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
|
||||||
try {
|
|
||||||
return iface.cast(this);
|
|
||||||
} catch (ClassCastException cce) {
|
|
||||||
throw new SQLException("Unable to unwrap to " + iface.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
|
||||||
return iface.isInstance(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,14 @@ import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.taosdata.jdbc.AbstractStatement;
|
import com.taosdata.jdbc.AbstractStatement;
|
||||||
import com.taosdata.jdbc.TSDBConstants;
|
|
||||||
import com.taosdata.jdbc.TSDBError;
|
import com.taosdata.jdbc.TSDBError;
|
||||||
import com.taosdata.jdbc.TSDBErrorNumbers;
|
import com.taosdata.jdbc.TSDBErrorNumbers;
|
||||||
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
import com.taosdata.jdbc.utils.HttpClientPoolUtil;
|
||||||
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.Connection;
|
||||||
import java.util.ArrayList;
|
import java.sql.ResultSet;
|
||||||
import java.util.Arrays;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class RestfulStatement extends AbstractStatement {
|
public class RestfulStatement extends AbstractStatement {
|
||||||
|
|
||||||
|
@ -30,39 +27,6 @@ public class RestfulStatement extends AbstractStatement {
|
||||||
this.database = database;
|
this.database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] parseTableIdentifier(String sql) {
|
|
||||||
sql = sql.trim().toLowerCase();
|
|
||||||
String[] ret = null;
|
|
||||||
if (sql.contains("where"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("where"));
|
|
||||||
if (sql.contains("interval"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("interval"));
|
|
||||||
if (sql.contains("fill"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("fill"));
|
|
||||||
if (sql.contains("sliding"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("sliding"));
|
|
||||||
if (sql.contains("group by"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("group by"));
|
|
||||||
if (sql.contains("order by"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("order by"));
|
|
||||||
if (sql.contains("slimit"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("slimit"));
|
|
||||||
if (sql.contains("limit"))
|
|
||||||
sql = sql.substring(0, sql.indexOf("limit"));
|
|
||||||
// parse
|
|
||||||
if (sql.contains("from")) {
|
|
||||||
sql = sql.substring(sql.indexOf("from") + 4).trim();
|
|
||||||
return Arrays.asList(sql.split(",")).stream()
|
|
||||||
.map(tableIdentifier -> {
|
|
||||||
tableIdentifier = tableIdentifier.trim();
|
|
||||||
if (tableIdentifier.contains(" "))
|
|
||||||
tableIdentifier = tableIdentifier.substring(0, tableIdentifier.indexOf(" "));
|
|
||||||
return tableIdentifier;
|
|
||||||
}).collect(Collectors.joining(",")).split(",");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet executeQuery(String sql) throws SQLException {
|
public ResultSet executeQuery(String sql) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
|
@ -75,9 +39,8 @@ public class RestfulStatement extends AbstractStatement {
|
||||||
return executeOneQuery(url, sql);
|
return executeOneQuery(url, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (this.database == null || this.database.isEmpty())
|
// if (this.database != null && !this.database.trim().replaceAll("\\s","").isEmpty())
|
||||||
// throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
// HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
|
||||||
return executeOneQuery(url, sql);
|
return executeOneQuery(url, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,10 +56,8 @@ public class RestfulStatement extends AbstractStatement {
|
||||||
return executeOneUpdate(url, sql);
|
return executeOneUpdate(url, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (this.database == null || this.database.isEmpty())
|
// if (this.database != null && !this.database.trim().replaceAll("\\s", "").isEmpty())
|
||||||
// throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
// HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||||
|
|
||||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
|
||||||
return executeOneUpdate(url, sql);
|
return executeOneUpdate(url, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,24 +109,9 @@ public class RestfulStatement extends AbstractStatement {
|
||||||
String result = HttpClientPoolUtil.execute(url, sql);
|
String result = HttpClientPoolUtil.execute(url, sql);
|
||||||
JSONObject resultJson = JSON.parseObject(result);
|
JSONObject resultJson = JSON.parseObject(result);
|
||||||
if (resultJson.getString("status").equals("error")) {
|
if (resultJson.getString("status").equals("error")) {
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code")));
|
throw TSDBError.createSQLException(resultJson.getInteger("code"), resultJson.getString("desc"));
|
||||||
}
|
}
|
||||||
// parse table name from sql
|
|
||||||
// String[] tableIdentifiers = parseTableIdentifier(sql);
|
|
||||||
// if (tableIdentifiers != null) {
|
|
||||||
// List<JSONObject> fieldJsonList = new ArrayList<>();
|
|
||||||
// for (String tableIdentifier : tableIdentifiers) {
|
|
||||||
// String fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + tableIdentifier);
|
|
||||||
// JSONObject fieldJson = JSON.parseObject(fields);
|
|
||||||
// if (fieldJson.getString("status").equals("error")) {
|
|
||||||
// throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + fieldJson.getString("desc") + "\n" + "error code: " + fieldJson.getString("code")));
|
|
||||||
// }
|
|
||||||
// fieldJsonList.add(fieldJson);
|
|
||||||
// }
|
|
||||||
// this.resultSet = new RestfulResultSet(database, this, resultJson, fieldJsonList);
|
|
||||||
// } else {
|
|
||||||
this.resultSet = new RestfulResultSet(database, this, resultJson);
|
this.resultSet = new RestfulResultSet(database, this, resultJson);
|
||||||
// }
|
|
||||||
this.affectedRows = 0;
|
this.affectedRows = 0;
|
||||||
return resultSet;
|
return resultSet;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +123,7 @@ public class RestfulStatement extends AbstractStatement {
|
||||||
String result = HttpClientPoolUtil.execute(url, sql);
|
String result = HttpClientPoolUtil.execute(url, sql);
|
||||||
JSONObject jsonObject = JSON.parseObject(result);
|
JSONObject jsonObject = JSON.parseObject(result);
|
||||||
if (jsonObject.getString("status").equals("error")) {
|
if (jsonObject.getString("status").equals("error")) {
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonObject.getString("desc") + "\n" + "error code: " + jsonObject.getString("code")));
|
throw TSDBError.createSQLException(jsonObject.getInteger("code"), jsonObject.getString("desc"));
|
||||||
}
|
}
|
||||||
this.resultSet = null;
|
this.resultSet = null;
|
||||||
this.affectedRows = checkJsonResultSet(jsonObject);
|
this.affectedRows = checkJsonResultSet(jsonObject);
|
||||||
|
|
|
@ -15,12 +15,12 @@ public class TSDBJNIConnectorTest {
|
||||||
public void test() {
|
public void test() {
|
||||||
try {
|
try {
|
||||||
// init
|
// init
|
||||||
TSDBJNIConnector.init(null, null, null, null);
|
TSDBJNIConnector.init("/etc/taos/taos.cfg", null, null, null);
|
||||||
// connect
|
// connect
|
||||||
TSDBJNIConnector connector = new TSDBJNIConnector();
|
TSDBJNIConnector connector = new TSDBJNIConnector();
|
||||||
connector.connect("127.0.0.1", 6030, null, "root", "taosdata");
|
connector.connect("127.0.0.1", 6030, "unsign_jni", "root", "taosdata");
|
||||||
// executeQuery
|
// executeQuery
|
||||||
long pSql = connector.executeQuery("show variables");
|
long pSql = connector.executeQuery("select * from unsign_jni.us_table");
|
||||||
if (connector.isUpdateQuery(pSql)) {
|
if (connector.isUpdateQuery(pSql)) {
|
||||||
connector.freeResultSet(pSql);
|
connector.freeResultSet(pSql);
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
|
||||||
|
@ -29,13 +29,13 @@ public class TSDBJNIConnectorTest {
|
||||||
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
||||||
int code = connector.getSchemaMetaData(pSql, columnMetaDataList);
|
int code = connector.getSchemaMetaData(pSql, columnMetaDataList);
|
||||||
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
|
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
|
||||||
}
|
}
|
||||||
if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
|
if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
|
||||||
}
|
}
|
||||||
if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) {
|
if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) {
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0);
|
||||||
}
|
}
|
||||||
int columnSize = columnMetaDataList.size();
|
int columnSize = columnMetaDataList.size();
|
||||||
// print metadata
|
// print metadata
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
package com.taosdata.jdbc.cases;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class InsertDbwithoutUseDbTest {
|
||||||
|
|
||||||
|
private static String host = "127.0.0.1";
|
||||||
|
// private static String host = "master";
|
||||||
|
private static Properties properties;
|
||||||
|
private static Random random = new Random(System.currentTimeMillis());
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void case001() throws ClassNotFoundException, SQLException {
|
||||||
|
// prepare schema
|
||||||
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
|
String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata";
|
||||||
|
Connection conn = DriverManager.getConnection(url, properties);
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
stmt.execute("drop database if exists inWithoutDb");
|
||||||
|
stmt.execute("create database if not exists inWithoutDb");
|
||||||
|
stmt.execute("create table inWithoutDb.weather(ts timestamp, f1 int)");
|
||||||
|
}
|
||||||
|
conn.close();
|
||||||
|
|
||||||
|
// execute insert
|
||||||
|
url = "jdbc:TAOS://127.0.0.1:6030/inWithoutDb?user=root&password=taosdata";
|
||||||
|
conn = DriverManager.getConnection(url, properties);
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")");
|
||||||
|
Assert.assertEquals(1, affectedRow);
|
||||||
|
boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")");
|
||||||
|
Assert.assertEquals(false, flag);
|
||||||
|
ResultSet rs = stmt.executeQuery("select count(*) from weather");
|
||||||
|
rs.next();
|
||||||
|
int count = rs.getInt("count(*)");
|
||||||
|
Assert.assertEquals(2, count);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void case002() throws ClassNotFoundException, SQLException {
|
||||||
|
// prepare the schema
|
||||||
|
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||||
|
final String url = "jdbc:TAOS-RS://" + host + ":6041/inWithoutDb?user=root&password=taosdata";
|
||||||
|
Connection conn = DriverManager.getConnection(url, properties);
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
stmt.execute("drop database if exists inWithoutDb");
|
||||||
|
stmt.execute("create database if not exists inWithoutDb");
|
||||||
|
stmt.execute("create table inWithoutDb.weather(ts timestamp, f1 int)");
|
||||||
|
}
|
||||||
|
conn.close();
|
||||||
|
|
||||||
|
// execute
|
||||||
|
conn = DriverManager.getConnection(url, properties);
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")");
|
||||||
|
Assert.assertEquals(1, affectedRow);
|
||||||
|
boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")");
|
||||||
|
Assert.assertEquals(false, flag);
|
||||||
|
ResultSet rs = stmt.executeQuery("select count(*) from weather");
|
||||||
|
rs.next();
|
||||||
|
int count = rs.getInt("count(*)");
|
||||||
|
Assert.assertEquals(2, count);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() {
|
||||||
|
properties = new Properties();
|
||||||
|
properties.setProperty("charset", "UTF-8");
|
||||||
|
properties.setProperty("locale", "en_US.UTF-8");
|
||||||
|
properties.setProperty("timezone", "UTC-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,191 @@
|
||||||
|
package com.taosdata.jdbc.cases;
|
||||||
|
|
||||||
|
import com.taosdata.jdbc.TSDBDriver;
|
||||||
|
import org.junit.*;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class UnsignedNumberJniTest {
|
||||||
|
private static final String host = "127.0.0.1";
|
||||||
|
private static Connection conn;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase001() {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table");
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals("127", rs.getString(2));
|
||||||
|
Assert.assertEquals("32767", rs.getString(3));
|
||||||
|
Assert.assertEquals("2147483647", rs.getString(4));
|
||||||
|
Assert.assertEquals("9223372036854775807", rs.getString(5));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase002() {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table");
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals(127, rs.getByte(2));
|
||||||
|
Assert.assertEquals(32767, rs.getShort(3));
|
||||||
|
Assert.assertEquals(2147483647, rs.getInt(4));
|
||||||
|
Assert.assertEquals(9223372036854775807l, rs.getLong(5));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase003() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 32767,2147483647, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals(127, rs.getByte(2));
|
||||||
|
Assert.assertEquals(32767, rs.getShort(3));
|
||||||
|
Assert.assertEquals(2147483647, rs.getInt(4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase004() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 32767,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals(127, rs.getByte(2));
|
||||||
|
Assert.assertEquals(32767, rs.getShort(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase005() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
Assert.assertEquals(127, rs.getByte(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase006() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 254, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase007() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 254, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals("254", rs.getString(2));
|
||||||
|
Assert.assertEquals("65534", rs.getString(3));
|
||||||
|
Assert.assertEquals("4294967294", rs.getString(4));
|
||||||
|
Assert.assertEquals("18446744073709551614", rs.getString(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
|
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
|
||||||
|
conn = DriverManager.getConnection(url, properties);
|
||||||
|
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
stmt.execute("drop database if exists unsign_jni");
|
||||||
|
stmt.execute("create database if not exists unsign_jni");
|
||||||
|
stmt.execute("use unsign_jni");
|
||||||
|
stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)");
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(now, 127, 32767,2147483647, 9223372036854775807)");
|
||||||
|
stmt.close();
|
||||||
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() {
|
||||||
|
try {
|
||||||
|
if (conn != null)
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,177 @@
|
||||||
|
package com.taosdata.jdbc.cases;
|
||||||
|
|
||||||
|
import com.taosdata.jdbc.TSDBDriver;
|
||||||
|
import org.junit.*;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class UnsignedNumberRestfulTest {
|
||||||
|
private static final String host = "127.0.0.1";
|
||||||
|
// private static final String host = "master";
|
||||||
|
private static Connection conn;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase001() {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table");
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase002() {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table");
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase003() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 32767,2147483647, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase004() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 32767,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase005() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 127, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SQLException.class)
|
||||||
|
public void testCase006() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 254, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.print(meta.getColumnLabel(1) + ": " + rs.getTimestamp(1) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(2) + ": " + rs.getByte(2) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(3) + ": " + rs.getShort(3) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(4) + ": " + rs.getInt(4) + "\t");
|
||||||
|
System.out.print(meta.getColumnLabel(5) + ": " + rs.getLong(5) + "\t");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCase007() throws SQLException {
|
||||||
|
try (Statement stmt = conn.createStatement()) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + now + ", 254, 65534,4294967294, 18446744073709551614)");
|
||||||
|
ResultSet rs = stmt.executeQuery("select * from us_table where ts = " + now);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
Assert.assertEquals("254", rs.getString(2));
|
||||||
|
Assert.assertEquals("65534", rs.getString(3));
|
||||||
|
Assert.assertEquals("4294967294", rs.getString(4));
|
||||||
|
Assert.assertEquals("18446744073709551614", rs.getString(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||||
|
final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
||||||
|
conn = DriverManager.getConnection(url, properties);
|
||||||
|
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
stmt.execute("drop database if exists unsign_restful");
|
||||||
|
stmt.execute("create database if not exists unsign_restful");
|
||||||
|
stmt.execute("use unsign_restful");
|
||||||
|
stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)");
|
||||||
|
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(now, 127, 32767,2147483647, 9223372036854775807)");
|
||||||
|
stmt.close();
|
||||||
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() {
|
||||||
|
try {
|
||||||
|
if (conn != null)
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -40,9 +40,12 @@ public class RestfulResultSetTest {
|
||||||
Assert.assertEquals(true, f9);
|
Assert.assertEquals(true, f9);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
@Test
|
||||||
public void getByte() throws SQLException {
|
public void getByte() throws SQLException {
|
||||||
rs.getByte(1);
|
byte f8 = rs.getByte("f8");
|
||||||
|
Assert.assertEquals(10, f8);
|
||||||
|
f8 = rs.getByte(8);
|
||||||
|
Assert.assertEquals(10, f8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue