diff --git a/README.md b/README.md
index 2c33119e34305cbbfa114842e2589ddf87417100..0e1adcd97c61265ec0ad272043c9604736545b3d 100644
--- a/README.md
+++ b/README.md
@@ -131,10 +131,10 @@ cmake .. -DCPUTYPE=mips64 && cmake --build .
### On Windows platform
If you use the Visual Studio 2013, please open a command window by executing "cmd.exe".
-Please specify "x86_amd64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat.
+Please specify "amd64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat.
```cmd
mkdir debug && cd debug
-"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" < x86_amd64 | x86 >
+"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" < amd64 | x86 >
cmake .. -G "NMake Makefiles"
nmake
```
diff --git a/cmake/define.inc b/cmake/define.inc
index cc8bd0fc355847354b23453d2329bda88bfaa2b7..441bf199974549fbe0acd33b3f971c0b29742096 100755
--- a/cmake/define.inc
+++ b/cmake/define.inc
@@ -122,10 +122,14 @@ IF (TD_LINUX)
ADD_DEFINITIONS(-D_TD_NINGSI_60)
MESSAGE(STATUS "set ningsi macro to true")
ENDIF ()
-
- SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
+
+ IF (TD_MEMORY_SANITIZER)
+ SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -O0 -g3 -DDEBUG")
+ ELSE ()
+ SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
+ ENDIF ()
SET(RELEASE_FLAGS "-O3 -Wno-error")
-
+
IF (${COVER} MATCHES "true")
MESSAGE(STATUS "Test coverage mode, add extra flags")
SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
@@ -144,7 +148,11 @@ IF (TD_DARWIN_64)
ADD_DEFINITIONS(-DUSE_LIBICONV)
MESSAGE(STATUS "darwin64 is defined")
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
- SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
+ IF (TD_MEMORY_SANITIZER)
+ SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -O0 -g3 -DDEBUG")
+ ELSE ()
+ SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
+ ENDIF ()
SET(RELEASE_FLAGS "-Og")
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc)
@@ -162,7 +170,14 @@ IF (TD_WINDOWS)
IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
ENDIF ()
- SET(DEBUG_FLAGS "/fsanitize=thread /fsanitize=leak /fsanitize=memory /fsanitize=undefined /fsanitize=hwaddress /Zi /W3 /GL")
+
+ IF (TD_MEMORY_SANITIZER)
+MESSAGE("memory sanitizer detected as true")
+ SET(DEBUG_FLAGS "/fsanitize=address /Zi /W3 /GL")
+ ELSE ()
+MESSAGE("memory sanitizer detected as false")
+ SET(DEBUG_FLAGS "/Zi /W3 /GL")
+ ENDIF ()
SET(RELEASE_FLAGS "/W0 /O3 /GL")
ENDIF ()
@@ -171,7 +186,7 @@ IF (TD_WINDOWS)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/regex)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/wepoll/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/MsvcLibX/include)
-ENDIF ()
+ENDIF ()
IF (TD_WINDOWS_64)
ADD_DEFINITIONS(-D_M_X64)
diff --git a/cmake/input.inc b/cmake/input.inc
index 9b72a35d940ba5e3d79458bbe2455b0db2b59e14..c073bbbc037d105dbacea1e14981537cd31b7202 100755
--- a/cmake/input.inc
+++ b/cmake/input.inc
@@ -83,3 +83,8 @@ SET(TD_BUILD_JDBC TRUE)
IF (${BUILD_JDBC} MATCHES "false")
SET(TD_BUILD_JDBC FALSE)
ENDIF ()
+
+SET(TD_MEMORY_SANITIZER FALSE)
+IF (${MEMORY_SANITIZER} MATCHES "true")
+ SET(TD_MEMORY_SANITIZER TRUE)
+ENDIF ()
diff --git a/cmake/install.inc b/cmake/install.inc
index f8b3b7c3c62c16df537a941d7f14ccb74bc64217..63764348d339d992e8ff3be1036c1c9921fd7b99 100755
--- a/cmake/install.inc
+++ b/cmake/install.inc
@@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
IF (TD_MVN_INSTALLED)
- INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.29.jar DESTINATION connector/jdbc)
+ INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.30.jar DESTINATION connector/jdbc)
ENDIF ()
ELSEIF (TD_DARWIN)
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
diff --git a/documentation20/cn/03.architecture/docs.md b/documentation20/cn/03.architecture/docs.md
index 2668967102986952793cd0f000f32ae4cc5e1125..d22855198abc804d6cee5603b56537c9315d610e 100644
--- a/documentation20/cn/03.architecture/docs.md
+++ b/documentation20/cn/03.architecture/docs.md
@@ -176,7 +176,7 @@ TDengine 分布式架构的逻辑结构图如下:
**通讯方式:**TDengine系统的各个数据节点之间,以及应用驱动与各数据节点之间的通讯是通过TCP/UDP进行的。因为考虑到物联网场景,数据写入的包一般不大,因此TDengine 除采用TCP做传输之外,还采用UDP方式,因为UDP 更加高效,而且不受连接数的限制。TDengine实现了自己的超时、重传、确认等机制,以确保UDP的可靠传输。对于数据量不到15K的数据包,采取UDP的方式进行传输,超过15K的,或者是查询类的操作,自动采取TCP的方式进行传输。同时,TDengine根据配置和数据包,会自动对数据进行压缩/解压缩,数字签名/认证等处理。对于数据节点之间的数据复制,只采用TCP方式进行数据传输。
-**FQDN配置**:一个数据节点有一个或多个FQDN,可以在系统配置文件taos.cfg通过参数“fqdn"进行指定,如果没有指定,系统将自动获取计算机的hostname作为其FQDN。如果节点没有配置FQDN,可以直接将该节点的配置参数fqdn设置为它的IP地址。但不建议使用IP,因为IP地址可变,一旦变化,将让集群无法正常工作。一个数据节点的EP(End Point)由FQDN + Port组成。采用FQDN,需要保证DNS服务正常工作,或者在节点以及应用所在的节点配置好hosts文件。
+**FQDN配置**:一个数据节点有一个或多个FQDN,可以在系统配置文件taos.cfg通过参数“fqdn"进行指定,如果没有指定,系统将自动获取计算机的hostname作为其FQDN。如果节点没有配置FQDN,可以直接将该节点的配置参数fqdn设置为它的IP地址。但不建议使用IP,因为IP地址可变,一旦变化,将让集群无法正常工作。一个数据节点的EP(End Point)由FQDN + Port组成。采用FQDN,需要保证DNS服务正常工作,或者在节点以及应用所在的节点配置好hosts文件。另外,这个参数值的长度需要控制在 96 个字符以内。
**端口配置:**一个数据节点对外的端口由TDengine的系统配置参数serverPort决定,对集群内部通讯的端口是serverPort+5。集群内数据节点之间的数据复制操作还占有一个TCP端口,是serverPort+10. 为支持多线程高效的处理UDP数据,每个对内和对外的UDP连接,都需要占用5个连续的端口。因此一个数据节点总的端口范围为serverPort到serverPort + 10,总共11个TCP/UDP端口。(另外还可能有 RESTful、Arbitrator 所使用的端口,那样的话就一共是 13 个。)使用时,需要确保防火墙将这些端口打开,以备使用。每个数据节点可以配置不同的serverPort。(详细的端口情况请参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port))
diff --git a/documentation20/cn/08.connector/01.java/docs.md b/documentation20/cn/08.connector/01.java/docs.md
index ffea252c86b5b3eab41e93685e04dfcccccec879..e6d214c74d3367d814e0022d4c6a147c4a44b326 100644
--- a/documentation20/cn/08.connector/01.java/docs.md
+++ b/documentation20/cn/08.connector/01.java/docs.md
@@ -325,10 +325,12 @@ for (int i = 0; i < numOfRows; i++){
}
s.setString(2, s2, 10);
-// AddBatch 之后,可以再设定新的表名、TAGS、VALUES 取值,这样就能实现一次执行向多个数据表写入:
+// AddBatch 之后,缓存并未清空。为避免混乱,并不推荐在 ExecuteBatch 之前再次绑定新一批的数据:
s.columnDataAddBatch();
-// 执行语句:
+// 执行绑定数据后的语句:
s.columnDataExecuteBatch();
+// 执行语句后清空缓存。在清空之后,可以复用当前的对象,绑定新的一批数据(可以是新表名、新 TAGS 值、新 VALUES 值):
+s.columnDataClearBatch();
// 执行完毕,释放资源:
s.columnDataCloseBatch();
```
diff --git a/documentation20/cn/08.connector/docs.md b/documentation20/cn/08.connector/docs.md
index b6125e3cfea180007bc784868d7be6e9d3747244..8c22d50185d1c30459487682800241b48e782d95 100644
--- a/documentation20/cn/08.connector/docs.md
+++ b/documentation20/cn/08.connector/docs.md
@@ -307,6 +307,8 @@ TDengine的异步API均采用非阻塞调用模式。应用程序可以用多线
8. 调用 `taos_stmt_execute` 执行已经准备好的批处理指令;
9. 执行完毕,调用 `taos_stmt_close` 释放所有资源。
+说明:如果 `taos_stmt_execute` 执行成功,假如不需要改变 SQL 语句的话,那么是可以复用 `taos_stmt_prepare` 的解析结果,直接进行第 3~6 步绑定新数据的。但如果执行出错,那么并不建议继续在当前的环境上下文下继续工作,而是建议释放资源,然后从 `taos_stmt_init` 步骤重新开始。
+
除 C/C++ 语言外,TDengine 的 Java 语言 JNI Connector 也提供参数绑定接口支持,具体请另外参见:[参数绑定接口的 Java 用法](https://www.taosdata.com/cn/documentation/connector/java#stmt-java)。
接口相关的具体函数如下(也可以参考 [apitest.c](https://github.com/taosdata/TDengine/blob/develop/tests/examples/c/apitest.c) 文件中使用对应函数的方式):
@@ -378,6 +380,11 @@ typedef struct TAOS_MULTI_BIND {
执行完毕,释放所有资源。
+- `char * taos_stmt_errstr(TAOS_STMT *stmt)`
+
+ (2.1.3.0 版本新增)
+ 用于在其他 stmt API 返回错误(返回错误码或空指针)时获取错误信息。
+
### 连续查询接口
TDengine提供时间驱动的实时流式计算API。可以每隔一指定的时间段,对一张或多张数据库的表(数据流)进行各种实时聚合计算操作。操作简单,仅有打开、关闭流的API。具体如下:
diff --git a/documentation20/cn/11.administrator/docs.md b/documentation20/cn/11.administrator/docs.md
index ee2f34ff11ef5e69195c01d0b605383c3257f48c..d0e82a16c8a1faf5568b2b4dd930af5af6646bf4 100644
--- a/documentation20/cn/11.administrator/docs.md
+++ b/documentation20/cn/11.administrator/docs.md
@@ -99,7 +99,7 @@ taosd -C
下面仅仅列出一些重要的配置参数,更多的参数请看配置文件里的说明。各个参数的详细介绍及作用请看前述章节,而且这些参数的缺省配置都是工作的,一般无需设置。**注意:配置修改后,需要重启*taosd*服务才能生效。**
- firstEp: taosd启动时,主动连接的集群中首个dnode的end point, 默认值为localhost:6030。
-- fqdn:数据节点的FQDN,缺省为操作系统配置的第一个hostname。如果习惯IP地址访问,可设置为该节点的IP地址。
+- fqdn:数据节点的FQDN,缺省为操作系统配置的第一个hostname。如果习惯IP地址访问,可设置为该节点的IP地址。这个参数值的长度需要控制在 96 个字符以内。
- serverPort:taosd启动后,对外服务的端口号,默认值为6030。(RESTful服务使用的端口号是在此基础上+11,即默认值为6041。)
- dataDir: 数据文件目录,所有的数据文件都将写入该目录。默认值:/var/lib/taos。
- logDir:日志文件目录,客户端和服务器的运行日志文件将写入该目录。默认值:/var/log/taos。
diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h
index f747184ce017e9cb780ba2a61b87360cee0379d8..427431d3c00549da4008bb6a9879288b4685b92d 100644
--- a/src/client/inc/tscUtil.h
+++ b/src/client/inc/tscUtil.h
@@ -123,6 +123,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i
*/
bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
+bool tscIsDiffQuery(SQueryInfo* pQueryInfo);
bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo);
bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo);
bool tsIsArithmeticQueryOnAggResult(SQueryInfo* pQueryInfo);
@@ -132,7 +133,6 @@ bool hasTagValOutput(SQueryInfo* pQueryInfo);
bool timeWindowInterpoRequired(SQueryInfo *pQueryInfo);
bool isStabledev(SQueryInfo* pQueryInfo);
bool isTsCompQuery(SQueryInfo* pQueryInfo);
-bool isSimpleAggregate(SQueryInfo* pQueryInfo);
bool isBlockDistQuery(SQueryInfo* pQueryInfo);
bool isSimpleAggregateRv(SQueryInfo* pQueryInfo);
@@ -214,7 +214,7 @@ void tscColumnListDestroy(SArray* pColList);
void tscColumnListCopy(SArray* dst, const SArray* src, uint64_t tableUid);
void tscColumnListCopyAll(SArray* dst, const SArray* src);
-void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo);
+void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo, uint64_t objId);
void tscDequoteAndTrimToken(SStrToken* pToken);
int32_t tscValidateName(SStrToken* pToken);
@@ -329,9 +329,7 @@ STableMeta* tscTableMetaDup(STableMeta* pTableMeta);
SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo);
int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr);
-
-void tsCreateSQLFunctionCtx(SQueryInfo* pQueryInfo, SQLFunctionCtx* pCtx, SSchema* pSchema);
-void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pOperator, char* sql, void* addr, int32_t stage);
+void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pOperator, char* sql, void* addr, int32_t stage, uint64_t qId);
void* malloc_throw(size_t size);
void* calloc_throw(size_t nmemb, size_t size);
diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h
index c002f2cf323a03ec024f4ebc41e04ac7e6c07571..5a0dcf6208be2b95268dd2df2d83bc185d96fde5 100644
--- a/src/client/inc/tsclient.h
+++ b/src/client/inc/tsclient.h
@@ -320,7 +320,7 @@ int32_t tscCreateResPointerInfo(SSqlRes *pRes, SQueryInfo *pQueryInfo);
void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo);
void tscSetResRawPtrRv(SSqlRes* pRes, SQueryInfo* pQueryInfo, SSDataBlock* pBlock);
-void handleDownstreamOperator(SSqlObj** pSqlList, int32_t numOfUpstream, SQueryInfo* px, SSqlRes* pOutput);
+void handleDownstreamOperator(SSqlObj** pSqlList, int32_t numOfUpstream, SQueryInfo* px, SSqlObj* pParent);
void destroyTableNameList(SInsertStatementParam* pInsertParam);
void tscResetSqlCmd(SSqlCmd *pCmd, bool removeMeta);
diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c
index 15276a38887523541cbe37ebf1add2152d2ffe80..d857d00e159d06df266187693913a6b6e404a2b3 100644
--- a/src/client/src/tscAsync.c
+++ b/src/client/src/tscAsync.c
@@ -144,7 +144,7 @@ static void tscAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows) {
}
// local merge has handle this situation during super table non-projection query.
- if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE) {
+ if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE) {
pRes->numOfClauseTotal += pRes->numOfRows;
}
@@ -174,7 +174,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo
}
pSql->fp = fp;
- if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) {
+ if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE && pCmd->command < TSDB_SQL_LOCAL) {
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
}
@@ -257,14 +257,14 @@ void taos_fetch_rows_a(TAOS_RES *tres, __async_cb_func_t fp, void *param) {
}
return;
- } else if (pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE) {
+ } else if (pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE) {
// in case of show command, return no data
(*pSql->fetchFp)(param, pSql, 0);
} else {
assert(0);
}
} else { // current query is not completed, continue retrieve from node
- if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) {
+ if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE && pCmd->command < TSDB_SQL_LOCAL) {
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
}
diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c
index f97f54a6267d2754cb2edf2fd38ff6c075a2b285..2c9717306f2b26dfbbb5ec1d676b5baad3eb2d2d 100644
--- a/src/client/src/tscLocal.c
+++ b/src/client/src/tscLocal.c
@@ -323,7 +323,7 @@ TAOS_ROW tscFetchRow(void *param) {
// current data set are exhausted, fetch more data from node
if (pRes->row >= pRes->numOfRows && (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) &&
(pCmd->command == TSDB_SQL_RETRIEVE ||
- pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE ||
+ pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE ||
pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE ||
pCmd->command == TSDB_SQL_FETCH ||
pCmd->command == TSDB_SQL_SHOW ||
diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c
index f199a5798779523e90e95bfce468a68b8afb6c6d..3f12bc811bd2508583397c37723b498c710088d1 100644
--- a/src/client/src/tscPrepare.c
+++ b/src/client/src/tscPrepare.c
@@ -78,6 +78,16 @@ typedef struct STscStmt {
SNormalStmt normal;
} STscStmt;
+#define STMT_RET(c) do { \
+ int32_t _code = c; \
+ if (pStmt && pStmt->pSql) { pStmt->pSql->res.code = _code; } else {terrno = _code;} \
+ return _code; \
+} while (0)
+
+static int32_t invalidOperationMsg(char* dstBuffer, const char* errMsg) {
+ return tscInvalidOperationMsg(dstBuffer, errMsg, NULL);
+}
+
static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_t len) {
uint16_t size = stmt->numParts + 1;
if (size > stmt->sizeParts) {
@@ -163,8 +173,8 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
break;
default:
- tscDebug("0x%"PRIx64" bind column%d: type mismatch or invalid", stmt->pSql->self, i);
- return TSDB_CODE_TSC_INVALID_VALUE;
+ tscError("0x%"PRIx64" bind column%d: type mismatch or invalid", stmt->pSql->self, i);
+ return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind type mismatch or invalid");
}
}
@@ -727,6 +737,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param,
#endif
if (bind->buffer_type != param->type) {
+ tscError("column type mismatch");
return TSDB_CODE_TSC_INVALID_VALUE;
}
@@ -754,6 +765,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param,
case TSDB_DATA_TYPE_BINARY:
if ((*bind->length) > (uintptr_t)param->bytes) {
+ tscError("column length is too big");
return TSDB_CODE_TSC_INVALID_VALUE;
}
size = (short)*bind->length;
@@ -763,6 +775,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param,
case TSDB_DATA_TYPE_NCHAR: {
int32_t output = 0;
if (!taosMbsToUcs4(bind->buffer, *bind->length, varDataVal(data + param->offset), param->bytes - VARSTR_HEADER_SIZE, &output)) {
+ tscError("convert nchar failed");
return TSDB_CODE_TSC_INVALID_VALUE;
}
varDataSetLen(data + param->offset, output);
@@ -787,6 +800,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param,
static int doBindBatchParam(STableDataBlocks* pBlock, SParamInfo* param, TAOS_MULTI_BIND* bind, int32_t rowNum) {
if (bind->buffer_type != param->type || !isValidDataType(param->type)) {
+ tscError("column mismatch or invalid");
return TSDB_CODE_TSC_INVALID_VALUE;
}
@@ -892,8 +906,8 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
int code = doBindParam(pBlock, data, param, &bind[param->idx], 1);
if (code != TSDB_CODE_SUCCESS) {
- tscDebug("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx);
- return code;
+ tscDebug("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx);
+ return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind column type mismatch or invalid");
}
}
@@ -957,13 +971,13 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_MULTI_BIND* bind, int c
SParamInfo* param = &pBlock->params[j];
if (bind[param->idx].num != rowNum) {
tscError("0x%"PRIx64" param %d: num[%d:%d] not match", pStmt->pSql->self, param->idx, rowNum, bind[param->idx].num);
- return TSDB_CODE_TSC_INVALID_VALUE;
+ return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind row num mismatch");
}
int code = doBindBatchParam(pBlock, param, &bind[param->idx], pCmd->batchSize);
if (code != TSDB_CODE_SUCCESS) {
tscError("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx);
- return code;
+ return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind column type mismatch or invalid");
}
}
@@ -974,7 +988,7 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_MULTI_BIND* bind, int c
int code = doBindBatchParam(pBlock, param, bind, pCmd->batchSize);
if (code != TSDB_CODE_SUCCESS) {
tscError("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx);
- return code;
+ return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind column type mismatch or invalid");
}
if (colIdx == (pBlock->numOfParams - 1)) {
@@ -993,7 +1007,7 @@ static int insertStmtUpdateBatch(STscStmt* stmt) {
if (pCmd->batchSize > INT16_MAX) {
tscError("too many record:%d", pCmd->batchSize);
- return TSDB_CODE_TSC_APP_ERROR;
+ return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "too many records");
}
if (taosHashGetSize(pCmd->insertParam.pTableBlockHashList) == 0) {
@@ -1057,7 +1071,8 @@ static int insertStmtReset(STscStmt* pStmt) {
static int insertStmtExecute(STscStmt* stmt) {
SSqlCmd* pCmd = &stmt->pSql->cmd;
if (pCmd->batchSize == 0) {
- return TSDB_CODE_TSC_INVALID_VALUE;
+ tscError("no records bind");
+ return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "no records bind");
}
if (taosHashGetSize(pCmd->insertParam.pTableBlockHashList) == 0) {
@@ -1174,7 +1189,7 @@ static int insertBatchStmtExecute(STscStmt* pStmt) {
if(pStmt->mtb.nameSet == false) {
tscError("0x%"PRIx64" no table name set", pStmt->pSql->self);
- return TSDB_CODE_TSC_APP_ERROR;
+ return invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "no table name set");
}
pStmt->pSql->retry = pStmt->pSql->maxRetry + 1; //no retry
@@ -1215,7 +1230,8 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) {
int32_t index = 0;
SStrToken sToken = tStrGetToken(pCmd->insertParam.sql, &index, false);
if (sToken.n == 0) {
- return TSDB_CODE_TSC_INVALID_OPERATION;
+ tscError("table is is expected, sql:%s", pCmd->insertParam.sql);
+ return tscSQLSyntaxErrMsg(pCmd->payload, "table name is expected", pCmd->insertParam.sql);
}
if (sToken.n == 1 && sToken.type == TK_QUESTION) {
@@ -1237,24 +1253,28 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) {
return TSDB_CODE_SUCCESS;
}
- if (sToken.n <= 0 || sToken.type != TK_USING) {
- return tscSQLSyntaxErrMsg(pCmd->payload, "keywords USING is expected", sToken.z);
+ if (sToken.n <= 0 || sToken.type != TK_USING) {
+ tscError("keywords USING is expected, sql:%s", pCmd->insertParam.sql);
+ return tscSQLSyntaxErrMsg(pCmd->payload, "keywords USING is expected", sToken.z ? sToken.z : pCmd->insertParam.sql);
}
sToken = tStrGetToken(pCmd->insertParam.sql, &index, false);
if (sToken.n <= 0 || ((sToken.type != TK_ID) && (sToken.type != TK_STRING))) {
- return tscSQLSyntaxErrMsg(pCmd->payload, "invalid token", sToken.z);
+ tscError("invalid token, sql:%s", pCmd->insertParam.sql);
+ return tscSQLSyntaxErrMsg(pCmd->payload, "invalid token", sToken.z ? sToken.z : pCmd->insertParam.sql);
}
pStmt->mtb.stbname = sToken;
sToken = tStrGetToken(pCmd->insertParam.sql, &index, false);
if (sToken.n <= 0 || sToken.type != TK_TAGS) {
- return tscSQLSyntaxErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z);
+ tscError("keyword TAGS expected, sql:%s", pCmd->insertParam.sql);
+ return tscSQLSyntaxErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z ? sToken.z : pCmd->insertParam.sql);
}
sToken = tStrGetToken(pCmd->insertParam.sql, &index, false);
if (sToken.n <= 0 || sToken.type != TK_LP) {
- return tscSQLSyntaxErrMsg(pCmd->payload, ") expected", sToken.z);
+ tscError("( expected, sql:%s", pCmd->insertParam.sql);
+ return tscSQLSyntaxErrMsg(pCmd->payload, "( expected", sToken.z ? sToken.z : pCmd->insertParam.sql);
}
pStmt->mtb.tags = taosArrayInit(4, sizeof(SStrToken));
@@ -1264,7 +1284,8 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) {
while (loopCont) {
sToken = tStrGetToken(pCmd->insertParam.sql, &index, false);
if (sToken.n <= 0) {
- return TSDB_CODE_TSC_INVALID_OPERATION;
+ tscError("unexpected sql end, sql:%s", pCmd->insertParam.sql);
+ return tscSQLSyntaxErrMsg(pCmd->payload, "unexpected sql end", pCmd->insertParam.sql);
}
switch (sToken.type) {
@@ -1272,7 +1293,8 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) {
loopCont = 0;
break;
case TK_VALUES:
- return TSDB_CODE_TSC_INVALID_OPERATION;
+ tscError("unexpected token values, sql:%s", pCmd->insertParam.sql);
+ return tscSQLSyntaxErrMsg(pCmd->payload, "unexpected token", sToken.z);
case TK_QUESTION:
pStmt->mtb.tagSet = false; //continue
default:
@@ -1282,12 +1304,14 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) {
}
if (taosArrayGetSize(pStmt->mtb.tags) <= 0) {
- return TSDB_CODE_TSC_INVALID_OPERATION;
+ tscError("no tags, sql:%s", pCmd->insertParam.sql);
+ return tscSQLSyntaxErrMsg(pCmd->payload, "no tags", pCmd->insertParam.sql);
}
sToken = tStrGetToken(pCmd->insertParam.sql, &index, false);
if (sToken.n <= 0 || (sToken.type != TK_VALUES && sToken.type != TK_LP)) {
- return TSDB_CODE_TSC_INVALID_OPERATION;
+ tscError("sql error, sql:%s", pCmd->insertParam.sql);
+ return tscSQLSyntaxErrMsg(pCmd->payload, "sql error", sToken.z ? sToken.z : pCmd->insertParam.sql);
}
pStmt->mtb.values = sToken;
@@ -1329,8 +1353,8 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO
} else {
if (tags[j].buffer == NULL) {
free(str);
- tscError("empty");
- return TSDB_CODE_TSC_APP_ERROR;
+ tscError("empty tag value in params");
+ return invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "empty tag value in params");
}
ret = converToStr(str + len, tags[j].buffer_type, tags[j].buffer, tags[j].length ? (int32_t)*tags[j].length : -1, &l);
@@ -1387,13 +1411,15 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO
TAOS_STMT* taos_stmt_init(TAOS* taos) {
STscObj* pObj = (STscObj*)taos;
+ STscStmt* pStmt = NULL;
+
if (pObj == NULL || pObj->signature != pObj) {
terrno = TSDB_CODE_TSC_DISCONNECTED;
tscError("connection disconnected");
return NULL;
}
- STscStmt* pStmt = calloc(1, sizeof(STscStmt));
+ pStmt = calloc(1, sizeof(STscStmt));
if (pStmt == NULL) {
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscError("failed to allocate memory for statement");
@@ -1410,6 +1436,14 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) {
return NULL;
}
+ if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) {
+ free(pSql);
+ free(pStmt);
+ terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
+ tscError("failed to malloc payload buffer");
+ return NULL;
+ }
+
tsem_init(&pSql->rspSem, 0, 0);
pSql->signature = pSql;
pSql->pTscObj = pObj;
@@ -1425,13 +1459,12 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
STscStmt* pStmt = (STscStmt*)stmt;
if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) {
- terrno = TSDB_CODE_TSC_DISCONNECTED;
- return TSDB_CODE_TSC_DISCONNECTED;
+ STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (pStmt->last != STMT_INIT) {
tscError("prepare status error, last:%d", pStmt->last);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "prepare status error"));
}
pStmt->last = STMT_PREPARE;
@@ -1447,17 +1480,11 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
pCmd->insertParam.insertType = TSDB_QUERY_TYPE_STMT_INSERT;
- if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) {
- tscError("%p failed to malloc payload buffer", pSql);
- return TSDB_CODE_TSC_OUT_OF_MEMORY;
- }
-
pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1);
if (pSql->sqlstr == NULL) {
tscError("%p failed to malloc sql string buffer", pSql);
- free(pCmd->payload);
- return TSDB_CODE_TSC_OUT_OF_MEMORY;
+ STMT_RET(TSDB_CODE_TSC_OUT_OF_MEMORY);
}
pRes->qId = 0;
@@ -1476,11 +1503,11 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
int32_t ret = stmtParseInsertTbTags(pSql, pStmt);
if (ret != TSDB_CODE_SUCCESS) {
- return ret;
+ STMT_RET(ret);
}
if (pStmt->multiTbInsert) {
- return TSDB_CODE_SUCCESS;
+ STMT_RET(TSDB_CODE_SUCCESS);
}
memset(&pStmt->mtb, 0, sizeof(pStmt->mtb));
@@ -1489,14 +1516,14 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
// wait for the callback function to post the semaphore
tsem_wait(&pSql->rspSem);
- return pSql->res.code;
+ STMT_RET(pSql->res.code);
}
- return code;
+ STMT_RET(code);
}
pStmt->isInsert = false;
- return normalStmtPrepare(pStmt);
+ STMT_RET(normalStmtPrepare(pStmt));
}
int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags) {
@@ -1505,25 +1532,22 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
SSqlCmd* pCmd = &pSql->cmd;
if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) {
- terrno = TSDB_CODE_TSC_DISCONNECTED;
- return TSDB_CODE_TSC_DISCONNECTED;
+ STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (name == NULL) {
- terrno = TSDB_CODE_TSC_APP_ERROR;
tscError("0x%"PRIx64" name is NULL", pSql->self);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "name is NULL"));
}
if (pStmt->multiTbInsert == false || !tscIsInsertData(pSql->sqlstr)) {
- terrno = TSDB_CODE_TSC_APP_ERROR;
- tscError("0x%"PRIx64" not multi table insert", pSql->self);
- return TSDB_CODE_TSC_APP_ERROR;
+ tscError("0x%"PRIx64" not multiple table insert", pSql->self);
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "not multiple table insert"));
}
if (pStmt->last == STMT_INIT || pStmt->last == STMT_BIND || pStmt->last == STMT_BIND_COL) {
- tscError("0x%"PRIx64" settbname status error, last:%d", pSql->self, pStmt->last);
- return TSDB_CODE_TSC_APP_ERROR;
+ tscError("0x%"PRIx64" set_tbname_tags status error, last:%d", pSql->self, pStmt->last);
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "set_tbname_tags status error"));
}
pStmt->last = STMT_SETTBNAME;
@@ -1535,7 +1559,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pStmt->mtb.pTableBlockHashList, (const char*)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid));
if (t1 == NULL) {
tscError("0x%"PRIx64" no table data block in hash list, uid:%" PRId64 , pSql->self, pStmt->mtb.currentUid);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(TSDB_CODE_TSC_APP_ERROR);
}
SSubmitBlk* pBlk = (SSubmitBlk*) (*t1)->pData;
@@ -1544,7 +1568,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
taosHashPut(pCmd->insertParam.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)t1, POINTER_BYTES);
tscDebug("0x%"PRIx64" table:%s is already prepared, uid:%" PRIu64, pSql->self, name, pStmt->mtb.currentUid);
- return TSDB_CODE_SUCCESS;
+ STMT_RET(TSDB_CODE_SUCCESS);
}
if (pStmt->mtb.tagSet) {
@@ -1552,12 +1576,12 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
} else {
if (tags == NULL) {
tscError("No tags set");
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "no tags set"));
}
int32_t ret = stmtGenInsertStatement(pSql, pStmt, name, tags);
if (ret != TSDB_CODE_SUCCESS) {
- return ret;
+ STMT_RET(ret);
}
}
@@ -1591,7 +1615,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
code = tscGetDataBlockFromList(pCmd->insertParam.pTableBlockHashList, pTableMeta->id.uid, TSDB_PAYLOAD_SIZE, sizeof(SSubmitBlk),
pTableMeta->tableInfo.rowSize, &pTableMetaInfo->name, pTableMeta, &pBlock, NULL);
if (code != TSDB_CODE_SUCCESS) {
- return code;
+ STMT_RET(code);
}
SSubmitBlk* blk = (SSubmitBlk*)pBlock->pData;
@@ -1606,7 +1630,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid);
}
- return code;
+ STMT_RET(code);
}
@@ -1639,35 +1663,34 @@ int taos_stmt_close(TAOS_STMT* stmt) {
}
taos_free_result(pStmt->pSql);
- free(pStmt);
- return TSDB_CODE_SUCCESS;
+ tfree(pStmt);
+ STMT_RET(TSDB_CODE_SUCCESS);
}
int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) {
STscStmt* pStmt = (STscStmt*)stmt;
if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) {
- terrno = TSDB_CODE_TSC_DISCONNECTED;
- return TSDB_CODE_TSC_DISCONNECTED;
+ STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (pStmt->isInsert) {
if (pStmt->multiTbInsert) {
if (pStmt->last != STMT_SETTBNAME && pStmt->last != STMT_ADD_BATCH) {
tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error"));
}
} else {
if (pStmt->last != STMT_PREPARE && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_EXECUTE) {
tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error"));
}
}
pStmt->last = STMT_BIND;
- return insertStmtBindParam(pStmt, bind);
+ STMT_RET(insertStmtBindParam(pStmt, bind));
} else {
- return normalStmtBindParam(pStmt, bind);
+ STMT_RET(normalStmtBindParam(pStmt, bind));
}
}
@@ -1676,69 +1699,67 @@ int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) {
STscStmt* pStmt = (STscStmt*)stmt;
if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) {
- terrno = TSDB_CODE_TSC_DISCONNECTED;
- return TSDB_CODE_TSC_DISCONNECTED;
+ STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (bind == NULL || bind->num <= 0 || bind->num > INT16_MAX) {
tscError("0x%"PRIx64" invalid parameter", pStmt->pSql->self);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "invalid bind param"));
}
if (!pStmt->isInsert) {
tscError("0x%"PRIx64" not or invalid batch insert", pStmt->pSql->self);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "not or invalid batch insert"));
}
if (pStmt->multiTbInsert) {
if (pStmt->last != STMT_SETTBNAME && pStmt->last != STMT_ADD_BATCH) {
tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error"));
}
} else {
if (pStmt->last != STMT_PREPARE && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_EXECUTE) {
tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error"));
}
}
pStmt->last = STMT_BIND;
- return insertStmtBindParamBatch(pStmt, bind, -1);
+ STMT_RET(insertStmtBindParamBatch(pStmt, bind, -1));
}
int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int colIdx) {
STscStmt* pStmt = (STscStmt*)stmt;
if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) {
- terrno = TSDB_CODE_TSC_DISCONNECTED;
- return TSDB_CODE_TSC_DISCONNECTED;
+ STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (bind == NULL || bind->num <= 0 || bind->num > INT16_MAX) {
tscError("0x%"PRIx64" invalid parameter", pStmt->pSql->self);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "invalid bind param"));
}
if (!pStmt->isInsert) {
tscError("0x%"PRIx64" not or invalid batch insert", pStmt->pSql->self);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "not or invalid batch insert"));
}
if (pStmt->multiTbInsert) {
if (pStmt->last != STMT_SETTBNAME && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_BIND_COL) {
tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error"));
}
} else {
if (pStmt->last != STMT_PREPARE && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_BIND_COL && pStmt->last != STMT_EXECUTE) {
tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error"));
}
}
pStmt->last = STMT_BIND_COL;
- return insertStmtBindParamBatch(pStmt, bind, colIdx);
+ STMT_RET(insertStmtBindParamBatch(pStmt, bind, colIdx));
}
@@ -1746,44 +1767,42 @@ int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, in
int taos_stmt_add_batch(TAOS_STMT* stmt) {
STscStmt* pStmt = (STscStmt*)stmt;
if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) {
- terrno = TSDB_CODE_TSC_DISCONNECTED;
- return TSDB_CODE_TSC_DISCONNECTED;
+ STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (pStmt->isInsert) {
if (pStmt->last != STMT_BIND && pStmt->last != STMT_BIND_COL) {
tscError("0x%"PRIx64" add batch status error, last:%d", pStmt->pSql->self, pStmt->last);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "add batch status error"));
}
pStmt->last = STMT_ADD_BATCH;
- return insertStmtAddBatch(pStmt);
+ STMT_RET(insertStmtAddBatch(pStmt));
}
- return TSDB_CODE_COM_OPS_NOT_SUPPORT;
+ STMT_RET(TSDB_CODE_COM_OPS_NOT_SUPPORT);
}
int taos_stmt_reset(TAOS_STMT* stmt) {
STscStmt* pStmt = (STscStmt*)stmt;
if (pStmt->isInsert) {
- return insertStmtReset(pStmt);
+ STMT_RET(insertStmtReset(pStmt));
}
- return TSDB_CODE_SUCCESS;
+ STMT_RET(TSDB_CODE_SUCCESS);
}
int taos_stmt_execute(TAOS_STMT* stmt) {
int ret = 0;
STscStmt* pStmt = (STscStmt*)stmt;
if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) {
- terrno = TSDB_CODE_TSC_DISCONNECTED;
- return TSDB_CODE_TSC_DISCONNECTED;
+ STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (pStmt->isInsert) {
if (pStmt->last != STMT_ADD_BATCH) {
tscError("0x%"PRIx64" exec status error, last:%d", pStmt->pSql->self, pStmt->last);
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "exec status error"));
}
pStmt->last = STMT_EXECUTE;
@@ -1809,7 +1828,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) {
}
}
- return ret;
+ STMT_RET(ret);
}
TAOS_RES *taos_stmt_use_result(TAOS_STMT* stmt) {
@@ -1833,32 +1852,30 @@ int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) {
STscStmt* pStmt = (STscStmt*)stmt;
if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) {
- terrno = TSDB_CODE_TSC_DISCONNECTED;
- return TSDB_CODE_TSC_DISCONNECTED;
+ STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (insert) *insert = pStmt->isInsert;
- return TSDB_CODE_SUCCESS;
+ STMT_RET(TSDB_CODE_SUCCESS);
}
int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) {
STscStmt* pStmt = (STscStmt*)stmt;
if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) {
- terrno = TSDB_CODE_TSC_DISCONNECTED;
- return TSDB_CODE_TSC_DISCONNECTED;
+ STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (pStmt->isInsert) {
SSqlObj* pSql = pStmt->pSql;
SSqlCmd *pCmd = &pSql->cmd;
*nums = pCmd->insertParam.numOfParams;
- return TSDB_CODE_SUCCESS;
+ STMT_RET(TSDB_CODE_SUCCESS);
} else {
SNormalStmt* normal = &pStmt->normal;
*nums = normal->numParams;
- return TSDB_CODE_SUCCESS;
+ STMT_RET(TSDB_CODE_SUCCESS);
}
}
@@ -1866,8 +1883,7 @@ int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) {
STscStmt* pStmt = (STscStmt*)stmt;
if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) {
- terrno = TSDB_CODE_TSC_DISCONNECTED;
- return TSDB_CODE_TSC_DISCONNECTED;
+ STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
}
if (pStmt->isInsert) {
@@ -1884,24 +1900,37 @@ int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) {
tscGetDataBlockFromList(pCmd->insertParam.pTableBlockHashList, pTableMeta->id.uid, TSDB_PAYLOAD_SIZE, sizeof(SSubmitBlk),
pTableMeta->tableInfo.rowSize, &pTableMetaInfo->name, pTableMeta, &pBlock, NULL);
if (ret != 0) {
- // todo handle error
+ STMT_RET(ret);
}
if (idx<0 || idx>=pBlock->numOfParams) {
tscError("0x%"PRIx64" param %d: out of range", pStmt->pSql->self, idx);
- abort();
+ STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "idx out of range"));
}
SParamInfo* param = &pBlock->params[idx];
if (type) *type = param->type;
if (bytes) *bytes = param->bytes;
- return TSDB_CODE_SUCCESS;
+ STMT_RET(TSDB_CODE_SUCCESS);
} else {
- return TSDB_CODE_TSC_APP_ERROR;
+ STMT_RET(TSDB_CODE_COM_OPS_NOT_SUPPORT);
+ }
+}
+
+
+char *taos_stmt_errstr(TAOS_STMT *stmt) {
+ STscStmt* pStmt = (STscStmt*)stmt;
+
+ if (stmt == NULL) {
+ return (char*) tstrerror(terrno);
}
+
+ return taos_errstr(pStmt->pSql);
}
+
+
const char *taos_data_type(int type) {
switch (type) {
case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL";
diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c
index 35c737d5e441e581beb602a028da2fcefa018471..17752e5e4d0b06528f61f7ac33bb068b64528c0b 100644
--- a/src/client/src/tscSQLParser.c
+++ b/src/client/src/tscSQLParser.c
@@ -63,6 +63,9 @@ static SExprInfo* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t colIndex, int3
static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo);
static char* getAccountId(SSqlObj* pSql);
+static bool serializeExprListToVariant(SArray* pList, tVariant **dest, int16_t colType);
+static int32_t validateParamOfRelationIn(tVariant *pVar, int32_t colType);
+
static bool has(SArray* pFieldList, int32_t startIdx, const char* name);
static char* cloneCurrentDBName(SSqlObj* pSql);
static int32_t getDelimiterIndex(SStrToken* pTableName);
@@ -119,7 +122,7 @@ static int32_t getColumnIndexByName(SSqlCmd* pCmd, const SStrToken* pToken, SQue
static int32_t getTableIndexByName(SStrToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex);
static int32_t getTableIndexImpl(SStrToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex);
-static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
+static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* msg);
static int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode);
static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate);
@@ -134,14 +137,97 @@ static bool validateDebugFlag(int32_t v);
static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
static int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo);
-static bool isTimeWindowQuery(SQueryInfo* pQueryInfo) {
+static bool isTimeWindowQuery(SQueryInfo* pQueryInfo) {
return pQueryInfo->interval.interval > 0 || pQueryInfo->sessionWindow.gap > 0;
}
+
int16_t getNewResColId(SSqlCmd* pCmd) {
return pCmd->resColumnId--;
}
+// serialize expr in exprlist to binary
+// formate "type | size | value"
+bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType) {
+ bool ret = false;
+ if (!pList || pList->size <= 0) {
+ return ret;
+ }
+ if (colType == TSDB_DATA_TYPE_DOUBLE || colType == TSDB_DATA_TYPE_FLOAT) {
+ return ret;
+ }
+
+ tSqlExprItem* item = (tSqlExprItem *)taosArrayGet(pList, 0);
+ int32_t firstTokenType = item->pNode->token.type;
+ int32_t type = firstTokenType;
+
+ //nchar to binary and
+ toTSDBType(type);
+ if (type != colType && (type != TSDB_DATA_TYPE_BINARY || colType != TSDB_DATA_TYPE_NCHAR)) {
+ return false;
+ }
+ type = colType;
+
+ SBufferWriter bw = tbufInitWriter( NULL, false );
+ tbufEnsureCapacity(&bw, 512);
+
+ int32_t size = (int32_t)(pList->size);
+ tbufWriteUint32(&bw, type);
+ tbufWriteInt32(&bw, size);
+
+ for (int32_t i = 0; i < size; i++) {
+ tSqlExpr* pSub = ((tSqlExprItem*)(taosArrayGet(pList, i)))->pNode;
+
+ // check all the token type in expr list same or not
+ if (firstTokenType != pSub->token.type) {
+ break;
+ }
+
+ toTSDBType(pSub->token.type);
+
+ tVariant var;
+ tVariantCreate(&var, &pSub->token);
+ if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT
+ || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) {
+ tbufWriteInt64(&bw, var.i64);
+ } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_FLOAT) {
+ tbufWriteDouble(&bw, var.dKey);
+ } else if (type == TSDB_DATA_TYPE_BINARY){
+ tbufWriteBinary(&bw, var.pz, var.nLen);
+ } else if (type == TSDB_DATA_TYPE_NCHAR) {
+ char *buf = (char *)calloc(1, (var.nLen + 1)*TSDB_NCHAR_SIZE);
+ if (tVariantDump(&var, buf, type, false) != TSDB_CODE_SUCCESS) {
+ free(buf);
+ tVariantDestroy(&var);
+ break;
+ }
+ tbufWriteBinary(&bw, buf, twcslen((wchar_t *)buf) * TSDB_NCHAR_SIZE);
+ free(buf);
+ }
+ tVariantDestroy(&var);
+
+ if (i == size - 1) { ret = true;}
+ }
+
+ if (ret == true) {
+ if ((*dst = calloc(1, sizeof(tVariant))) != NULL) {
+ tVariantCreateFromBinary(*dst, tbufGetData(&bw, false), tbufTell(&bw), TSDB_DATA_TYPE_BINARY);
+ } else {
+ ret = false;
+ }
+ }
+ tbufCloseWriter(&bw);
+ return ret;
+}
+
+static int32_t validateParamOfRelationIn(tVariant *pVar, int32_t colType) {
+ if (pVar->nType != TSDB_DATA_TYPE_BINARY) {
+ return -1;
+ }
+ SBufferReader br = tbufInitReader(pVar->pz, pVar->nLen, false);
+ return colType == TSDB_DATA_TYPE_NCHAR ? 0 : (tbufReadUint32(&br) == colType ? 0: -1);
+}
+
static uint8_t convertOptr(SStrToken *pToken) {
switch (pToken->type) {
case TK_LT:
@@ -162,6 +248,7 @@ static uint8_t convertOptr(SStrToken *pToken) {
return TSDB_RELATION_EQUAL;
case TK_PLUS:
return TSDB_BINARY_OP_ADD;
+
case TK_MINUS:
return TSDB_BINARY_OP_SUBTRACT;
case TK_STAR:
@@ -177,6 +264,8 @@ static uint8_t convertOptr(SStrToken *pToken) {
return TSDB_RELATION_ISNULL;
case TK_NOTNULL:
return TSDB_RELATION_NOTNULL;
+ case TK_IN:
+ return TSDB_RELATION_IN;
default: { return 0; }
}
}
@@ -2068,7 +2157,9 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const char* msg6 = "function applied to tags not allowed";
const char* msg7 = "normal table can not apply this function";
const char* msg8 = "multi-columns selection does not support alias column name";
- const char* msg9 = "diff can no be applied to unsigned numeric type";
+ const char* msg9 = "diff/derivative can no be applied to unsigned numeric type";
+ const char* msg10 = "derivative duration should be greater than 1 Second";
+ const char* msg11 = "third parameter in derivative should be 0 or 1";
switch (functionId) {
case TSDB_FUNC_COUNT: {
@@ -2157,11 +2248,14 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case TSDB_FUNC_MIN:
case TSDB_FUNC_MAX:
case TSDB_FUNC_DIFF:
+ case TSDB_FUNC_DERIVATIVE:
case TSDB_FUNC_STDDEV:
case TSDB_FUNC_LEASTSQR: {
// 1. valid the number of parameters
- if (pItem->pNode->pParam == NULL || (functionId != TSDB_FUNC_LEASTSQR && taosArrayGetSize(pItem->pNode->pParam) != 1) ||
- (functionId == TSDB_FUNC_LEASTSQR && taosArrayGetSize(pItem->pNode->pParam) != 3)) {
+ int32_t numOfParams = (pItem->pNode->pParam == NULL)? 0: (int32_t) taosArrayGetSize(pItem->pNode->pParam);
+ if (pItem->pNode->pParam == NULL ||
+ (functionId != TSDB_FUNC_LEASTSQR && functionId != TSDB_FUNC_DERIVATIVE && numOfParams != 1) ||
+ ((functionId == TSDB_FUNC_LEASTSQR || functionId == TSDB_FUNC_DERIVATIVE) && numOfParams != 3)) {
/* no parameters or more than one parameter for function */
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
@@ -2182,11 +2276,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
// 2. check if sql function can be applied on this column data type
pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
+ STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta);
+
SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex);
if (!IS_NUMERIC_TYPE(pSchema->type)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
- } else if (IS_UNSIGNED_NUMERIC_TYPE(pSchema->type) && functionId == TSDB_FUNC_DIFF) {
+ } else if (IS_UNSIGNED_NUMERIC_TYPE(pSchema->type) && (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg9);
}
@@ -2200,11 +2296,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
// set the first column ts for diff query
- if (functionId == TSDB_FUNC_DIFF) {
+ if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
colIndex += 1;
SColumnIndex indexTS = {.tableIndex = index.tableIndex, .columnIndex = 0};
- SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE,
- getNewResColId(pCmd), TSDB_KEYSIZE, false);
+ SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP,
+ TSDB_KEYSIZE, getNewResColId(pCmd), TSDB_KEYSIZE, false);
SColumnList ids = createColumnList(1, 0, 0);
insertResultField(pQueryInfo, 0, &ids, TSDB_KEYSIZE, TSDB_DATA_TYPE_TIMESTAMP, aAggs[TSDB_FUNC_TS_DUMMY].name, pExpr);
@@ -2215,7 +2311,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
}
- SExprInfo* pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), resultSize, false);
+ SExprInfo* pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), intermediateResSize, false);
if (functionId == TSDB_FUNC_LEASTSQR) { // set the leastsquares parameters
char val[8] = {0};
@@ -2230,12 +2326,39 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return TSDB_CODE_TSC_INVALID_OPERATION;
}
- tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double));
+ tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_DOUBLE, DOUBLE_BYTES);
} else if (functionId == TSDB_FUNC_IRATE) {
- STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta);
int64_t prec = info.precision;
-
tscExprAddParams(&pExpr->base, (char*)&prec, TSDB_DATA_TYPE_BIGINT, LONG_BYTES);
+ } else if (functionId == TSDB_FUNC_DERIVATIVE) {
+ char val[8] = {0};
+
+ int64_t tickPerSec = 0;
+ if (tVariantDump(&pParamElem[1].pNode->value, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, true) < 0) {
+ return TSDB_CODE_TSC_INVALID_OPERATION;
+ }
+
+ if (info.precision == TSDB_TIME_PRECISION_MILLI) {
+ tickPerSec /= 1000;
+ }
+
+ if (tickPerSec <= 0 || tickPerSec < TSDB_TICK_PER_SECOND(info.precision)) {
+ return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10);
+ }
+
+ tscExprAddParams(&pExpr->base, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, LONG_BYTES);
+ memset(val, 0, tListLen(val));
+
+ if (tVariantDump(&pParamElem[2].pNode->value, val, TSDB_DATA_TYPE_BIGINT, true) < 0) {
+ return TSDB_CODE_TSC_INVALID_OPERATION;
+ }
+
+ int64_t v = *(int64_t*) val;
+ if (v != 0 && v != 1) {
+ return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg11);
+ }
+
+ tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_BIGINT, LONG_BYTES);
}
SColumnList ids = createColumnList(1, index.tableIndex, index.columnIndex);
@@ -2935,8 +3058,8 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) {
}
bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
- const char* msg1 = "TWA not allowed to apply to super table directly";
- const char* msg2 = "TWA only support group by tbname for super table query";
+ const char* msg1 = "TWA/Diff not allowed to apply to super table directly";
+ const char* msg2 = "TWA/Diff only support group by tbname for super table query";
const char* msg3 = "function not support for super table query";
// filter sql function not supported by metric query yet.
@@ -2949,7 +3072,7 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo)
}
}
- if (tscIsTWAQuery(pQueryInfo)) {
+ if (tscIsTWAQuery(pQueryInfo) || tscIsDiffQuery(pQueryInfo)) {
if (pQueryInfo->groupbyExpr.numOfGroupCols == 0) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
return true;
@@ -3207,6 +3330,25 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
retVal = tVariantDump(&pRight->value, (char*)&pColumnFilter->upperBndd, colType, false);
// TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd
+ } else if (pExpr->tokenId == TK_IN) {
+ tVariant *pVal;
+ if (pRight->tokenId != TK_SET || !serializeExprListToVariant(pRight->pParam, &pVal, colType) || colType == TSDB_DATA_TYPE_TIMESTAMP) {
+ return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
+ }
+ if (validateParamOfRelationIn(pVal, colType) != TSDB_CODE_SUCCESS) {
+ tVariantDestroy(pVal);
+ free(pVal);
+ return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
+ }
+ pColumnFilter->pz = (int64_t)calloc(1, pVal->nLen + 1);
+ pColumnFilter->len = pVal->nLen;
+ pColumnFilter->filterstr = 1;
+ memcpy((char *)(pColumnFilter->pz), (char *)(pVal->pz), pVal->nLen);
+ //retVal = tVariantDump(pVal, (char *)(pColumnFilter->pz), TSDB_DATA_TYPE_BINARY, false);
+
+ tVariantDestroy(pVal);
+ free(pVal);
+
} else if (colType == TSDB_DATA_TYPE_BINARY) {
pColumnFilter->pz = (int64_t)calloc(1, bufLen * TSDB_NCHAR_SIZE);
pColumnFilter->len = pRight->value.nLen;
@@ -3255,6 +3397,9 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
case TK_NOTNULL:
pColumnFilter->lowerRelOptr = TSDB_RELATION_NOTNULL;
break;
+ case TK_IN:
+ pColumnFilter->lowerRelOptr = TSDB_RELATION_IN;
+ break;
default:
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
}
@@ -3370,7 +3515,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
&& pExpr->tokenId != TK_ISNULL
&& pExpr->tokenId != TK_NOTNULL
&& pExpr->tokenId != TK_LIKE
- ) {
+ && pExpr->tokenId != TK_IN) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
} else {
@@ -3380,7 +3525,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
if (pSchema->type == TSDB_DATA_TYPE_BOOL) {
int32_t t = pExpr->tokenId;
- if (t != TK_EQ && t != TK_NE && t != TK_NOTNULL && t != TK_ISNULL) {
+ if (t != TK_EQ && t != TK_NE && t != TK_NOTNULL && t != TK_ISNULL && t != TK_IN) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
}
@@ -4422,7 +4567,11 @@ static int32_t validateTagCondExpr(SSqlCmd* pCmd, tExprNode *p) {
free(tmp);
} else {
double tmp;
- retVal = tVariantDump(vVariant, (char*)&tmp, schemaType, false);
+ if (p->_node.optr == TSDB_RELATION_IN) {
+ retVal = validateParamOfRelationIn(vVariant, schemaType);
+ } else {
+ retVal = tVariantDump(vVariant, (char*)&tmp, schemaType, false);
+ }
}
if (retVal != TSDB_CODE_SUCCESS) {
@@ -5508,7 +5657,7 @@ int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
bool isProjectionFunction = false;
- const char* msg1 = "column projection is not compatible with interval";
+ const char* msg1 = "functions not compatible with interval";
// multi-output set/ todo refactor
size_t size = taosArrayGetSize(pQueryInfo->exprList);
@@ -5532,8 +5681,8 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu
}
}
- if ((pExpr->base.functionId == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) || pExpr->base.functionId == TSDB_FUNC_DIFF ||
- pExpr->base.functionId == TSDB_FUNC_ARITHM) {
+ int32_t f = pExpr->base.functionId;
+ if ((f == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) || f == TSDB_FUNC_DIFF || f == TSDB_FUNC_ARITHM || f == TSDB_FUNC_DERIVATIVE) {
isProjectionFunction = true;
}
}
@@ -6121,7 +6270,7 @@ static void updateTagPrjFunction(SQueryInfo* pQueryInfo) {
* 2. if selectivity function and tagprj function both exist, there should be only
* one selectivity function exists.
*/
-static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) {
+static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) {
const char* msg1 = "only one selectivity function allowed in presence of tags function";
const char* msg3 = "aggregation function should not be mixed up with projection";
@@ -6148,6 +6297,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
continue;
}
+
if ((aAggs[functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0) {
numOfSelectivity++;
} else {
@@ -6159,7 +6309,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
// When the tag projection function on tag column that is not in the group by clause, aggregation function and
// selectivity function exist in select clause is not allowed.
if (numOfAggregation > 0) {
- return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
+ return invalidOperationMsg(msg, msg1);
}
/*
@@ -6188,7 +6338,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
(functionId == TSDB_FUNC_LAST_DST && (pExpr->base.colInfo.flag & TSDB_COL_NULL) != 0)) {
// do nothing
} else {
- return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
+ return invalidOperationMsg(msg, msg1);
}
}
@@ -6201,7 +6351,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
} else {
if ((pQueryInfo->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0) {
if (numOfAggregation > 0 && pQueryInfo->groupbyExpr.numOfGroupCols == 0) {
- return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
+ return invalidOperationMsg(msg, msg3);
}
if (numOfAggregation > 0 || numOfSelectivity > 0) {
@@ -6311,7 +6461,7 @@ static int32_t doTagFunctionCheck(SQueryInfo* pQueryInfo) {
return (tableCounting && tagProjection)? -1:0;
}
-int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
+int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* msg) {
const char* msg1 = "functions/columns not allowed in group by query";
const char* msg2 = "projection query on columns not allowed";
const char* msg3 = "group by/session/state_window not allowed on projection query";
@@ -6321,17 +6471,17 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
// only retrieve tags, group by is not supportted
if (tscQueryTags(pQueryInfo)) {
if (doTagFunctionCheck(pQueryInfo) != TSDB_CODE_SUCCESS) {
- return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5);
+ return invalidOperationMsg(msg, msg5);
}
if (pQueryInfo->groupbyExpr.numOfGroupCols > 0 || isTimeWindowQuery(pQueryInfo)) {
- return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
+ return invalidOperationMsg(msg, msg4);
} else {
return TSDB_CODE_SUCCESS;
}
}
if (tscIsProjectionQuery(pQueryInfo) && tscIsSessionWindowQuery(pQueryInfo)) {
- return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
+ return invalidOperationMsg(msg, msg3);
}
if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) {
@@ -6339,6 +6489,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
if (onlyTagPrjFunction(pQueryInfo) && allTagPrjInGroupby(pQueryInfo)) {
// It is a groupby aggregate query, the tag project function is not suitable for this case.
updateTagPrjFunction(pQueryInfo);
+
return doAddGroupbyColumnsOnDemand(pCmd, pQueryInfo);
}
@@ -6363,21 +6514,21 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
}
if (!qualified) {
- return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
+ return invalidOperationMsg(msg, msg2);
}
}
if (IS_MULTIOUTPUT(aAggs[functId].status) && functId != TSDB_FUNC_TOP && functId != TSDB_FUNC_BOTTOM &&
- functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_PRJ) {
- return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
+ functId != TSDB_FUNC_DIFF && functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_PRJ) {
+ return invalidOperationMsg(msg, msg1);
}
if (functId == TSDB_FUNC_COUNT && pExpr->base.colInfo.colIndex == TSDB_TBNAME_COLUMN_INDEX) {
- return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
+ return invalidOperationMsg(msg, msg1);
}
}
- if (checkUpdateTagPrjFunctions(pQueryInfo, pCmd) != TSDB_CODE_SUCCESS) {
+ if (checkUpdateTagPrjFunctions(pQueryInfo, msg) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
@@ -6387,12 +6538,12 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
// projection query on super table does not compatible with "group by" syntax
if (tscIsProjectionQuery(pQueryInfo)) {
- return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
+ return invalidOperationMsg(msg, msg3);
}
return TSDB_CODE_SUCCESS;
} else {
- return checkUpdateTagPrjFunctions(pQueryInfo, pCmd);
+ return checkUpdateTagPrjFunctions(pQueryInfo, msg);
}
}
int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode) {
@@ -6478,6 +6629,13 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
}
+ int32_t blocks = ntohl(pCreate->totalBlocks);
+ if (blocks != -1 && (blocks < TSDB_MIN_TOTAL_BLOCKS || blocks > TSDB_MAX_TOTAL_BLOCKS)) {
+ snprintf(msg, tListLen(msg), "invalid db option totalBlocks: %d valid range: [%d, %d]", blocks,
+ TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS);
+ return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
+ }
+
if (pCreate->quorum != -1 &&
(pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) {
snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum,
@@ -6850,7 +7008,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
const char* msg6 = "from missing in subclause";
const char* msg7 = "time interval is required";
const char* msg8 = "the first column should be primary timestamp column";
-
+
SSqlCmd* pCmd = &pSql->cmd;
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd);
assert(pQueryInfo->numOfTables == 1);
@@ -7644,7 +7802,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
if (validateIntervalNode(pSql, pQueryInfo, pSqlNode) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
} else {
- if (isTimeWindowQuery(pQueryInfo)) {
+ if (isTimeWindowQuery(pQueryInfo) || pQueryInfo->sessionWindow.gap > 0) {
// check if the first column of the nest query result is timestamp column
SColumn* pCol = taosArrayGetP(pQueryInfo->colList, 0);
if (pCol->info.type != TSDB_DATA_TYPE_TIMESTAMP) {
@@ -7659,10 +7817,13 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
// set order by info
STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta;
- if (validateOrderbyNode(pCmd, pQueryInfo, pSqlNode, tscGetTableSchema(pTableMeta)) !=
- TSDB_CODE_SUCCESS) {
+ if (validateOrderbyNode(pCmd, pQueryInfo, pSqlNode, tscGetTableSchema(pTableMeta)) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
+
+ if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo, tscGetErrorMsgPayload(pCmd))) != TSDB_CODE_SUCCESS) {
+ return code;
+ }
} else {
pQueryInfo->command = TSDB_SQL_SELECT;
@@ -7727,11 +7888,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
// set interval value
if (validateIntervalNode(pSql, pQueryInfo, pSqlNode) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
- } else {
- if (isTimeWindowQuery(pQueryInfo) &&
- (validateFunctionsInIntervalOrGroupbyQuery(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS)) {
- return TSDB_CODE_TSC_INVALID_OPERATION;
- }
}
if (tscQueryTags(pQueryInfo)) {
@@ -7762,6 +7918,11 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return TSDB_CODE_TSC_INVALID_OPERATION;
}
+ if ((isTimeWindowQuery(pQueryInfo) || pQueryInfo->sessionWindow.gap > 0) &&
+ (validateFunctionsInIntervalOrGroupbyQuery(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS)) {
+ return TSDB_CODE_TSC_INVALID_OPERATION;
+ }
+
if (isSTable) {
tscTansformFuncForSTableQuery(pQueryInfo);
if (hasUnsupportFunctionsForSTableQuery(pCmd, pQueryInfo)) {
@@ -7791,7 +7952,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return code;
}
- if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo)) != TSDB_CODE_SUCCESS) {
+ if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo,tscGetErrorMsgPayload(pCmd))) != TSDB_CODE_SUCCESS) {
return code;
}
@@ -7804,14 +7965,15 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
}
{ // set the query info
- pQueryInfo->projectionQuery = tscIsProjectionQuery(pQueryInfo);
- pQueryInfo->hasFilter = tscHasColumnFilter(pQueryInfo);
- pQueryInfo->simpleAgg = isSimpleAggregateRv(pQueryInfo);
- pQueryInfo->onlyTagQuery = onlyTagPrjFunction(pQueryInfo);
- pQueryInfo->groupbyColumn = tscGroupbyColumn(pQueryInfo);
+ pQueryInfo->projectionQuery = tscIsProjectionQuery(pQueryInfo);
+ pQueryInfo->hasFilter = tscHasColumnFilter(pQueryInfo);
+ pQueryInfo->simpleAgg = isSimpleAggregateRv(pQueryInfo);
+ pQueryInfo->onlyTagQuery = onlyTagPrjFunction(pQueryInfo);
+ pQueryInfo->groupbyColumn = tscGroupbyColumn(pQueryInfo);
- pQueryInfo->arithmeticOnAgg = tsIsArithmeticQueryOnAggResult(pQueryInfo);
+ pQueryInfo->arithmeticOnAgg = tsIsArithmeticQueryOnAggResult(pQueryInfo);
pQueryInfo->orderProjectQuery = tscOrderedProjectionQueryOnSTable(pQueryInfo, 0);
+ pQueryInfo->diffQuery = tscIsDiffQuery(pQueryInfo);
SExprInfo** p = NULL;
int32_t numOfExpr = 0;
@@ -7922,6 +8084,24 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
}
return TSDB_CODE_SUCCESS;
+ } else if (pSqlExpr->tokenId == TK_SET) {
+ int32_t type = -1;
+ STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta;
+ if (pCols != NULL) {
+ SColIndex* idx = taosArrayGet(pCols, 0);
+ SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex);
+ if (pSchema != NULL) {
+ type = pSchema->type;
+ }
+ }
+
+ tVariant *pVal;
+ if (serializeExprListToVariant(pSqlExpr->pParam, &pVal, type) == false) {
+ return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "not support filter expression");
+ }
+ *pExpr = calloc(1, sizeof(tExprNode));
+ (*pExpr)->nodeType = TSQL_NODE_VALUE;
+ (*pExpr)->pVal = pVal;
} else {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "not support filter expression");
}
diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c
index f997d487d1687ec41385651160bc7146019724ec..b4c7a64fd0e566bd323d9c5f44507f849900b9c7 100644
--- a/src/client/src/tscServer.c
+++ b/src/client/src/tscServer.c
@@ -912,7 +912,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
SGroupbyExpr *pGroupbyExpr = query.pGroupbyExpr;
- if (pGroupbyExpr->numOfGroupCols > 0) {
+ if (pGroupbyExpr != NULL && pGroupbyExpr->numOfGroupCols > 0) {
pQueryMsg->orderByIdx = htons(pGroupbyExpr->orderIndex);
pQueryMsg->orderType = htons(pGroupbyExpr->orderType);
@@ -1588,7 +1588,7 @@ int tscProcessLocalRetrieveRsp(SSqlObj *pSql) {
return tscLocalResultCommonBuilder(pSql, numOfRes);
}
-int tscProcessRetrieveLocalMergeRsp(SSqlObj *pSql) {
+int tscProcessRetrieveGlobalMergeRsp(SSqlObj *pSql) {
SSqlRes *pRes = &pSql->res;
SSqlCmd* pCmd = &pSql->cmd;
@@ -1615,12 +1615,13 @@ int tscProcessRetrieveLocalMergeRsp(SSqlObj *pSql) {
taosArrayPush(group, &tableKeyInfo);
taosArrayPush(tableGroupInfo.pGroupList, &group);
- pQueryInfo->pQInfo = createQInfoFromQueryNode(pQueryInfo, &tableGroupInfo, NULL, NULL, pRes->pMerger, MERGE_STAGE);
+ tscDebug("0x%"PRIx64" create QInfo 0x%"PRIx64" to execute query processing", pSql->self, pSql->self);
+ pQueryInfo->pQInfo = createQInfoFromQueryNode(pQueryInfo, &tableGroupInfo, NULL, NULL, pRes->pMerger, MERGE_STAGE, pSql->self);
}
- uint64_t localQueryId = 0;
+ uint64_t localQueryId = pSql->self;
qTableQuery(pQueryInfo->pQInfo, &localQueryId);
- convertQueryResult(pRes, pQueryInfo);
+ convertQueryResult(pRes, pQueryInfo, pSql->self);
code = pRes->code;
if (pRes->code == TSDB_CODE_SUCCESS) {
@@ -2689,7 +2690,7 @@ void tscInitMsgsFp() {
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp;
- tscProcessMsgRsp[TSDB_SQL_RETRIEVE_LOCALMERGE] = tscProcessRetrieveLocalMergeRsp;
+ tscProcessMsgRsp[TSDB_SQL_RETRIEVE_GLOBALMERGE] = tscProcessRetrieveGlobalMergeRsp;
tscProcessMsgRsp[TSDB_SQL_ALTER_TABLE] = tscProcessAlterTableMsgRsp;
tscProcessMsgRsp[TSDB_SQL_ALTER_DB] = tscProcessAlterDbMsgRsp;
diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c
index 554ce351eb05a3196a08a79c3b3067df6de6aab8..1e9389287674996b63ff3a7cc2d8ece81d4bc130 100644
--- a/src/client/src/tscSql.c
+++ b/src/client/src/tscSql.c
@@ -456,7 +456,7 @@ static bool needToFetchNewBlock(SSqlObj* pSql) {
return (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) &&
(pCmd->command == TSDB_SQL_RETRIEVE ||
- pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE ||
+ pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE ||
pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE ||
pCmd->command == TSDB_SQL_FETCH ||
pCmd->command == TSDB_SQL_SHOW ||
diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c
index 2f32e775d66e3c3e1cf45b1437f3fa82278346a6..49ce73854520aa95249d9f42590acd36d83bb523 100644
--- a/src/client/src/tscSubquery.c
+++ b/src/client/src/tscSubquery.c
@@ -1977,9 +1977,8 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) {
}
memset(pSql->subState.states, 0, sizeof(*pSql->subState.states) * pSql->subState.numOfSub);
- tscDebug("0x%"PRIx64" reset all sub states to 0", pSql->self);
+ tscDebug("0x%"PRIx64" reset all sub states to 0, start subquery, total:%d", pSql->self, pQueryInfo->numOfTables);
- tscDebug("0x%"PRIx64" start subquery, total:%d", pSql->self, pQueryInfo->numOfTables);
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
SJoinSupporter *pSupporter = tscCreateJoinSupporter(pSql, i);
if (pSupporter == NULL) { // failed to create support struct, abort current query
@@ -2424,7 +2423,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
// pRes->code check only serves in launching metric sub-queries
if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) {
- pCmd->command = TSDB_SQL_RETRIEVE_LOCALMERGE; // enable the abort of kill super table function.
+ pCmd->command = TSDB_SQL_RETRIEVE_GLOBALMERGE; // enable the abort of kill super table function.
return pRes->code;
}
@@ -2780,7 +2779,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
if (code == TSDB_CODE_SUCCESS && trsupport->pExtMemBuffer == NULL) {
pParentSql->cmd.command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; // no result, set the result empty
} else {
- pParentSql->cmd.command = TSDB_SQL_RETRIEVE_LOCALMERGE;
+ pParentSql->cmd.command = TSDB_SQL_RETRIEVE_GLOBALMERGE;
}
tscCreateResPointerInfo(&pParentSql->res, pPQueryInfo);
@@ -3502,7 +3501,7 @@ static UNUSED_FUNC bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) {
}
void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pSourceOperator,
- char* sql, void* merger, int32_t stage) {
+ char* sql, void* merger, int32_t stage, uint64_t qId) {
assert(pQueryInfo != NULL);
SQInfo *pQInfo = (SQInfo *)calloc(1, sizeof(SQInfo));
if (pQInfo == NULL) {
@@ -3511,7 +3510,7 @@ void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGr
// to make sure third party won't overwrite this structure
pQInfo->signature = pQInfo;
-
+ pQInfo->qId = qId;
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
SQueryAttr *pQueryAttr = &pQInfo->query;
diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c
index b5dfc956ddd31a141c009bbf8200299cd82c607f..60919c98b5ae1d1ebc4d229b2023d679c87c1118 100644
--- a/src/client/src/tscUtil.c
+++ b/src/client/src/tscUtil.c
@@ -222,6 +222,8 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
functionId != TSDB_FUNC_TS &&
functionId != TSDB_FUNC_ARITHM &&
functionId != TSDB_FUNC_TS_COMP &&
+ functionId != TSDB_FUNC_DIFF &&
+ functionId != TSDB_FUNC_TS_DUMMY &&
functionId != TSDB_FUNC_TID_TAG) {
return false;
}
@@ -434,6 +436,23 @@ bool tscIsTWAQuery(SQueryInfo* pQueryInfo) {
return false;
}
+
+bool tscIsDiffQuery(SQueryInfo* pQueryInfo) {
+ size_t num = tscNumOfExprs(pQueryInfo);
+ for(int32_t i = 0; i < num; ++i) {
+ SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
+ if (pExpr == NULL || pExpr->base.functionId == TSDB_FUNC_TS_DUMMY) {
+ continue;
+ }
+
+ if (pExpr->base.functionId == TSDB_FUNC_DIFF) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo) {
return pQueryInfo->sessionWindow.gap > 0;
}
@@ -467,42 +486,12 @@ bool tscNeedReverseScan(SQueryInfo* pQueryInfo) {
return false;
}
-bool isSimpleAggregate(SQueryInfo* pQueryInfo) {
- if (pQueryInfo->interval.interval > 0) {
- return false;
- }
-
- // Note:top/bottom query is fixed output query
- if (tscIsTopBotQuery(pQueryInfo) || tscGroupbyColumn(pQueryInfo) || isTsCompQuery(pQueryInfo)) {
- return true;
- }
-
- size_t numOfExprs = tscNumOfExprs(pQueryInfo);
- for (int32_t i = 0; i < numOfExprs; ++i) {
- SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
- if (pExpr == NULL) {
- continue;
- }
-
- int32_t functionId = pExpr->base.functionId;
- if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY) {
- continue;
- }
-
- if (!IS_MULTIOUTPUT(aAggs[functionId].status)) {
- return true;
- }
- }
-
- return false;
-}
-
bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) {
if (pQueryInfo->interval.interval > 0 || pQueryInfo->sessionWindow.gap > 0) {
return false;
}
- if (tscGroupbyColumn(pQueryInfo) || isTsCompQuery(pQueryInfo)) {
+ if (tscIsDiffQuery(pQueryInfo)) {
return false;
}
@@ -518,13 +507,13 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) {
continue;
}
- if (!IS_MULTIOUTPUT(aAggs[functionId].status)) {
+ if ((!IS_MULTIOUTPUT(aAggs[functionId].status)) ||
+ (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_TS_COMP)) {
return true;
}
}
return false;
-
}
bool isBlockDistQuery(SQueryInfo* pQueryInfo) {
@@ -812,6 +801,7 @@ static void fetchNextBlockIfCompleted(SOperatorInfo* pOperator, bool* newgroup)
for (int32_t i = 0; i < pOperator->numOfUpstream; ++i) {
SJoinStatus* pStatus = &pJoinInfo->status[i];
if (pStatus->pBlock == NULL || pStatus->index >= pStatus->pBlock->info.rows) {
+ tscDebug("Retrieve nest query result, index:%d, total:%d", i, pOperator->numOfUpstream);
pStatus->pBlock = pOperator->upstream[i]->exec(pOperator->upstream[i], newgroup);
pStatus->index = 0;
@@ -972,6 +962,9 @@ static void destroyDummyInputOperator(void* param, int32_t numOfOutput) {
pInfo->block = destroyOutputBuf(pInfo->block);
pInfo->pSql = NULL;
+
+ cleanupResultRowInfo(&pInfo->pTableQueryInfo->resInfo);
+ tfree(pInfo->pTableQueryInfo);
}
// todo this operator servers as the adapter for Operator tree and SqlRes result, remove it later
@@ -1056,7 +1049,7 @@ SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pUpstream, int32_t numOfUp
return pOperator;
}
-void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
+void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo, uint64_t objId) {
// set the correct result
SSDataBlock* p = pQueryInfo->pQInfo->runtimeEnv.outputBuf;
pRes->numOfRows = (p != NULL)? p->info.rows: 0;
@@ -1066,6 +1059,7 @@ void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
tscSetResRawPtrRv(pRes, pQueryInfo, p);
}
+ tscDebug("0x%"PRIx64" retrieve result in pRes, numOfRows:%d", objId, pRes->numOfRows);
pRes->row = 0;
pRes->completed = (pRes->numOfRows == 0);
}
@@ -1088,7 +1082,9 @@ static void createInputDataFilterInfo(SQueryInfo* px, int32_t numOfCol1, int32_t
tfree(tableCols);
}
-void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQueryInfo* px, SSqlRes* pOutput) {
+void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQueryInfo* px, SSqlObj* pSql) {
+ SSqlRes* pOutput = &pSql->res;
+
// handle the following query process
if (px->pQInfo == NULL) {
SColumnInfo* pColumnInfo = extractColumnInfoFromResult(px->colList);
@@ -1168,7 +1164,9 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue
}
}
- px->pQInfo = createQInfoFromQueryNode(px, &tableGroupInfo, pSourceOperator, NULL, NULL, MASTER_SCAN);
+ tscDebug("0x%"PRIx64" create QInfo 0x%"PRIx64" to execute the main query while all nest queries are ready", pSql->self, pSql->self);
+ px->pQInfo = createQInfoFromQueryNode(px, &tableGroupInfo, pSourceOperator, NULL, NULL, MASTER_SCAN, pSql->self);
+
tfree(pColumnInfo);
tfree(schema);
@@ -1176,9 +1174,9 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue
pSourceOperator->pRuntimeEnv = &px->pQInfo->runtimeEnv;
}
- uint64_t qId = 0;
+ uint64_t qId = pSql->self;
qTableQuery(px->pQInfo, &qId);
- convertQueryResult(pOutput, px);
+ convertQueryResult(pOutput, px, pSql->self);
}
static void tscDestroyResPointerInfo(SSqlRes* pRes) {
@@ -1374,7 +1372,7 @@ void tscFreeSqlObj(SSqlObj* pSql) {
SSqlCmd* pCmd = &pSql->cmd;
int32_t cmd = pCmd->command;
- if (cmd < TSDB_SQL_INSERT || cmd == TSDB_SQL_RETRIEVE_LOCALMERGE || cmd == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
+ if (cmd < TSDB_SQL_INSERT || cmd == TSDB_SQL_RETRIEVE_GLOBALMERGE || cmd == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
cmd == TSDB_SQL_TABLE_JOIN_RETRIEVE) {
tscRemoveFromSqlList(pSql);
}
@@ -2177,6 +2175,7 @@ size_t tscNumOfExprs(SQueryInfo* pQueryInfo) {
return taosArrayGetSize(pQueryInfo->exprList);
}
+// todo REFACTOR
void tscExprAddParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes) {
assert (pExpr != NULL || argument != NULL || bytes != 0);
@@ -3278,7 +3277,6 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
pNewQueryInfo->numOfTables = 0;
pNewQueryInfo->pTableMetaInfo = NULL;
pNewQueryInfo->bufLen = pQueryInfo->bufLen;
-
pNewQueryInfo->buf = malloc(pQueryInfo->bufLen);
if (pNewQueryInfo->buf == NULL) {
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
@@ -3438,7 +3436,7 @@ void doRetrieveSubqueryData(SSchedMsg *pMsg) {
}
SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd);
- handleDownstreamOperator(pSql->pSubs, pSql->subState.numOfSub, pQueryInfo, &pSql->res);
+ handleDownstreamOperator(pSql->pSubs, pSql->subState.numOfSub, pQueryInfo, pSql);
pSql->res.qId = -1;
if (pSql->res.code == TSDB_CODE_SUCCESS) {
@@ -3468,13 +3466,12 @@ static void tscSubqueryRetrieveCallback(void* param, TAOS_RES* tres, int code) {
}
pParentSql->cmd.active = pParentSql->cmd.pQueryInfo;
-
- SSchedMsg schedMsg = {0};
- schedMsg.fp = doRetrieveSubqueryData;
- schedMsg.ahandle = (void *)pParentSql;
- schedMsg.thandle = (void *)1;
- schedMsg.msg = 0;
- taosScheduleTask(tscQhandle, &schedMsg);
+ pParentSql->res.qId = -1;
+ if (pSql->res.code == TSDB_CODE_SUCCESS) {
+ (*pSql->fp)(pParentSql->param, pParentSql, pParentSql->res.numOfRows);
+ } else {
+ tscAsyncResultOnError(pParentSql);
+ }
}
// todo handle the failure
@@ -4238,7 +4235,8 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
pQueryAttr->hasTagResults = hasTagValOutput(pQueryInfo);
pQueryAttr->stabledev = isStabledev(pQueryInfo);
pQueryAttr->tsCompQuery = isTsCompQuery(pQueryInfo);
- pQueryAttr->simpleAgg = isSimpleAggregate(pQueryInfo);
+ pQueryAttr->diffQuery = tscIsDiffQuery(pQueryInfo);
+ pQueryAttr->simpleAgg = isSimpleAggregateRv(pQueryInfo);
pQueryAttr->needReverseScan = tscNeedReverseScan(pQueryInfo);
pQueryAttr->stableQuery = QUERY_IS_STABLE_QUERY(pQueryInfo->type);
pQueryAttr->groupbyColumn = (!pQueryInfo->stateWindow) && tscGroupbyColumn(pQueryInfo);
@@ -4257,7 +4255,6 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
pQueryAttr->fillType = pQueryInfo->fillType;
pQueryAttr->havingNum = pQueryInfo->havingFieldNum;
-
if (pQueryInfo->order.order == TSDB_ORDER_ASC) { // TODO refactor
pQueryAttr->window = pQueryInfo->window;
} else {
@@ -4269,10 +4266,9 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
STableMetaInfo* pTableMetaInfo = pQueryInfo->pTableMetaInfo[0];
- pQueryAttr->pGroupbyExpr = calloc(1, sizeof(SGroupbyExpr));
- *(pQueryAttr->pGroupbyExpr) = pQueryInfo->groupbyExpr;
-
if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) {
+ pQueryAttr->pGroupbyExpr = calloc(1, sizeof(SGroupbyExpr));
+ *(pQueryAttr->pGroupbyExpr) = pQueryInfo->groupbyExpr;
pQueryAttr->pGroupbyExpr->columnInfo = taosArrayDup(pQueryInfo->groupbyExpr.columnInfo);
} else {
assert(pQueryInfo->groupbyExpr.columnInfo == NULL);
@@ -4351,7 +4347,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
return TSDB_CODE_TSC_INVALID_OPERATION;
}
- if (pQueryAttr->pGroupbyExpr->numOfGroupCols < 0) {
+ if (pQueryAttr->pGroupbyExpr != NULL && pQueryAttr->pGroupbyExpr->numOfGroupCols < 0) {
tscError("%p illegal value of numOfGroupCols in query msg: %d", addr, pQueryInfo->groupbyExpr.numOfGroupCols);
return TSDB_CODE_TSC_INVALID_OPERATION;
}
diff --git a/src/common/inc/tcmdtype.h b/src/common/inc/tcmdtype.h
index adf210cfebb15ddc0adcfce2aa85e606f79c44a5..90426519e66682ab9d5fab16a3a38e827a7d97df 100644
--- a/src/common/inc/tcmdtype.h
+++ b/src/common/inc/tcmdtype.h
@@ -76,7 +76,7 @@ enum {
// SQL below for client local
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_LOCAL, "local" )
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DESCRIBE_TABLE, "describe-table" )
- TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_LOCALMERGE, "retrieve-localmerge" )
+ TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_GLOBALMERGE, "retrieve-globalmerge" )
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_TABLE_JOIN_RETRIEVE, "join-retrieve" )
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW_CREATE_TABLE, "show-create-table")
diff --git a/src/common/inc/texpr.h b/src/common/inc/texpr.h
index 275dd12fd7ca9f9771592039d846593fa958f240..2e49a69366c2277c98ec32a1d8419c141ddecc0f 100644
--- a/src/common/inc/texpr.h
+++ b/src/common/inc/texpr.h
@@ -94,6 +94,8 @@ bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp
void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
char *(*cb)(void *, const char*, int32_t));
+void buildFilterSetFromBinary(void **q, const char *buf, int32_t len);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c
index f2dd3890a163ec1e1e25d2ac8b55f23aa9d5a79d..6fa4d68734df6fde94725026bd65b219cc6564ab 100644
--- a/src/common/src/texpr.c
+++ b/src/common/src/texpr.c
@@ -466,6 +466,32 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
return expr;
}
+void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) {
+ SBufferReader br = tbufInitReader(buf, len, false);
+ uint32_t type = tbufReadUint32(&br);
+ SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(type), true, false);
+ int dummy = -1;
+ int32_t sz = tbufReadInt32(&br);
+ for (int32_t i = 0; i < sz; i++) {
+ if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) {
+ int64_t val = tbufReadInt64(&br);
+ taosHashPut(pObj, (char *)&val, sizeof(val), &dummy, sizeof(dummy));
+ } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_FLOAT) {
+ double val = tbufReadDouble(&br);
+ taosHashPut(pObj, (char *)&val, sizeof(val), &dummy, sizeof(dummy));
+ } else if (type == TSDB_DATA_TYPE_BINARY) {
+ size_t t = 0;
+ const char *val = tbufReadBinary(&br, &t);
+ taosHashPut(pObj, (char *)val, t, &dummy, sizeof(dummy));
+ } else if (type == TSDB_DATA_TYPE_NCHAR) {
+ size_t t = 0;
+ const char *val = tbufReadBinary(&br, &t);
+ taosHashPut(pObj, (char *)val, t, &dummy, sizeof(dummy));
+ }
+ }
+ *q = (void *)pObj;
+}
+
tExprNode* exprdup(tExprNode* pNode) {
if (pNode == NULL) {
return NULL;
diff --git a/src/connector/jdbc/CMakeLists.txt b/src/connector/jdbc/CMakeLists.txt
index 61e976cb184d3240bdc8917a5b2e5f3182d55fcc..a04902a422deadf590fa9f6172b1a58c739be19a 100644
--- a/src/connector/jdbc/CMakeLists.txt
+++ b/src/connector/jdbc/CMakeLists.txt
@@ -8,10 +8,9 @@ IF (TD_MVN_INSTALLED)
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
POST_BUILD
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.29.jar ${LIBRARY_OUTPUT_PATH}
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.30.jar ${LIBRARY_OUTPUT_PATH}
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
COMMENT "build jdbc driver")
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
ENDIF ()
-
diff --git a/src/connector/jdbc/deploy-pom.xml b/src/connector/jdbc/deploy-pom.xml
index 968a9bf470ddde1996467467fa24cfd2fbf355e0..657645d46c00d6b7554c931a6dacca4695e34383 100755
--- a/src/connector/jdbc/deploy-pom.xml
+++ b/src/connector/jdbc/deploy-pom.xml
@@ -5,7 +5,7 @@
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.29
+ 2.0.30
jar
JDBCDriver
diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml
index e350e9738e9a15be58a3d288ddc2af564fbf3fbe..96e17bcd9b0eedc2116c2a8358e46d7b6e696b4e 100644
--- a/src/connector/jdbc/pom.xml
+++ b/src/connector/jdbc/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.29
+ 2.0.30
jar
JDBCDriver
https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
index 5dcaa77ebd4a15087785a6a9b642b85f160f5287..48811d30a6903c077a9c0fb55176b0bc2ca9ba75 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
@@ -12,6 +12,9 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
private final static int DRIVER_MAJAR_VERSION = 2;
private final static int DRIVER_MINOR_VERSION = 0;
+ private String precision = "ms";
+ private String database;
+
public boolean allProceduresAreCallable() throws SQLException {
return false;
}
@@ -493,102 +496,105 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
public abstract ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException;
- protected ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types, Connection connection) throws SQLException {
- try (Statement stmt = connection.createStatement()) {
- if (catalog == null || catalog.isEmpty())
- return null;
-
- ResultSet databases = stmt.executeQuery("show databases");
- String dbname = null;
- while (databases.next()) {
- dbname = databases.getString("name");
- if (dbname.equalsIgnoreCase(catalog))
- break;
- }
- databases.close();
- if (dbname == null)
- return null;
+ private List buildGetTablesColumnMetaDataList() {
+ List columnMetaDataList = new ArrayList<>();
+ columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT
+ columnMetaDataList.add(buildTableSchemaMeta(2)); // 2. TABLE_SCHEM
+ columnMetaDataList.add(buildTableNameMeta(3)); // 3. TABLE_NAME
+ columnMetaDataList.add(buildTableTypeMeta(4)); // 4. TABLE_TYPE
+ columnMetaDataList.add(buildRemarksMeta(5)); // 5. remarks
+ columnMetaDataList.add(buildTypeCatMeta(6)); // 6. TYPE_CAT
+ columnMetaDataList.add(buildTypeSchemaMeta(7)); // 7. TYPE_SCHEM
+ columnMetaDataList.add(buildTypeNameMeta(8)); // 8. TYPE_NAME
+ columnMetaDataList.add(buildSelfReferencingColName(9)); // 9. SELF_REFERENCING_COL_NAME
+ columnMetaDataList.add(buildRefGenerationMeta(10)); // 10. REF_GENERATION
+ return columnMetaDataList;
+ }
+
+ private ColumnMetaData buildTypeCatMeta(int colIndex) {
+ ColumnMetaData col6 = new ColumnMetaData();
+ col6.setColIndex(colIndex);
+ col6.setColName("TYPE_CAT");
+ col6.setColType(Types.NCHAR);
+ return col6;
+ }
+
+ private ColumnMetaData buildTypeSchemaMeta(int colIndex) {
+ ColumnMetaData col7 = new ColumnMetaData();
+ col7.setColIndex(colIndex);
+ col7.setColName("TYPE_SCHEM");
+ col7.setColType(Types.NCHAR);
+ return col7;
+ }
+
+ private ColumnMetaData buildTypeNameMeta(int colIndex) {
+ ColumnMetaData col8 = new ColumnMetaData();
+ col8.setColIndex(colIndex);
+ col8.setColName("TYPE_NAME");
+ col8.setColType(Types.NCHAR);
+ return col8;
+ }
+
+ private ColumnMetaData buildSelfReferencingColName(int colIndex) {
+ ColumnMetaData col9 = new ColumnMetaData();
+ col9.setColIndex(colIndex);
+ col9.setColName("SELF_REFERENCING_COL_NAME");
+ col9.setColType(Types.NCHAR);
+ return col9;
+ }
+
+ private ColumnMetaData buildRefGenerationMeta(int colIndex) {
+ ColumnMetaData col10 = new ColumnMetaData();
+ col10.setColIndex(colIndex);
+ col10.setColName("REF_GENERATION");
+ col10.setColType(Types.NCHAR);
+ return col10;
+ }
- stmt.execute("use " + dbname);
- DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
- List columnMetaDataList = new ArrayList<>();
- ColumnMetaData col1 = new ColumnMetaData();
- col1.setColIndex(1);
- col1.setColName("TABLE_CAT");
- col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col1);
- ColumnMetaData col2 = new ColumnMetaData();
- col2.setColIndex(2);
- col2.setColName("TABLE_SCHEM");
- col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col2);
- ColumnMetaData col3 = new ColumnMetaData();
- col3.setColIndex(3);
- col3.setColName("TABLE_NAME");
- col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col3);
- ColumnMetaData col4 = new ColumnMetaData();
- col4.setColIndex(4);
- col4.setColName("TABLE_TYPE");
- col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col4);
- ColumnMetaData col5 = new ColumnMetaData();
- col5.setColIndex(5);
- col5.setColName("REMARKS");
- col5.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col5);
- ColumnMetaData col6 = new ColumnMetaData();
- col6.setColIndex(6);
- col6.setColName("TYPE_CAT");
- col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col6);
- ColumnMetaData col7 = new ColumnMetaData();
- col7.setColIndex(7);
- col7.setColName("TYPE_SCHEM");
- col7.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col7);
- ColumnMetaData col8 = new ColumnMetaData();
- col8.setColIndex(8);
- col8.setColName("TYPE_NAME");
- col8.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col8);
- ColumnMetaData col9 = new ColumnMetaData();
- col9.setColIndex(9);
- col9.setColName("SELF_REFERENCING_COL_NAME");
- col9.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col9);
- ColumnMetaData col10 = new ColumnMetaData();
- col10.setColIndex(10);
- col10.setColName("REF_GENERATION");
- col10.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col10);
- resultSet.setColumnMetaDataList(columnMetaDataList);
+ protected ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types, Connection connection) throws SQLException {
+ if (catalog == null || catalog.isEmpty())
+ return null;
+ if (!isAvailableCatalog(connection, catalog))
+ return new EmptyResultSet();
- List rowDataList = new ArrayList<>();
+ DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
+ // set column metadata list
+ resultSet.setColumnMetaDataList(buildGetTablesColumnMetaDataList());
+ // set row data
+ List rowDataList = new ArrayList<>();
+ try (Statement stmt = connection.createStatement()) {
+ stmt.execute("use " + catalog);
ResultSet tables = stmt.executeQuery("show tables");
while (tables.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(10);
- rowData.setString(0, dbname); //table_cat
- rowData.setString(1, null); //TABLE_SCHEM
- rowData.setString(2, tables.getString("table_name")); //TABLE_NAME
- rowData.setString(3, "TABLE"); //TABLE_TYPE
- rowData.setString(4, ""); //REMARKS
+ rowData.setStringValue(1, catalog); //TABLE_CAT
+ rowData.setStringValue(2, null); //TABLE_SCHEM
+ rowData.setStringValue(3, tables.getString("table_name")); //TABLE_NAME
+ rowData.setStringValue(4, "TABLE"); //TABLE_TYPE
+ rowData.setStringValue(5, ""); //REMARKS
rowDataList.add(rowData);
}
-
ResultSet stables = stmt.executeQuery("show stables");
while (stables.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(10);
- rowData.setString(0, dbname); //TABLE_CAT
- rowData.setString(1, null); //TABLE_SCHEM
- rowData.setString(2, stables.getString("name")); //TABLE_NAME
- rowData.setString(3, "TABLE"); //TABLE_TYPE
- rowData.setString(4, "STABLE"); //REMARKS
+ rowData.setStringValue(1, catalog); //TABLE_CAT
+ rowData.setStringValue(2, null); //TABLE_SCHEM
+ rowData.setStringValue(3, stables.getString("name")); //TABLE_NAME
+ rowData.setStringValue(4, "TABLE"); //TABLE_TYPE
+ rowData.setStringValue(5, "STABLE"); //REMARKS
rowDataList.add(rowData);
}
resultSet.setRowDataList(rowDataList);
- return resultSet;
}
+ return resultSet;
+ }
+
+ private ColumnMetaData buildTableTypeMeta(int colIndex) {
+ ColumnMetaData col4 = new ColumnMetaData();
+ col4.setColIndex(colIndex);
+ col4.setColName("TABLE_TYPE");
+ col4.setColType(Types.NCHAR);
+ return col4;
}
public ResultSet getSchemas() throws SQLException {
@@ -597,25 +603,24 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
public abstract ResultSet getCatalogs() throws SQLException;
+ private List buildTableTypesColumnMetadataList() {
+ List columnMetaDataList = new ArrayList<>();
+ columnMetaDataList.add(buildTableTypeMeta(1));
+ return columnMetaDataList;
+ }
+
public ResultSet getTableTypes() throws SQLException {
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
// set up ColumnMetaDataList
- List columnMetaDataList = new ArrayList<>();
- ColumnMetaData colMetaData = new ColumnMetaData();
- colMetaData.setColIndex(0);
- colMetaData.setColName("TABLE_TYPE");
- colMetaData.setColSize(10);
- colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(colMetaData);
- resultSet.setColumnMetaDataList(columnMetaDataList);
+ resultSet.setColumnMetaDataList(buildTableTypesColumnMetadataList());
// set up rowDataList
List rowDataList = new ArrayList<>();
TSDBResultSetRowData rowData = new TSDBResultSetRowData(1);
- rowData.setString(0, "TABLE");
+ rowData.setStringValue(1, "TABLE");
rowDataList.add(rowData);
rowData = new TSDBResultSetRowData(1);
- rowData.setString(0, "STABLE");
+ rowData.setStringValue(1, "STABLE");
rowDataList.add(rowData);
resultSet.setRowDataList(rowDataList);
@@ -625,278 +630,330 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
public abstract ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;
protected ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern, Connection conn) {
- try (Statement stmt = conn.createStatement()) {
- if (catalog == null || catalog.isEmpty())
- return null;
-
- ResultSet databases = stmt.executeQuery("show databases");
- String dbname = null;
- while (databases.next()) {
- dbname = databases.getString("name");
- if (dbname.equalsIgnoreCase(catalog))
- break;
- }
- databases.close();
- if (dbname == null)
- return null;
+ if (catalog == null || catalog.isEmpty())
+ return null;
+ if (!isAvailableCatalog(conn, catalog))
+ return new EmptyResultSet();
- stmt.execute("use " + dbname);
- DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
- // set up ColumnMetaDataList
-
- List columnMetaDataList = new ArrayList<>();
- // TABLE_CAT
- ColumnMetaData col1 = new ColumnMetaData();
- col1.setColIndex(1);
- col1.setColName("TABLE_CAT");
- col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col1);
- // TABLE_SCHEM
- ColumnMetaData col2 = new ColumnMetaData();
- col2.setColIndex(2);
- col2.setColName("TABLE_SCHEM");
- col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col2);
- // TABLE_NAME
- ColumnMetaData col3 = new ColumnMetaData();
- col3.setColIndex(3);
- col3.setColName("TABLE_NAME");
- col3.setColSize(193);
- col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col3);
- // COLUMN_NAME
- ColumnMetaData col4 = new ColumnMetaData();
- col4.setColIndex(4);
- col4.setColName("COLUMN_NAME");
- col4.setColSize(65);
- col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col4);
- // DATA_TYPE
- ColumnMetaData col5 = new ColumnMetaData();
- col5.setColIndex(5);
- col5.setColName("DATA_TYPE");
- col5.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
- columnMetaDataList.add(col5);
- // TYPE_NAME
- ColumnMetaData col6 = new ColumnMetaData();
- col6.setColIndex(6);
- col6.setColName("TYPE_NAME");
- col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col6);
- // COLUMN_SIZE
- ColumnMetaData col7 = new ColumnMetaData();
- col7.setColIndex(7);
- col7.setColName("COLUMN_SIZE");
- col7.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
- columnMetaDataList.add(col7);
- // BUFFER_LENGTH, not used
- ColumnMetaData col8 = new ColumnMetaData();
- col8.setColIndex(8);
- col8.setColName("BUFFER_LENGTH");
- columnMetaDataList.add(col8);
- // DECIMAL_DIGITS
- ColumnMetaData col9 = new ColumnMetaData();
- col9.setColIndex(9);
- col9.setColName("DECIMAL_DIGITS");
- col9.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
- columnMetaDataList.add(col9);
- // add NUM_PREC_RADIX
- ColumnMetaData col10 = new ColumnMetaData();
- col10.setColIndex(10);
- col10.setColName("NUM_PREC_RADIX");
- col10.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
- columnMetaDataList.add(col10);
- // NULLABLE
- ColumnMetaData col11 = new ColumnMetaData();
- col11.setColIndex(11);
- col11.setColName("NULLABLE");
- col11.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
- columnMetaDataList.add(col11);
- // REMARKS
- ColumnMetaData col12 = new ColumnMetaData();
- col12.setColIndex(12);
- col12.setColName("REMARKS");
- col12.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col12);
- // COLUMN_DEF
- ColumnMetaData col13 = new ColumnMetaData();
- col13.setColIndex(13);
- col13.setColName("COLUMN_DEF");
- col13.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col13);
- //SQL_DATA_TYPE
- ColumnMetaData col14 = new ColumnMetaData();
- col14.setColIndex(14);
- col14.setColName("SQL_DATA_TYPE");
- col14.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
- columnMetaDataList.add(col14);
- //SQL_DATETIME_SUB
- ColumnMetaData col15 = new ColumnMetaData();
- col15.setColIndex(15);
- col15.setColName("SQL_DATETIME_SUB");
- col15.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
- columnMetaDataList.add(col15);
- //CHAR_OCTET_LENGTH
- ColumnMetaData col16 = new ColumnMetaData();
- col16.setColIndex(16);
- col16.setColName("CHAR_OCTET_LENGTH");
- col16.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
- columnMetaDataList.add(col16);
- //ORDINAL_POSITION
- ColumnMetaData col17 = new ColumnMetaData();
- col17.setColIndex(17);
- col17.setColName("ORDINAL_POSITION");
- col17.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
- columnMetaDataList.add(col17);
- // IS_NULLABLE
- ColumnMetaData col18 = new ColumnMetaData();
- col18.setColIndex(18);
- col18.setColName("IS_NULLABLE");
- col18.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col18);
- //SCOPE_CATALOG
- ColumnMetaData col19 = new ColumnMetaData();
- col19.setColIndex(19);
- col19.setColName("SCOPE_CATALOG");
- col19.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col19);
- //SCOPE_SCHEMA
- ColumnMetaData col20 = new ColumnMetaData();
- col20.setColIndex(20);
- col20.setColName("SCOPE_SCHEMA");
- col20.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col20);
- //SCOPE_TABLE
- ColumnMetaData col21 = new ColumnMetaData();
- col21.setColIndex(21);
- col21.setColName("SCOPE_TABLE");
- col21.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col21);
- //SOURCE_DATA_TYPE
- ColumnMetaData col22 = new ColumnMetaData();
- col22.setColIndex(22);
- col22.setColName("SOURCE_DATA_TYPE");
- col22.setColType(TSDBConstants.TSDB_DATA_TYPE_SMALLINT);
- columnMetaDataList.add(col22);
- //IS_AUTOINCREMENT
- ColumnMetaData col23 = new ColumnMetaData();
- col23.setColIndex(23);
- col23.setColName("IS_AUTOINCREMENT");
- col23.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col23);
- //IS_GENERATEDCOLUMN
- ColumnMetaData col24 = new ColumnMetaData();
- col24.setColIndex(24);
- col24.setColName("IS_GENERATEDCOLUMN");
- col24.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col24);
-
- resultSet.setColumnMetaDataList(columnMetaDataList);
- // set up rowDataList
- ResultSet rs = stmt.executeQuery("describe " + dbname + "." + tableNamePattern);
- List rowDataList = new ArrayList<>();
- int index = 0;
+ DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
+ // set up ColumnMetaDataList
+ resultSet.setColumnMetaDataList(buildGetColumnsColumnMetaDataList());
+ // set up rowDataList
+ List rowDataList = new ArrayList<>();
+ try (Statement stmt = conn.createStatement()) {
+ ResultSet rs = stmt.executeQuery("describe " + catalog + "." + tableNamePattern);
+ int rowIndex = 0;
while (rs.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(24);
// set TABLE_CAT
- rowData.setString(0, dbname);
+ rowData.setStringValue(1, catalog);
+ // set TABLE_SCHEM
+ rowData.setStringValue(2, null);
// set TABLE_NAME
- rowData.setString(2, tableNamePattern);
+ rowData.setStringValue(3, tableNamePattern);
// set COLUMN_NAME
- rowData.setString(3, rs.getString("Field"));
+ rowData.setStringValue(4, rs.getString("Field"));
// set DATA_TYPE
String typeName = rs.getString("Type");
- rowData.setInt(4, getDataType(typeName));
+ rowData.setIntValue(5, TSDBConstants.typeName2JdbcType(typeName));
// set TYPE_NAME
- rowData.setString(5, typeName);
+ rowData.setStringValue(6, typeName);
// set COLUMN_SIZE
int length = rs.getInt("Length");
- rowData.setInt(6, getColumnSize(typeName, length));
+ rowData.setIntValue(7, calculateColumnSize(typeName, precision, length));
+ // set BUFFER LENGTH
+ rowData.setStringValue(8, null);
// set DECIMAL_DIGITS
- rowData.setInt(8, getDecimalDigits(typeName));
+ Integer decimalDigits = calculateDecimalDigits(typeName);
+ if (decimalDigits != null) {
+ rowData.setIntValue(9, decimalDigits);
+ } else {
+ rowData.setStringValue(9, null);
+ }
// set NUM_PREC_RADIX
- rowData.setInt(9, 10);
+ rowData.setIntValue(10, 10);
// set NULLABLE
- rowData.setInt(10, getNullable(index, typeName));
+ rowData.setIntValue(11, isNullable(rowIndex, typeName));
// set REMARKS
- rowData.setString(11, rs.getString("Note"));
+ String note = rs.getString("Note");
+ rowData.setStringValue(12, note.trim().isEmpty() ? null : note);
rowDataList.add(rowData);
- index++;
+ rowIndex++;
}
resultSet.setRowDataList(rowDataList);
- return resultSet;
-
} catch (SQLException e) {
e.printStackTrace();
}
- return null;
+ return resultSet;
}
- protected int getNullable(int index, String typeName) {
+ private int isNullable(int index, String typeName) {
if (index == 0 && "TIMESTAMP".equals(typeName))
return DatabaseMetaData.columnNoNulls;
return DatabaseMetaData.columnNullable;
}
- protected int getColumnSize(String typeName, int length) {
+ private Integer calculateColumnSize(String typeName, String precisionType, int length) {
switch (typeName) {
case "TIMESTAMP":
- return 23;
- default:
- return 0;
- }
- }
-
- protected int getDecimalDigits(String typeName) {
- switch (typeName) {
+ return precisionType.equals("ms") ? TSDBConstants.TIMESTAMP_MS_PRECISION : TSDBConstants.TIMESTAMP_US_PRECISION;
+ case "BOOL":
+ return TSDBConstants.BOOLEAN_PRECISION;
+ case "TINYINT":
+ return TSDBConstants.TINYINT_PRECISION;
+ case "SMALLINT":
+ return TSDBConstants.SMALLINT_PRECISION;
+ case "INT":
+ return TSDBConstants.INT_PRECISION;
+ case "BIGINT":
+ return TSDBConstants.BIGINT_PRECISION;
case "FLOAT":
- return 5;
+ return TSDBConstants.FLOAT_PRECISION;
case "DOUBLE":
- return 9;
+ return TSDBConstants.DOUBLE_PRECISION;
+ case "NCHAR":
+ case "BINARY":
+ return length;
default:
- return 0;
+ return null;
}
}
- protected int getDataType(String typeName) {
+ private Integer calculateDecimalDigits(String typeName) {
switch (typeName) {
- case "TIMESTAMP":
- return Types.TIMESTAMP;
+ case "TINYINT":
+ case "SMALLINT":
case "INT":
- return Types.INTEGER;
case "BIGINT":
- return Types.BIGINT;
- case "FLOAT":
- return Types.FLOAT;
- case "DOUBLE":
- return Types.DOUBLE;
- case "BINARY":
- return Types.BINARY;
- case "SMALLINT":
- return Types.SMALLINT;
- case "TINYINT":
- return Types.TINYINT;
- case "BOOL":
- return Types.BOOLEAN;
- case "NCHAR":
- return Types.NCHAR;
+ return 0;
default:
- return Types.NULL;
+ return null;
}
}
- public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern)
- throws SQLException {
+ private ColumnMetaData buildTableCatalogMeta(int colIndex) {
+ ColumnMetaData col1 = new ColumnMetaData();
+ col1.setColIndex(colIndex);
+ col1.setColName("TABLE_CAT");
+ col1.setColType(Types.NCHAR);
+ return col1;
+ }
+
+ private ColumnMetaData buildTableSchemaMeta(int colIndex) {
+ ColumnMetaData col2 = new ColumnMetaData();
+ col2.setColIndex(colIndex);
+ col2.setColName("TABLE_SCHEM");
+ col2.setColType(Types.NCHAR);
+ return col2;
+ }
+
+ private ColumnMetaData buildTableNameMeta(int colIndex) {
+ ColumnMetaData col3 = new ColumnMetaData();
+ col3.setColIndex(colIndex);
+ col3.setColName("TABLE_NAME");
+ col3.setColSize(193);
+ col3.setColType(Types.NCHAR);
+ return col3;
+ }
+
+ private ColumnMetaData buildColumnNameMeta(int colIndex) {
+ ColumnMetaData col4 = new ColumnMetaData();
+ col4.setColIndex(colIndex);
+ col4.setColName("COLUMN_NAME");
+ col4.setColSize(65);
+ col4.setColType(Types.NCHAR);
+ return col4;
+ }
+
+ private ColumnMetaData buildDataTypeMeta(int colIndex) {
+ ColumnMetaData col5 = new ColumnMetaData();
+ col5.setColIndex(colIndex);
+ col5.setColName("DATA_TYPE");
+ col5.setColType(Types.INTEGER);
+ return col5;
+ }
+
+ private ColumnMetaData buildColumnSizeMeta() {
+ ColumnMetaData col7 = new ColumnMetaData();
+ col7.setColIndex(7);
+ col7.setColName("COLUMN_SIZE");
+ col7.setColType(Types.INTEGER);
+ return col7;
+ }
+
+ private ColumnMetaData buildBufferLengthMeta() {
+ ColumnMetaData col8 = new ColumnMetaData();
+ col8.setColIndex(8);
+ col8.setColName("BUFFER_LENGTH");
+ return col8;
+ }
+
+ private ColumnMetaData buildDecimalDigitsMeta() {
+ ColumnMetaData col9 = new ColumnMetaData();
+ col9.setColIndex(9);
+ col9.setColName("DECIMAL_DIGITS");
+ col9.setColType(Types.INTEGER);
+ return col9;
+ }
+
+ private ColumnMetaData buildNumPrecRadixMeta() {
+ ColumnMetaData col10 = new ColumnMetaData();
+ col10.setColIndex(10);
+ col10.setColName("NUM_PREC_RADIX");
+ col10.setColType(Types.INTEGER);
+ return col10;
+ }
+
+ private ColumnMetaData buildNullableMeta() {
+ ColumnMetaData col11 = new ColumnMetaData();
+ col11.setColIndex(11);
+ col11.setColName("NULLABLE");
+ col11.setColType(Types.INTEGER);
+ return col11;
+ }
+
+ private ColumnMetaData buildRemarksMeta(int colIndex) {
+ ColumnMetaData col12 = new ColumnMetaData();
+ col12.setColIndex(colIndex);
+ col12.setColName("REMARKS");
+ col12.setColType(Types.NCHAR);
+ return col12;
+ }
+
+ private ColumnMetaData buildColumnDefMeta() {
+ ColumnMetaData col13 = new ColumnMetaData();
+ col13.setColIndex(13);
+ col13.setColName("COLUMN_DEF");
+ col13.setColType(Types.NCHAR);
+ return col13;
+ }
+
+ private ColumnMetaData buildSqlDataTypeMeta() {
+ ColumnMetaData col14 = new ColumnMetaData();
+ col14.setColIndex(14);
+ col14.setColName("SQL_DATA_TYPE");
+ col14.setColType(Types.INTEGER);
+ return col14;
+ }
+
+ private ColumnMetaData buildSqlDatetimeSubMeta() {
+ ColumnMetaData col15 = new ColumnMetaData();
+ col15.setColIndex(15);
+ col15.setColName("SQL_DATETIME_SUB");
+ col15.setColType(Types.INTEGER);
+ return col15;
+ }
+
+ private ColumnMetaData buildCharOctetLengthMeta() {
+ ColumnMetaData col16 = new ColumnMetaData();
+ col16.setColIndex(16);
+ col16.setColName("CHAR_OCTET_LENGTH");
+ col16.setColType(Types.INTEGER);
+ return col16;
+ }
+
+ private ColumnMetaData buildOrdinalPositionMeta() {
+ ColumnMetaData col17 = new ColumnMetaData();
+ col17.setColIndex(17);
+ col17.setColName("ORDINAL_POSITION");
+ col17.setColType(Types.INTEGER);
+ return col17;
+ }
+
+ private ColumnMetaData buildIsNullableMeta() {
+ ColumnMetaData col18 = new ColumnMetaData();
+ col18.setColIndex(18);
+ col18.setColName("IS_NULLABLE");
+ col18.setColType(Types.NCHAR);
+ return col18;
+ }
+
+ private ColumnMetaData buildScopeCatalogMeta() {
+ ColumnMetaData col19 = new ColumnMetaData();
+ col19.setColIndex(19);
+ col19.setColName("SCOPE_CATALOG");
+ col19.setColType(Types.NCHAR);
+ return col19;
+ }
+
+ private ColumnMetaData buildScopeSchemaMeta() {
+ ColumnMetaData col20 = new ColumnMetaData();
+ col20.setColIndex(20);
+ col20.setColName("SCOPE_SCHEMA");
+ col20.setColType(Types.NCHAR);
+ return col20;
+ }
+
+ private ColumnMetaData buildScopeTableMeta() {
+ ColumnMetaData col21 = new ColumnMetaData();
+ col21.setColIndex(21);
+ col21.setColName("SCOPE_TABLE");
+ col21.setColType(Types.NCHAR);
+ return col21;
+ }
+
+ private ColumnMetaData buildSourceDataTypeMeta() {
+ ColumnMetaData col22 = new ColumnMetaData();
+ col22.setColIndex(22);
+ col22.setColName("SOURCE_DATA_TYPE");
+ col22.setColType(TSDBConstants.TSDB_DATA_TYPE_SMALLINT);
+ return col22;
+ }
+
+ private ColumnMetaData buildIsAutoIncrementMeta() {
+ ColumnMetaData col23 = new ColumnMetaData();
+ col23.setColIndex(23);
+ col23.setColName("IS_AUTOINCREMENT");
+ col23.setColType(Types.NCHAR);
+ return col23;
+ }
+
+ private ColumnMetaData buildIsGeneratedColumnMeta() {
+ ColumnMetaData col24 = new ColumnMetaData();
+ col24.setColIndex(24);
+ col24.setColName("IS_GENERATEDCOLUMN");
+ col24.setColType(Types.NCHAR);
+ return col24;
+ }
+
+ private List buildGetColumnsColumnMetaDataList() {
+ List columnMetaDataList = new ArrayList<>();
+ columnMetaDataList.add(buildTableCatalogMeta(1)); //1. TABLE_CAT
+ columnMetaDataList.add(buildTableSchemaMeta(2)); //2. TABLE_SCHEMA
+ columnMetaDataList.add(buildTableNameMeta(3)); //3. TABLE_NAME
+ columnMetaDataList.add(buildColumnNameMeta(4)); //4. COLUMN_NAME
+ columnMetaDataList.add(buildDataTypeMeta(5)); //5. DATA_TYPE
+ columnMetaDataList.add(buildTypeNameMeta(6)); //6. TYPE_NAME
+ columnMetaDataList.add(buildColumnSizeMeta()); //7. COLUMN_SIZE
+ columnMetaDataList.add(buildBufferLengthMeta()); //8. BUFFER_LENGTH, not used
+ columnMetaDataList.add(buildDecimalDigitsMeta()); //9. DECIMAL_DIGITS
+ columnMetaDataList.add(buildNumPrecRadixMeta()); //10. NUM_PREC_RADIX
+ columnMetaDataList.add(buildNullableMeta()); //11. NULLABLE
+ columnMetaDataList.add(buildRemarksMeta(12)); //12. REMARKS
+ columnMetaDataList.add(buildColumnDefMeta()); //13. COLUMN_DEF
+ columnMetaDataList.add(buildSqlDataTypeMeta()); //14. SQL_DATA_TYPE
+ columnMetaDataList.add(buildSqlDatetimeSubMeta()); //15. SQL_DATETIME_SUB
+ columnMetaDataList.add(buildCharOctetLengthMeta()); //16. CHAR_OCTET_LENGTH
+ columnMetaDataList.add(buildOrdinalPositionMeta()); //17. ORDINAL_POSITION
+ columnMetaDataList.add(buildIsNullableMeta()); //18. IS_NULLABLE
+ columnMetaDataList.add(buildScopeCatalogMeta()); //19. SCOPE_CATALOG
+ columnMetaDataList.add(buildScopeSchemaMeta()); //20. SCOPE_SCHEMA
+ columnMetaDataList.add(buildScopeTableMeta()); //21. SCOPE_TABLE
+ columnMetaDataList.add(buildSourceDataTypeMeta()); //22. SOURCE_DATA_TYPE
+ columnMetaDataList.add(buildIsAutoIncrementMeta()); //23. IS_AUTOINCREMENT
+ columnMetaDataList.add(buildIsGeneratedColumnMeta()); //24. IS_GENERATEDCOLUMN
+ return columnMetaDataList;
+ }
+
+ public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException {
return getEmptyResultSet();
}
- public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern)
- throws SQLException {
+ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
return getEmptyResultSet();
}
- public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable)
- throws SQLException {
+ public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException {
return getEmptyResultSet();
}
@@ -914,8 +971,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
return getEmptyResultSet();
}
- public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable,
- String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException {
+ public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException {
return getEmptyResultSet();
}
@@ -923,8 +979,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
return getEmptyResultSet();
}
- public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate)
- throws SQLException {
+ public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException {
return getEmptyResultSet();
}
@@ -976,8 +1031,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
return false;
}
- public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types)
- throws SQLException {
+ public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException {
return getEmptyResultSet();
}
@@ -1005,8 +1059,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
public abstract ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException;
- public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern,
- String attributeNamePattern) throws SQLException {
+ public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException {
return getEmptyResultSet();
}
@@ -1069,18 +1122,15 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
return getEmptyResultSet();
}
- public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern)
- throws SQLException {
+ public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException {
return getEmptyResultSet();
}
- public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern,
- String columnNamePattern) throws SQLException {
+ public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException {
return getEmptyResultSet();
}
- public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern,
- String columnNamePattern) throws SQLException {
+ public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
return getEmptyResultSet();
}
@@ -1093,164 +1143,142 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da
}
protected ResultSet getCatalogs(Connection conn) throws SQLException {
- try (Statement stmt = conn.createStatement()) {
- DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
- // set up ColumnMetaDataList
- List columnMetaDataList = new ArrayList<>();
- // TABLE_CAT
- ColumnMetaData col1 = new ColumnMetaData();
- col1.setColIndex(1);
- col1.setColName("TABLE_CAT");
- col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col1);
-
- resultSet.setColumnMetaDataList(columnMetaDataList);
+ DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
+ // set up ColumnMetaDataList
+ List columnMetaDataList = new ArrayList<>();
+ columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT
+ resultSet.setColumnMetaDataList(columnMetaDataList);
+ try (Statement stmt = conn.createStatement()) {
List rowDataList = new ArrayList<>();
ResultSet rs = stmt.executeQuery("show databases");
while (rs.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(1);
- rowData.setString(0, rs.getString("name"));
+ rowData.setStringValue(1, rs.getString("name"));
rowDataList.add(rowData);
}
resultSet.setRowDataList(rowDataList);
- return resultSet;
}
+ return resultSet;
}
protected ResultSet getPrimaryKeys(String catalog, String schema, String table, Connection conn) throws SQLException {
- try (Statement stmt = conn.createStatement()) {
- if (catalog == null || catalog.isEmpty())
- return null;
+ if (catalog == null || catalog.isEmpty())
+ return null;
+ if (!isAvailableCatalog(conn, catalog))
+ return new EmptyResultSet();
- ResultSet databases = stmt.executeQuery("show databases");
- String dbname = null;
- while (databases.next()) {
- dbname = databases.getString("name");
- if (dbname.equalsIgnoreCase(catalog))
- break;
- }
- databases.close();
- if (dbname == null)
- return null;
-
- stmt.execute("use " + dbname);
- DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
+ DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
+ try (Statement stmt = conn.createStatement()) {
// set up ColumnMetaDataList
- List columnMetaDataList = new ArrayList<>();
- // TABLE_CAT
- ColumnMetaData col1 = new ColumnMetaData();
- col1.setColIndex(0);
- col1.setColName("TABLE_CAT");
- col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col1);
- // TABLE_SCHEM
- ColumnMetaData col2 = new ColumnMetaData();
- col2.setColIndex(1);
- col2.setColName("TABLE_SCHEM");
- col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col2);
- // TABLE_NAME
- ColumnMetaData col3 = new ColumnMetaData();
- col3.setColIndex(2);
- col3.setColName("TABLE_NAME");
- col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col3);
- // COLUMN_NAME
- ColumnMetaData col4 = new ColumnMetaData();
- col4.setColIndex(3);
- col4.setColName("COLUMN_NAME");
- col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col4);
- // KEY_SEQ
- ColumnMetaData col5 = new ColumnMetaData();
- col5.setColIndex(4);
- col5.setColName("KEY_SEQ");
- col5.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
- columnMetaDataList.add(col5);
- // PK_NAME
- ColumnMetaData col6 = new ColumnMetaData();
- col6.setColIndex(5);
- col6.setColName("PK_NAME");
- col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col6);
- resultSet.setColumnMetaDataList(columnMetaDataList);
-
+ resultSet.setColumnMetaDataList(buildGetPrimaryKeysMetadataList());
// set rowData
List rowDataList = new ArrayList<>();
- ResultSet rs = stmt.executeQuery("describe " + dbname + "." + table);
+ ResultSet rs = stmt.executeQuery("describe " + catalog + "." + table);
rs.next();
TSDBResultSetRowData rowData = new TSDBResultSetRowData(6);
- rowData.setString(0, null);
- rowData.setString(1, null);
- rowData.setString(2, table);
- String pkName = rs.getString(1);
- rowData.setString(3, pkName);
- rowData.setInt(4, 1);
- rowData.setString(5, pkName);
+ rowData.setStringValue(1, catalog);
+ rowData.setStringValue(2, null);
+ rowData.setStringValue(3, table);
+ String primaryKey = rs.getString("Field");
+ rowData.setStringValue(4, primaryKey);
+ rowData.setShortValue(5, (short) 1);
+ rowData.setStringValue(6, primaryKey);
rowDataList.add(rowData);
resultSet.setRowDataList(rowDataList);
- return resultSet;
}
+ return resultSet;
}
- protected ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern, Connection conn) throws SQLException {
- try (Statement stmt = conn.createStatement()) {
- if (catalog == null || catalog.isEmpty())
- return null;
+ private List buildGetPrimaryKeysMetadataList() {
+ List columnMetaDataList = new ArrayList<>();
+ columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT
+ columnMetaDataList.add(buildTableSchemaMeta(2)); // 2. TABLE_SCHEM
+ columnMetaDataList.add(buildTableNameMeta(3)); // 3. TABLE_NAME
+ columnMetaDataList.add(buildColumnNameMeta(4)); // 4. COLUMN_NAME
+ columnMetaDataList.add(buildKeySeqMeta(5)); // 5. KEY_SEQ
+ columnMetaDataList.add(buildPrimaryKeyNameMeta(6)); // 6. PK_NAME
+ return columnMetaDataList;
+ }
+
+ private ColumnMetaData buildKeySeqMeta(int colIndex) {
+ ColumnMetaData col5 = new ColumnMetaData();
+ col5.setColIndex(colIndex);
+ col5.setColName("KEY_SEQ");
+ col5.setColType(Types.SMALLINT);
+ return col5;
+ }
+
+ private ColumnMetaData buildPrimaryKeyNameMeta(int colIndex) {
+ ColumnMetaData col6 = new ColumnMetaData();
+ col6.setColIndex(colIndex);
+ col6.setColName("PK_NAME");
+ col6.setColType(Types.NCHAR);
+ return col6;
+ }
+ private boolean isAvailableCatalog(Connection connection, String catalog) {
+ try (Statement stmt = connection.createStatement()) {
ResultSet databases = stmt.executeQuery("show databases");
- String dbname = null;
while (databases.next()) {
- dbname = databases.getString("name");
+ String dbname = databases.getString("name");
+ this.database = dbname;
+ this.precision = databases.getString("precision");
if (dbname.equalsIgnoreCase(catalog))
- break;
+ return true;
}
databases.close();
- if (dbname == null)
- return null;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
- stmt.execute("use " + dbname);
- DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
- // set up ColumnMetaDataList
- List columnMetaDataList = new ArrayList<>();
- // TABLE_CAT
- ColumnMetaData col1 = new ColumnMetaData();
- col1.setColIndex(0);
- col1.setColName("TABLE_CAT");
- col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col1);
- // TABLE_SCHEM
- ColumnMetaData col2 = new ColumnMetaData();
- col2.setColIndex(1);
- col2.setColName("TABLE_SCHEM");
- col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col2);
- // TABLE_NAME
- ColumnMetaData col3 = new ColumnMetaData();
- col3.setColIndex(2);
- col3.setColName("TABLE_NAME");
- col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col3);
- // SUPERTABLE_NAME
- ColumnMetaData col4 = new ColumnMetaData();
- col4.setColIndex(3);
- col4.setColName("SUPERTABLE_NAME");
- col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
- columnMetaDataList.add(col4);
- resultSet.setColumnMetaDataList(columnMetaDataList);
+ protected ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern, Connection conn) throws SQLException {
+ if (catalog == null || catalog.isEmpty())
+ return null;
+
+ if (!isAvailableCatalog(conn, catalog)) {
+ return new EmptyResultSet();
+ }
+ DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
+ try (Statement stmt = conn.createStatement()) {
+ // set up ColumnMetaDataList
+ resultSet.setColumnMetaDataList(buildGetSuperTablesColumnMetaDataList());
+ // set result set row data
+ stmt.execute("use " + catalog);
ResultSet rs = stmt.executeQuery("show tables like '" + tableNamePattern + "'");
List rowDataList = new ArrayList<>();
while (rs.next()) {
TSDBResultSetRowData rowData = new TSDBResultSetRowData(4);
- rowData.setString(2, rs.getString(1));
- rowData.setString(3, rs.getString(4));
+ rowData.setStringValue(1, catalog);
+ rowData.setStringValue(2, null);
+ rowData.setStringValue(3, rs.getString("table_name"));
+ rowData.setStringValue(4, rs.getString("stable_name"));
rowDataList.add(rowData);
}
resultSet.setRowDataList(rowDataList);
- return resultSet;
}
+ return resultSet;
+ }
+
+ private List buildGetSuperTablesColumnMetaDataList() {
+ List columnMetaDataList = new ArrayList<>();
+ columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT
+ columnMetaDataList.add(buildTableSchemaMeta(2)); // 2. TABLE_SCHEM
+ columnMetaDataList.add(buildTableNameMeta(3)); // 3. TABLE_NAME
+ columnMetaDataList.add(buildSuperTableNameMeta(4)); // 4. SUPERTABLE_NAME
+ return columnMetaDataList;
}
+
+ private ColumnMetaData buildSuperTableNameMeta(int colIndex) {
+ ColumnMetaData col4 = new ColumnMetaData();
+ col4.setColIndex(colIndex);
+ col4.setColName("SUPERTABLE_NAME");
+ col4.setColType(Types.NCHAR);
+ return col4;
+ }
+
}
\ No newline at end of file
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java
index 7df7252ae2010b5aa5e8f74de2cca55844e25b83..cb6c7d40ad1f1e12324043d78cb423fcfd46dca8 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java
@@ -1,5 +1,7 @@
package com.taosdata.jdbc;
+import com.sun.org.apache.xpath.internal.operations.Bool;
+
import java.sql.ParameterMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
@@ -49,6 +51,22 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P
if (param < 1 && param >= parameters.length)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
+ if (parameters[param - 1] instanceof Boolean)
+ return TSDBConstants.BOOLEAN_PRECISION;
+ if (parameters[param - 1] instanceof Byte)
+ return TSDBConstants.TINYINT_PRECISION;
+ if (parameters[param - 1] instanceof Short)
+ return TSDBConstants.SMALLINT_PRECISION;
+ if (parameters[param - 1] instanceof Integer)
+ return TSDBConstants.INT_PRECISION;
+ if (parameters[param - 1] instanceof Long)
+ return TSDBConstants.BIGINT_PRECISION;
+ if (parameters[param - 1] instanceof Timestamp)
+ return TSDBConstants.TIMESTAMP_MS_PRECISION;
+ if (parameters[param - 1] instanceof Float)
+ return TSDBConstants.FLOAT_PRECISION;
+ if (parameters[param - 1] instanceof Double)
+ return TSDBConstants.DOUBLE_PRECISION;
if (parameters[param - 1] instanceof String)
return ((String) parameters[param - 1]).length();
if (parameters[param - 1] instanceof byte[])
@@ -60,6 +78,11 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P
public int getScale(int param) throws SQLException {
if (param < 1 && param >= parameters.length)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
+
+ if (parameters[param - 1] instanceof Float)
+ return TSDBConstants.FLOAT_SCALE;
+ if (parameters[param - 1] instanceof Double)
+ return TSDBConstants.DOUBLE_SCALE;
return 0;
}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java
index f8ea9af4230e9584197f1141dc5a4f7c1621b3ff..e17548055c792e900a1e2fb5b510de8bf65de7a7 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java
@@ -66,10 +66,16 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet
public abstract byte[] getBytes(int columnIndex) throws SQLException;
@Override
- public abstract Date getDate(int columnIndex) throws SQLException;
+ public Date getDate(int columnIndex) throws SQLException {
+ Timestamp timestamp = getTimestamp(columnIndex);
+ return timestamp == null ? null : new Date(timestamp.getTime());
+ }
@Override
- public abstract Time getTime(int columnIndex) throws SQLException;
+ public Time getTime(int columnIndex) throws SQLException {
+ Timestamp timestamp = getTimestamp(columnIndex);
+ return timestamp == null ? null : new Time(timestamp.getTime());
+ }
@Override
public abstract Timestamp getTimestamp(int columnIndex) throws SQLException;
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
index f6a0fcca316cb07d28c71a4e1d51d9405de083ba..cd266529f34c0693a9891af33c12705b90132800 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
@@ -14,76 +14,42 @@
*****************************************************************************/
package com.taosdata.jdbc;
-import java.io.InputStream;
-import java.io.Reader;
import java.math.BigDecimal;
-import java.net.URL;
-import java.sql.Date;
import java.sql.*;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
/*
- * TDengine only supports a subset of the standard SQL, thus this implemetation of the
+ * TDengine only supports a subset of the standard SQL, thus this implementation of the
* standard JDBC API contains more or less some adjustments customized for certain
* compatibility needs.
*/
-public class DatabaseMetaDataResultSet implements ResultSet {
+public class DatabaseMetaDataResultSet extends AbstractResultSet {
- private List columnMetaDataList;
- private List rowDataList;
+ private List columnMetaDataList = new ArrayList<>();
+ private List rowDataList = new ArrayList<>();
private TSDBResultSetRowData rowCursor;
// position of cursor, starts from 0 as beforeFirst, increases as next() is called
private int cursorRowNumber = 0;
- public DatabaseMetaDataResultSet() {
- rowDataList = new ArrayList();
- columnMetaDataList = new ArrayList();
- }
-
- public List getRowDataList() {
- return rowDataList;
- }
-
public void setRowDataList(List rowDataList) {
this.rowDataList = rowDataList;
}
- public List getColumnMetaDataList() {
- return columnMetaDataList;
- }
-
public void setColumnMetaDataList(List columnMetaDataList) {
this.columnMetaDataList = columnMetaDataList;
}
- public TSDBResultSetRowData getRowCursor() {
- return rowCursor;
- }
-
- public void setRowCursor(TSDBResultSetRowData rowCursor) {
- this.rowCursor = rowCursor;
- }
-
@Override
public boolean next() throws SQLException {
-// boolean ret = false;
-// if (rowDataList.size() > 0) {
-// ret = rowDataList.iterator().hasNext();
-// if (ret) {
-// rowCursor = rowDataList.iterator().next();
-// cursorRowNumber++;
-// }
-// }
-// return ret;
-
- /**** add by zyyang 2020-09-29 ****************/
boolean ret = false;
if (!rowDataList.isEmpty() && cursorRowNumber < rowDataList.size()) {
rowCursor = rowDataList.get(cursorRowNumber++);
ret = true;
}
-
return ret;
}
@@ -99,189 +65,72 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public String getString(int columnIndex) throws SQLException {
- columnIndex--;
- int colType = columnMetaDataList.get(columnIndex).getColType();
- return rowCursor.getString(columnIndex, colType);
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ return rowCursor.getString(columnIndex, nativeType);
}
@Override
public boolean getBoolean(int columnIndex) throws SQLException {
- columnIndex--;
- return rowCursor.getBoolean(columnIndex, columnMetaDataList.get(columnIndex).getColType());
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ return rowCursor.getBoolean(columnIndex, nativeType);
}
@Override
public byte getByte(int columnIndex) throws SQLException {
- columnIndex--;
- return (byte) rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType());
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ return (byte) rowCursor.getInt(columnIndex, nativeType);
}
@Override
public short getShort(int columnIndex) throws SQLException {
- columnIndex--;
- return (short) rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType());
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ return (short) rowCursor.getInt(columnIndex, nativeType);
}
@Override
public int getInt(int columnIndex) throws SQLException {
- columnIndex--;
- return rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType());
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ return rowCursor.getInt(columnIndex, nativeType);
}
@Override
public long getLong(int columnIndex) throws SQLException {
- columnIndex--;
- return rowCursor.getLong(columnIndex, columnMetaDataList.get(columnIndex).getColType());
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ return rowCursor.getLong(columnIndex, nativeType);
}
@Override
public float getFloat(int columnIndex) throws SQLException {
- columnIndex--;
- return rowCursor.getFloat(columnIndex, columnMetaDataList.get(columnIndex).getColType());
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ return rowCursor.getFloat(columnIndex, nativeType);
}
@Override
public double getDouble(int columnIndex) throws SQLException {
- columnIndex--;
- return rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType());
- }
-
- @Override
- public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
- columnIndex--;
- return new BigDecimal(rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType()));
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ return rowCursor.getDouble(columnIndex, nativeType);
}
@Override
public byte[] getBytes(int columnIndex) throws SQLException {
- columnIndex--;
- return (rowCursor.getString(columnIndex, columnMetaDataList.get(columnIndex).getColType())).getBytes();
- }
-
- @Override
- public Date getDate(int columnIndex) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public Time getTime(int columnIndex) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ return (rowCursor.getString(columnIndex, nativeType)).getBytes();
}
@Override
public Timestamp getTimestamp(int columnIndex) throws SQLException {
- columnIndex--;
- return rowCursor.getTimestamp(columnIndex);
- }
-
- @Override
- public InputStream getAsciiStream(int columnIndex) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public InputStream getUnicodeStream(int columnIndex) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public InputStream getBinaryStream(int columnIndex) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public String getString(String columnLabel) throws SQLException {
- return getString(findColumn(columnLabel));
- }
-
- @Override
- public boolean getBoolean(String columnLabel) throws SQLException {
- return getBoolean(findColumn(columnLabel));
- }
-
- @Override
- public byte getByte(String columnLabel) throws SQLException {
- return getByte(findColumn(columnLabel));
- }
-
- @Override
- public short getShort(String columnLabel) throws SQLException {
- return getShort(findColumn(columnLabel));
- }
-
- @Override
- public int getInt(String columnLabel) throws SQLException {
- return getInt(findColumn(columnLabel));
- }
-
- @Override
- public long getLong(String columnLabel) throws SQLException {
- return getLong(findColumn(columnLabel));
- }
-
- @Override
- public float getFloat(String columnLabel) throws SQLException {
- return getFloat(findColumn(columnLabel));
- }
-
- @Override
- public double getDouble(String columnLabel) throws SQLException {
- return getDouble(findColumn(columnLabel));
- }
-
- @Override
- public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
- return getBigDecimal(findColumn(columnLabel));
- }
-
- @Override
- public byte[] getBytes(String columnLabel) throws SQLException {
- return getBytes(findColumn(columnLabel));
- }
-
- @Override
- public Date getDate(String columnLabel) throws SQLException {
- return getDate(findColumn(columnLabel));
- }
-
- @Override
- public Time getTime(String columnLabel) throws SQLException {
- return getTime(findColumn(columnLabel));
- }
-
- @Override
- public Timestamp getTimestamp(String columnLabel) throws SQLException {
- return getTimestamp(findColumn(columnLabel));
- }
-
- @Override
- public InputStream getAsciiStream(String columnLabel) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public InputStream getUnicodeStream(String columnLabel) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public InputStream getBinaryStream(String columnLabel) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public SQLWarning getWarnings() throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void clearWarnings() throws SQLException {
-
- }
-
- @Override
- public String getCursorName() throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ return rowCursor.getTimestamp(columnIndex,nativeType);
}
@Override
@@ -291,12 +140,7 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public Object getObject(int columnIndex) throws SQLException {
- return rowCursor.get(columnIndex);
- }
-
- @Override
- public Object getObject(String columnLabel) throws SQLException {
- return rowCursor.get(findColumn(columnLabel));
+ return rowCursor.getObject(columnIndex);
}
@Override
@@ -304,31 +148,19 @@ public class DatabaseMetaDataResultSet implements ResultSet {
Iterator colMetaDataIt = this.columnMetaDataList.iterator();
while (colMetaDataIt.hasNext()) {
ColumnMetaData colMetaData = colMetaDataIt.next();
- if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) {
- return colMetaData.getColIndex() + 1;
+ if (colMetaData.getColName() != null && colMetaData.getColName().equals(columnLabel)) {
+ return colMetaData.getColIndex();
}
}
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
}
- @Override
- public Reader getCharacterStream(int columnIndex) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public Reader getCharacterStream(String columnLabel) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
@Override
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
- return new BigDecimal(rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType()));
- }
-
- @Override
- public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
- return getBigDecimal(findColumn(columnLabel));
+ int colType = columnMetaDataList.get(columnIndex - 1).getColType();
+ int nativeType = TSDBConstants.jdbcType2TaosType(colType);
+ double value = rowCursor.getDouble(columnIndex, nativeType);
+ return new BigDecimal(value);
}
@Override
@@ -378,7 +210,6 @@ public class DatabaseMetaDataResultSet implements ResultSet {
} else {
return 0;
}
-
}
@Override
@@ -397,680 +228,23 @@ public class DatabaseMetaDataResultSet implements ResultSet {
}
@Override
- public void setFetchDirection(int direction) throws SQLException {
-
- }
-
- @Override
- public int getFetchDirection() throws SQLException {
- return ResultSet.FETCH_FORWARD;
- }
-
- @Override
- public void setFetchSize(int rows) throws SQLException {
-
- }
-
- @Override
- public int getFetchSize() throws SQLException {
- return 0;
- }
-
- @Override
- public int getType() throws SQLException {
- return ResultSet.TYPE_FORWARD_ONLY;
- }
-
- @Override
- public int getConcurrency() throws SQLException {
- return ResultSet.CONCUR_READ_ONLY;
- }
-
- @Override
- public boolean rowUpdated() throws SQLException {
- return false;
+ public Statement getStatement() throws SQLException {
+ return null;
}
- @Override
- public boolean rowInserted() throws SQLException {
- return false;
+ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
+ //TODO: calendar is not used
+ return getTimestamp(columnIndex);
}
@Override
- public boolean rowDeleted() throws SQLException {
+ public boolean isClosed() throws SQLException {
return false;
}
@Override
- public void updateNull(int columnIndex) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateBoolean(int columnIndex, boolean x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateByte(int columnIndex, byte x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateShort(int columnIndex, short x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateInt(int columnIndex, int x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateLong(int columnIndex, long x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateFloat(int columnIndex, float x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateDouble(int columnIndex, double x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateString(int columnIndex, String x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateBytes(int columnIndex, byte[] x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateDate(int columnIndex, Date x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateTime(int columnIndex, Time x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateObject(int columnIndex, Object x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateNull(String columnLabel) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateBoolean(String columnLabel, boolean x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateByte(String columnLabel, byte x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateShort(String columnLabel, short x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateInt(String columnLabel, int x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateLong(String columnLabel, long x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateFloat(String columnLabel, float x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateDouble(String columnLabel, double x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateString(String columnLabel, String x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
+ public String getNString(int columnIndex) throws SQLException {
+ return getString(columnIndex);
}
- @Override
- public void updateBytes(String columnLabel, byte[] x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateDate(String columnLabel, Date x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateTime(String columnLabel, Time x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateObject(String columnLabel, Object x) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void insertRow() throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void updateRow() throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void deleteRow() throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void refreshRow() throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void cancelRowUpdates() throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void moveToInsertRow() throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void moveToCurrentRow() throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public Statement getStatement() throws SQLException {
- return null;
- }
-
- @Override
- public Object getObject(int columnIndex, Map> map) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public Ref getRef(int columnIndex) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public Blob getBlob(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Clob getClob(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Array getArray(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Object getObject(String columnLabel, Map> map) throws SQLException {
- return null;
- }
-
- @Override
- public Ref getRef(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Blob getBlob(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Clob getClob(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Array getArray(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Date getDate(int columnIndex, Calendar cal) throws SQLException {
- return null;
- }
-
- @Override
- public Date getDate(String columnLabel, Calendar cal) throws SQLException {
- return null;
- }
-
- @Override
- public Time getTime(int columnIndex, Calendar cal) throws SQLException {
- return null;
- }
-
- @Override
- public Time getTime(String columnLabel, Calendar cal) throws SQLException {
- return null;
- }
-
- @Override
- public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
- return null;
- }
-
- @Override
- public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException {
- return null;
- }
-
- @Override
- public URL getURL(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public URL getURL(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public void updateRef(int columnIndex, Ref x) throws SQLException {
-
- }
-
- @Override
- public void updateRef(String columnLabel, Ref x) throws SQLException {
-
- }
-
- @Override
- public void updateBlob(int columnIndex, Blob x) throws SQLException {
-
- }
-
- @Override
- public void updateBlob(String columnLabel, Blob x) throws SQLException {
-
- }
-
- @Override
- public void updateClob(int columnIndex, Clob x) throws SQLException {
-
- }
-
- @Override
- public void updateClob(String columnLabel, Clob x) throws SQLException {
-
- }
-
- @Override
- public void updateArray(int columnIndex, Array x) throws SQLException {
-
- }
-
- @Override
- public void updateArray(String columnLabel, Array x) throws SQLException {
-
- }
-
- @Override
- public RowId getRowId(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public RowId getRowId(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public void updateRowId(int columnIndex, RowId x) throws SQLException {
-
- }
-
- @Override
- public void updateRowId(String columnLabel, RowId x) throws SQLException {
-
- }
-
- @Override
- public int getHoldability() throws SQLException {
- return 0;
- }
-
- @Override
- public boolean isClosed() throws SQLException {
- return false;
- }
-
- @Override
- public void updateNString(int columnIndex, String nString) throws SQLException {
-
- }
-
- @Override
- public void updateNString(String columnLabel, String nString) throws SQLException {
-
- }
-
- @Override
- public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
-
- }
-
- @Override
- public void updateNClob(String columnLabel, NClob nClob) throws SQLException {
-
- }
-
- @Override
- public NClob getNClob(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public NClob getNClob(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public SQLXML getSQLXML(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public SQLXML getSQLXML(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
-
- }
-
- @Override
- public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException {
-
- }
-
- @Override
- public String getNString(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public String getNString(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public Reader getNCharacterStream(int columnIndex) throws SQLException {
- return null;
- }
-
- @Override
- public Reader getNCharacterStream(String columnLabel) throws SQLException {
- return null;
- }
-
- @Override
- public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
-
- }
-
- @Override
- public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
-
- }
-
- @Override
- public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
-
- }
-
- @Override
- public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
-
- }
-
- @Override
- public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
-
- }
-
- @Override
- public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
-
- }
-
- @Override
- public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
-
- }
-
- @Override
- public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
-
- }
-
- @Override
- public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException {
-
- }
-
- @Override
- public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException {
-
- }
-
- @Override
- public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
-
- }
-
- @Override
- public void updateClob(String columnLabel, Reader reader, long length) throws SQLException {
-
- }
-
- @Override
- public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
-
- }
-
- @Override
- public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException {
-
- }
-
- @Override
- public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
-
- }
-
- @Override
- public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException {
-
- }
-
- @Override
- public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
-
- }
-
- @Override
- public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
-
- }
-
- @Override
- public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
-
- }
-
- @Override
- public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
-
- }
-
- @Override
- public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
-
- }
-
- @Override
- public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException {
-
- }
-
- @Override
- public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
-
- }
-
- @Override
- public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException {
-
- }
-
- @Override
- public void updateClob(int columnIndex, Reader reader) throws SQLException {
-
- }
-
- @Override
- public void updateClob(String columnLabel, Reader reader) throws SQLException {
-
- }
-
- @Override
- public void updateNClob(int columnIndex, Reader reader) throws SQLException {
-
- }
-
- @Override
- public void updateNClob(String columnLabel, Reader reader) throws SQLException {
-
- }
-
- @Override
- public T getObject(int columnIndex, Class type) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public T getObject(String columnLabel, Class type) throws SQLException {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public T unwrap(Class iface) throws SQLException {
- return null;
- }
-
- @Override
- public boolean isWrapperFor(Class> iface) throws SQLException {
- return false;
- }
-
- private int getTrueColumnIndex(int columnIndex) throws SQLException {
- if (columnIndex < 1) {
- throw new SQLException("Column Index out of range, " + columnIndex + " < " + 1);
- }
-
- int numOfCols = this.columnMetaDataList.size();
- if (columnIndex > numOfCols) {
- throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols);
- }
-
- return columnIndex - 1;
- }
}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
index f38555ce8a6c7ee946b3bdbda2204c702b49198a..e6406d2c6dc7990ec4f3149bb8c5146202f5d326 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
@@ -41,15 +41,15 @@ public abstract class TSDBConstants {
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_NCHAR = 10;
- /*
- 系统增加新的无符号数据类型,分别是:
- 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);
- */
+ /**
+ * 系统增加新的无符号数据类型,分别是:
+ * 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
@@ -57,6 +57,47 @@ public abstract class TSDBConstants {
// nchar column max length
public static final int maxFieldSize = 16 * 1024;
+ // precision for data types
+ public static final int BOOLEAN_PRECISION = 1;
+ public static final int TINYINT_PRECISION = 4;
+ public static final int SMALLINT_PRECISION = 6;
+ public static final int INT_PRECISION = 11;
+ public static final int BIGINT_PRECISION = 20;
+ public static final int FLOAT_PRECISION = 12;
+ public static final int DOUBLE_PRECISION = 22;
+ public static final int TIMESTAMP_MS_PRECISION = 23;
+ public static final int TIMESTAMP_US_PRECISION = 26;
+ // scale for data types
+ public static final int FLOAT_SCALE = 31;
+ public static final int DOUBLE_SCALE = 31;
+
+ public static int typeName2JdbcType(String type) {
+ switch (type.toUpperCase()) {
+ case "TIMESTAMP":
+ return Types.TIMESTAMP;
+ case "INT":
+ return Types.INTEGER;
+ case "BIGINT":
+ return Types.BIGINT;
+ case "FLOAT":
+ return Types.FLOAT;
+ case "DOUBLE":
+ return Types.DOUBLE;
+ case "BINARY":
+ return Types.BINARY;
+ case "SMALLINT":
+ return Types.SMALLINT;
+ case "TINYINT":
+ return Types.TINYINT;
+ case "BOOL":
+ return Types.BOOLEAN;
+ case "NCHAR":
+ return Types.NCHAR;
+ default:
+ return Types.NULL;
+ }
+ }
+
public static int taosType2JdbcType(int taosType) throws SQLException {
switch (taosType) {
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
@@ -88,7 +129,7 @@ public abstract class TSDBConstants {
}
public static String taosType2JdbcTypeName(int taosType) throws SQLException {
- switch (taosType){
+ switch (taosType) {
case TSDBConstants.TSDB_DATA_TYPE_BOOL:
return "BOOL";
case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
@@ -119,7 +160,7 @@ public abstract class TSDBConstants {
}
public static int jdbcType2TaosType(int jdbcType) throws SQLException {
- switch (jdbcType){
+ switch (jdbcType) {
case Types.BOOLEAN:
return TSDBConstants.TSDB_DATA_TYPE_BOOL;
case Types.TINYINT:
@@ -145,7 +186,7 @@ public abstract class TSDBConstants {
}
public static String jdbcType2TaosTypeName(int jdbcType) throws SQLException {
- switch (jdbcType){
+ switch (jdbcType) {
case Types.BOOLEAN:
return "BOOL";
case Types.TINYINT:
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
index 256e735285bd493f37c9e369a49b369e9e6b4b38..92792d97517c98f9a5402aaae557d01e09bbca30 100755
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
@@ -16,13 +16,13 @@
*/
package com.taosdata.jdbc;
+import com.taosdata.jdbc.utils.TaosInfo;
+
import java.nio.ByteBuffer;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.util.List;
-import com.taosdata.jdbc.utils.TaosInfo;
-
/**
* JNI connector
*/
@@ -30,10 +30,10 @@ public class TSDBJNIConnector {
private static volatile Boolean isInitialized = false;
private TaosInfo taosInfo = TaosInfo.getInstance();
-
+
// Connection pointer used in C
private long taos = TSDBConstants.JNI_NULL_POINTER;
-
+
// result set status in current connection
private boolean isResultsetClosed;
@@ -194,7 +194,9 @@ public class TSDBJNIConnector {
* Get schema metadata
*/
public int getSchemaMetaData(long resultSet, List columnMetaData) {
- return this.getSchemaMetaDataImp(this.taos, resultSet, columnMetaData);
+ int ret = this.getSchemaMetaDataImp(this.taos, resultSet, columnMetaData);
+ columnMetaData.stream().forEach(column -> column.setColIndex(column.getColIndex() + 1));
+ return ret;
}
private native int getSchemaMetaDataImp(long connection, long resultSet, List columnMetaData);
@@ -221,7 +223,7 @@ public class TSDBJNIConnector {
*/
public void closeConnection() throws SQLException {
int code = this.closeConnectionImp(this.taos);
-
+
if (code < 0) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
} else if (code == 0) {
@@ -229,7 +231,7 @@ public class TSDBJNIConnector {
} else {
throw new SQLException("Undefined error code returned by TDengine when closing a connection");
}
-
+
// invoke closeConnectionImpl only here
taosInfo.connect_close_increment();
}
@@ -274,67 +276,76 @@ public class TSDBJNIConnector {
}
private native int validateCreateTableSqlImp(long connection, byte[] sqlBytes);
-
- public long prepareStmt(String sql) throws SQLException {
- Long stmt = prepareStmtImp(sql.getBytes(), this.taos);
- if (stmt == TSDBConstants.JNI_TDENGINE_ERROR) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_SQL);
- } else if (stmt == TSDBConstants.JNI_CONNECTION_NULL) {
+
+ public long prepareStmt(String sql) throws SQLException {
+ Long stmt;
+ try {
+ stmt = prepareStmtImp(sql.getBytes(), this.taos);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING);
+ }
+
+ if (stmt == TSDBConstants.JNI_CONNECTION_NULL) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
- } else if (stmt == TSDBConstants.JNI_SQL_NULL) {
+ }
+
+ if (stmt == TSDBConstants.JNI_SQL_NULL) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_SQL_NULL);
- } else if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) {
+ }
+
+ if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY);
}
-
- return stmt;
+
+ return stmt;
}
-
+
private native long prepareStmtImp(byte[] sql, long con);
-
+
public void setBindTableName(long stmt, String tableName) throws SQLException {
- int code = setBindTableNameImp(stmt, tableName, this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
+ int code = setBindTableNameImp(stmt, tableName, this.taos);
+ if (code != TSDBConstants.JNI_SUCCESS) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to set table name");
- }
- }
-
+ }
+ }
+
private native int setBindTableNameImp(long stmt, String name, long conn);
-
+
public void setBindTableNameAndTags(long stmt, String tableName, int numOfTags, ByteBuffer tags, ByteBuffer typeList, ByteBuffer lengthList, ByteBuffer nullList) throws SQLException {
- int code = setTableNameTagsImp(stmt, tableName, numOfTags, tags.array(), typeList.array(), lengthList.array(),
- nullList.array(), this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to bind table name and corresponding tags");
- }
+ int code = setTableNameTagsImp(stmt, tableName, numOfTags, tags.array(), typeList.array(), lengthList.array(),
+ nullList.array(), this.taos);
+ if (code != TSDBConstants.JNI_SUCCESS) {
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to bind table name and corresponding tags");
+ }
}
-
+
private native int setTableNameTagsImp(long stmt, String name, int numOfTags, byte[] tags, byte[] typeList, byte[] lengthList, byte[] nullList, long conn);
-
- public void bindColumnDataArray(long stmt, ByteBuffer colDataList, ByteBuffer lengthList, ByteBuffer isNullList, int type, int bytes, int numOfRows,int columnIndex) throws SQLException {
- int code = bindColDataImp(stmt, colDataList.array(), lengthList.array(), isNullList.array(), type, bytes, numOfRows, columnIndex, this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
+
+ public void bindColumnDataArray(long stmt, ByteBuffer colDataList, ByteBuffer lengthList, ByteBuffer isNullList, int type, int bytes, int numOfRows, int columnIndex) throws SQLException {
+ int code = bindColDataImp(stmt, colDataList.array(), lengthList.array(), isNullList.array(), type, bytes, numOfRows, columnIndex, this.taos);
+ if (code != TSDBConstants.JNI_SUCCESS) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to bind column data");
- }
- }
-
+ }
+ }
+
private native int bindColDataImp(long stmt, byte[] colDataList, byte[] lengthList, byte[] isNullList, int type, int bytes, int numOfRows, int columnIndex, long conn);
-
+
public void executeBatch(long stmt) throws SQLException {
- int code = executeBatchImp(stmt, this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
+ int code = executeBatchImp(stmt, this.taos);
+ if (code != TSDBConstants.JNI_SUCCESS) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to execute batch bind");
- }
+ }
}
-
+
private native int executeBatchImp(long stmt, long con);
-
+
public void closeBatch(long stmt) throws SQLException {
- int code = closeStmt(stmt, this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
+ int code = closeStmt(stmt, this.taos);
+ if (code != TSDBConstants.JNI_SUCCESS) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to close batch bind");
- }
+ }
}
-
+
private native int closeStmt(long stmt, long con);
}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
index f6810237c097a62a4c8f0f63d6e435bfb0354125..c3d5abf35c7304f86f9cc4dc4449d8c88d144e3d 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
@@ -39,18 +39,18 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
private String rawSql;
private Object[] parameters;
private boolean isPrepared;
-
+
private ArrayList colData;
private ArrayList tableTags;
private int tagValueLength;
-
+
private String tableName;
private long nativeStmtHandle = 0;
-
+
private volatile TSDBParameterMetaData parameterMetaData;
TSDBPreparedStatement(TSDBConnection connection, String sql) {
- super(connection);
+ super(connection);
init(sql);
int parameterCnt = 0;
@@ -64,11 +64,11 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
this.isPrepared = true;
}
- if (parameterCnt > 1) {
- // the table name is also a parameter, so ignore it.
- this.colData = new ArrayList();
- this.tableTags = new ArrayList();
- }
+ if (parameterCnt > 1) {
+ // the table name is also a parameter, so ignore it.
+ this.colData = new ArrayList();
+ this.tableTags = new ArrayList();
+ }
}
private void init(String sql) {
@@ -205,9 +205,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
+ setObject(parameterIndex, x.doubleValue());
}
@Override
@@ -222,16 +220,12 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override
public void setDate(int parameterIndex, Date x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
+ setObject(parameterIndex, new Timestamp(x.getTime()));
}
@Override
public void setTime(int parameterIndex, Time x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
+ setObject(parameterIndex, new Timestamp(x.getTime()));
}
@Override
@@ -279,11 +273,10 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
if (isClosed()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
}
-
+
if (parameterIndex < 1 && parameterIndex >= parameters.length) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
}
-
parameters[parameterIndex - 1] = x;
}
@@ -323,7 +316,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
if (isClosed()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
}
-
+
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@@ -350,9 +343,9 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override
public ResultSetMetaData getMetaData() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
+ if (this.getResultSet() == null)
+ return null;
+ return getResultSet().getMetaData();
}
@Override
@@ -396,10 +389,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- if (parameterMetaData == null) {
- this.parameterMetaData = new TSDBParameterMetaData(parameters);
- }
- return this.parameterMetaData;
+ return new TSDBParameterMetaData(parameters);
}
@Override
@@ -411,9 +401,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override
public void setNString(int parameterIndex, String value) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
+ setString(parameterIndex, value);
}
@Override
@@ -536,489 +524,495 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
-
+
///////////////////////////////////////////////////////////////////////
// NOTE: the following APIs are not JDBC compatible
// set the bind table name
private static class ColumnInfo {
- @SuppressWarnings("rawtypes")
- private ArrayList data;
- private int type;
- private int bytes;
- private boolean typeIsSet;
-
- public ColumnInfo() {
- this.typeIsSet = false;
- }
-
- public void setType(int type) throws SQLException {
- if (this.isTypeSet()) {
+ @SuppressWarnings("rawtypes")
+ private ArrayList data;
+ private int type;
+ private int bytes;
+ private boolean typeIsSet;
+
+ public ColumnInfo() {
+ this.typeIsSet = false;
+ }
+
+ public void setType(int type) throws SQLException {
+ if (this.isTypeSet()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data type has been set");
- }
-
- this.typeIsSet = true;
- this.type = type;
- }
-
- public boolean isTypeSet() {
- return this.typeIsSet;
- }
- };
-
+ }
+
+ this.typeIsSet = true;
+ this.type = type;
+ }
+
+ public boolean isTypeSet() {
+ return this.typeIsSet;
+ }
+ }
+
+ ;
+
private static class TableTagInfo {
- private boolean isNull;
- private Object value;
- private int type;
- public TableTagInfo(Object value, int type) {
- this.value = value;
- this.type = type;
- }
-
- public static TableTagInfo createNullTag(int type) {
- TableTagInfo info = new TableTagInfo(null, type);
- info.isNull = true;
- return info;
- }
- };
-
+ private boolean isNull;
+ private Object value;
+ private int type;
+
+ public TableTagInfo(Object value, int type) {
+ this.value = value;
+ this.type = type;
+ }
+
+ public static TableTagInfo createNullTag(int type) {
+ TableTagInfo info = new TableTagInfo(null, type);
+ info.isNull = true;
+ return info;
+ }
+ }
+
+ ;
+
public void setTableName(String name) {
- this.tableName = name;
+ this.tableName = name;
}
-
+
private void ensureTagCapacity(int index) {
- if (this.tableTags.size() < index + 1) {
- int delta = index + 1 - this.tableTags.size();
- this.tableTags.addAll(Collections.nCopies(delta, null));
- }
+ if (this.tableTags.size() < index + 1) {
+ int delta = index + 1 - this.tableTags.size();
+ this.tableTags.addAll(Collections.nCopies(delta, null));
+ }
}
-
+
public void setTagNull(int index, int type) {
- ensureTagCapacity(index);
- this.tableTags.set(index, TableTagInfo.createNullTag(type));
+ ensureTagCapacity(index);
+ this.tableTags.set(index, TableTagInfo.createNullTag(type));
}
-
+
public void setTagBoolean(int index, boolean value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BOOL));
- this.tagValueLength += Byte.BYTES;
+ ensureTagCapacity(index);
+ this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BOOL));
+ this.tagValueLength += Byte.BYTES;
}
-
+
public void setTagInt(int index, int value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_INT));
- this.tagValueLength += Integer.BYTES;
+ ensureTagCapacity(index);
+ this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_INT));
+ this.tagValueLength += Integer.BYTES;
}
-
+
public void setTagByte(int index, byte value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TINYINT));
- this.tagValueLength += Byte.BYTES;
+ ensureTagCapacity(index);
+ this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TINYINT));
+ this.tagValueLength += Byte.BYTES;
}
-
+
public void setTagShort(int index, short value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_SMALLINT));
- this.tagValueLength += Short.BYTES;
+ ensureTagCapacity(index);
+ this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_SMALLINT));
+ this.tagValueLength += Short.BYTES;
}
-
+
public void setTagLong(int index, long value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BIGINT));
- this.tagValueLength += Long.BYTES;
+ ensureTagCapacity(index);
+ this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BIGINT));
+ this.tagValueLength += Long.BYTES;
}
-
+
public void setTagTimestamp(int index, long value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP));
- this.tagValueLength += Long.BYTES;
+ ensureTagCapacity(index);
+ this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP));
+ this.tagValueLength += Long.BYTES;
}
-
+
public void setTagFloat(int index, float value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_FLOAT));
- this.tagValueLength += Float.BYTES;
+ ensureTagCapacity(index);
+ this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_FLOAT));
+ this.tagValueLength += Float.BYTES;
}
-
+
public void setTagDouble(int index, double value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_DOUBLE));
- this.tagValueLength += Double.BYTES;
+ ensureTagCapacity(index);
+ this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_DOUBLE));
+ this.tagValueLength += Double.BYTES;
}
-
+
public void setTagString(int index, String value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BINARY));
- this.tagValueLength += value.getBytes().length;
+ ensureTagCapacity(index);
+ this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BINARY));
+ this.tagValueLength += value.getBytes().length;
}
-
+
public void setTagNString(int index, String value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_NCHAR));
-
- String charset = TaosGlobalConfig.getCharset();
- try {
- this.tagValueLength += value.getBytes(charset).length;
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- }
-
+ ensureTagCapacity(index);
+ this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_NCHAR));
+
+ String charset = TaosGlobalConfig.getCharset();
+ try {
+ this.tagValueLength += value.getBytes(charset).length;
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ }
+
public void setValueImpl(int columnIndex, ArrayList list, int type, int bytes) throws SQLException {
- if (this.colData.size() == 0) {
- this.colData.addAll(Collections.nCopies(this.parameters.length - 1 - this.tableTags.size(), null));
-
- }
- ColumnInfo col = (ColumnInfo) this.colData.get(columnIndex);
- if (col == null) {
- ColumnInfo p = new ColumnInfo();
- p.setType(type);
- p.bytes = bytes;
- p.data = (ArrayList>) list.clone();
- this.colData.set(columnIndex, p);
- } else {
- if (col.type != type) {
+ if (this.colData.size() == 0) {
+ this.colData.addAll(Collections.nCopies(this.parameters.length - 1 - this.tableTags.size(), null));
+ }
+
+ ColumnInfo col = (ColumnInfo) this.colData.get(columnIndex);
+ if (col == null) {
+ ColumnInfo p = new ColumnInfo();
+ p.setType(type);
+ p.bytes = bytes;
+ p.data = (ArrayList>) list.clone();
+ this.colData.set(columnIndex, p);
+ } else {
+ if (col.type != type) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data type mismatch");
- }
- col.data.addAll(list);
- }
+ }
+ col.data.addAll(list);
+ }
}
-
+
public void setInt(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_INT, Integer.BYTES);
+ setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_INT, Integer.BYTES);
}
-
+
public void setFloat(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_FLOAT, Float.BYTES);
+ setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_FLOAT, Float.BYTES);
}
-
+
public void setTimestamp(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP, Long.BYTES);
+ setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP, Long.BYTES);
}
-
+
public void setLong(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BIGINT, Long.BYTES);
+ setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BIGINT, Long.BYTES);
}
-
+
public void setDouble(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_DOUBLE, Double.BYTES);
+ setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_DOUBLE, Double.BYTES);
}
-
+
public void setBoolean(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BOOL, Byte.BYTES);
+ setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BOOL, Byte.BYTES);
}
-
+
public void setByte(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TINYINT, Byte.BYTES);
+ setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TINYINT, Byte.BYTES);
}
-
+
public void setShort(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_SMALLINT, Short.BYTES);
+ setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_SMALLINT, Short.BYTES);
}
-
+
public void setString(int columnIndex, ArrayList list, int size) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BINARY, size);
+ setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BINARY, size);
}
-
+
// note: expand the required space for each NChar character
public void setNString(int columnIndex, ArrayList list, int size) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_NCHAR, size * Integer.BYTES);
+ setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_NCHAR, size * Integer.BYTES);
}
-
+
public void columnDataAddBatch() throws SQLException {
- // pass the data block to native code
- if (rawSql == null) {
+ // pass the data block to native code
+ if (rawSql == null) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "sql statement not set yet");
- }
-
- // table name is not set yet, abort
- if (this.tableName == null) {
+ }
+
+ // table name is not set yet, abort
+ if (this.tableName == null) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "table name not set yet");
- }
-
- int numOfCols = this.colData.size();
- if (numOfCols == 0) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind");
- }
-
- TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
- this.nativeStmtHandle = connector.prepareStmt(rawSql);
-
- if (this.tableTags == null) {
- connector.setBindTableName(this.nativeStmtHandle, this.tableName);
- } else {
- int num = this.tableTags.size();
- ByteBuffer tagDataList = ByteBuffer.allocate(this.tagValueLength);
- tagDataList.order(ByteOrder.LITTLE_ENDIAN);
-
- ByteBuffer typeList = ByteBuffer.allocate(num);
- typeList.order(ByteOrder.LITTLE_ENDIAN);
-
- ByteBuffer lengthList = ByteBuffer.allocate(num * Long.BYTES);
- lengthList.order(ByteOrder.LITTLE_ENDIAN);
-
- ByteBuffer isNullList = ByteBuffer.allocate(num * Integer.BYTES);
- isNullList.order(ByteOrder.LITTLE_ENDIAN);
-
- for (int i = 0; i < num; ++i) {
- TableTagInfo tag = this.tableTags.get(i);
- if (tag.isNull) {
- typeList.put((byte) tag.type);
- isNullList.putInt(1);
- lengthList.putLong(0);
- continue;
- }
-
- switch (tag.type) {
- case TSDBConstants.TSDB_DATA_TYPE_INT: {
- Integer val = (Integer) tag.value;
- tagDataList.putInt(val);
- lengthList.putLong(Integer.BYTES);
- break;
- }
- case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
- Byte val = (Byte) tag.value;
- tagDataList.put(val);
- lengthList.putLong(Byte.BYTES);
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
- Boolean val = (Boolean) tag.value;
- tagDataList.put((byte) (val ? 1 : 0));
- lengthList.putLong(Byte.BYTES);
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
- Short val = (Short) tag.value;
- tagDataList.putShort(val);
- lengthList.putLong(Short.BYTES);
-
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
- case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
- Long val = (Long) tag.value;
- tagDataList.putLong(val == null ? 0 : val);
- lengthList.putLong(Long.BYTES);
-
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
- Float val = (Float) tag.value;
- tagDataList.putFloat(val == null ? 0 : val);
- lengthList.putLong(Float.BYTES);
-
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
- Double val = (Double) tag.value;
- tagDataList.putDouble(val == null ? 0 : val);
- lengthList.putLong(Double.BYTES);
-
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
- case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
- String charset = TaosGlobalConfig.getCharset();
- String val = (String) tag.value;
-
- byte[] b = null;
- try {
- if (tag.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) {
- b = val.getBytes();
- } else {
- b = val.getBytes(charset);
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
-
- tagDataList.put(b);
- lengthList.putLong(b.length);
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
- case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
- case TSDBConstants.TSDB_DATA_TYPE_UINT:
- case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types");
- }
- }
-
- typeList.put((byte) tag.type);
- isNullList.putInt(tag.isNull? 1 : 0);
- }
-
- connector.setBindTableNameAndTags(this.nativeStmtHandle, this.tableName, this.tableTags.size(), tagDataList,
- typeList, lengthList, isNullList);
- }
-
- ColumnInfo colInfo = (ColumnInfo) this.colData.get(0);
- if (colInfo == null) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind");
- }
-
- int rows = colInfo.data.size();
- for (int i = 0; i < numOfCols; ++i) {
- ColumnInfo col1 = this.colData.get(i);
- if (col1 == null || !col1.isTypeSet()) {
+ }
+
+ int numOfCols = this.colData.size();
+ if (numOfCols == 0) {
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind");
+ }
+
+ TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
+ this.nativeStmtHandle = connector.prepareStmt(rawSql);
+
+ if (this.tableTags == null) {
+ connector.setBindTableName(this.nativeStmtHandle, this.tableName);
+ } else {
+ int num = this.tableTags.size();
+ ByteBuffer tagDataList = ByteBuffer.allocate(this.tagValueLength);
+ tagDataList.order(ByteOrder.LITTLE_ENDIAN);
+
+ ByteBuffer typeList = ByteBuffer.allocate(num);
+ typeList.order(ByteOrder.LITTLE_ENDIAN);
+
+ ByteBuffer lengthList = ByteBuffer.allocate(num * Long.BYTES);
+ lengthList.order(ByteOrder.LITTLE_ENDIAN);
+
+ ByteBuffer isNullList = ByteBuffer.allocate(num * Integer.BYTES);
+ isNullList.order(ByteOrder.LITTLE_ENDIAN);
+
+ for (int i = 0; i < num; ++i) {
+ TableTagInfo tag = this.tableTags.get(i);
+ if (tag.isNull) {
+ typeList.put((byte) tag.type);
+ isNullList.putInt(1);
+ lengthList.putLong(0);
+ continue;
+ }
+
+ switch (tag.type) {
+ case TSDBConstants.TSDB_DATA_TYPE_INT: {
+ Integer val = (Integer) tag.value;
+ tagDataList.putInt(val);
+ lengthList.putLong(Integer.BYTES);
+ break;
+ }
+ case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
+ Byte val = (Byte) tag.value;
+ tagDataList.put(val);
+ lengthList.putLong(Byte.BYTES);
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
+ Boolean val = (Boolean) tag.value;
+ tagDataList.put((byte) (val ? 1 : 0));
+ lengthList.putLong(Byte.BYTES);
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
+ Short val = (Short) tag.value;
+ tagDataList.putShort(val);
+ lengthList.putLong(Short.BYTES);
+
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
+ case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
+ Long val = (Long) tag.value;
+ tagDataList.putLong(val == null ? 0 : val);
+ lengthList.putLong(Long.BYTES);
+
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
+ Float val = (Float) tag.value;
+ tagDataList.putFloat(val == null ? 0 : val);
+ lengthList.putLong(Float.BYTES);
+
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
+ Double val = (Double) tag.value;
+ tagDataList.putDouble(val == null ? 0 : val);
+ lengthList.putLong(Double.BYTES);
+
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
+ case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
+ String charset = TaosGlobalConfig.getCharset();
+ String val = (String) tag.value;
+
+ byte[] b = null;
+ try {
+ if (tag.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) {
+ b = val.getBytes();
+ } else {
+ b = val.getBytes(charset);
+ }
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
+ tagDataList.put(b);
+ lengthList.putLong(b.length);
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
+ case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
+ case TSDBConstants.TSDB_DATA_TYPE_UINT:
+ case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types");
+ }
+ }
+
+ typeList.put((byte) tag.type);
+ isNullList.putInt(tag.isNull ? 1 : 0);
+ }
+
+ connector.setBindTableNameAndTags(this.nativeStmtHandle, this.tableName, this.tableTags.size(), tagDataList,
+ typeList, lengthList, isNullList);
+ }
+
+ ColumnInfo colInfo = (ColumnInfo) this.colData.get(0);
+ if (colInfo == null) {
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind");
+ }
+
+ int rows = colInfo.data.size();
+ for (int i = 0; i < numOfCols; ++i) {
+ ColumnInfo col1 = this.colData.get(i);
+ if (col1 == null || !col1.isTypeSet()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind");
- }
-
- if (rows != col1.data.size()) {
+ }
+
+ if (rows != col1.data.size()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "the rows in column data not identical");
- }
-
- ByteBuffer colDataList = ByteBuffer.allocate(rows * col1.bytes);
- colDataList.order(ByteOrder.LITTLE_ENDIAN);
-
+ }
+
+ ByteBuffer colDataList = ByteBuffer.allocate(rows * col1.bytes);
+ colDataList.order(ByteOrder.LITTLE_ENDIAN);
+
ByteBuffer lengthList = ByteBuffer.allocate(rows * Integer.BYTES);
lengthList.order(ByteOrder.LITTLE_ENDIAN);
-
+
ByteBuffer isNullList = ByteBuffer.allocate(rows * Byte.BYTES);
isNullList.order(ByteOrder.LITTLE_ENDIAN);
-
- switch (col1.type) {
- case TSDBConstants.TSDB_DATA_TYPE_INT: {
- for (int j = 0; j < rows; ++j) {
- Integer val = (Integer) col1.data.get(j);
- colDataList.putInt(val == null? Integer.MIN_VALUE:val);
- isNullList.put((byte) (val == null? 1:0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
- for (int j = 0; j < rows; ++j) {
- Byte val = (Byte) col1.data.get(j);
- colDataList.put(val == null? 0:val);
- isNullList.put((byte) (val == null? 1:0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
- for (int j = 0; j < rows; ++j) {
- Boolean val = (Boolean) col1.data.get(j);
- if (val == null) {
- colDataList.put((byte) 0);
- } else {
- colDataList.put((byte) (val? 1:0));
- }
-
- isNullList.put((byte) (val == null? 1:0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
- for (int j = 0; j < rows; ++j) {
- Short val = (Short) col1.data.get(j);
- colDataList.putShort(val == null? 0:val);
- isNullList.put((byte) (val == null? 1:0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
- case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
- for (int j = 0; j < rows; ++j) {
- Long val = (Long) col1.data.get(j);
- colDataList.putLong(val == null? 0:val);
- isNullList.put((byte) (val == null? 1:0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
- for (int j = 0; j < rows; ++j) {
- Float val = (Float) col1.data.get(j);
- colDataList.putFloat(val == null? 0:val);
- isNullList.put((byte) (val == null? 1:0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
- for (int j = 0; j < rows; ++j) {
- Double val = (Double) col1.data.get(j);
- colDataList.putDouble(val == null? 0:val);
- isNullList.put((byte) (val == null? 1:0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
- case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
- String charset = TaosGlobalConfig.getCharset();
- for (int j = 0; j < rows; ++j) {
- String val = (String) col1.data.get(j);
-
- colDataList.position(j * col1.bytes); // seek to the correct position
- if (val != null) {
- byte[] b = null;
- try {
- if (col1.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) {
- b = val.getBytes();
- } else {
- b = val.getBytes(charset);
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
-
- if (val.length() > col1.bytes) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "string data too long");
- }
-
- colDataList.put(b);
- lengthList.putInt(b.length);
- isNullList.put((byte) 0);
- } else {
- lengthList.putInt(0);
- isNullList.put((byte) 1);
- }
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
- case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
- case TSDBConstants.TSDB_DATA_TYPE_UINT:
- case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types");
- }
- };
-
- connector.bindColumnDataArray(this.nativeStmtHandle, colDataList, lengthList, isNullList, col1.type, col1.bytes, rows, i);
- }
- }
-
- public void columnDataExecuteBatch() throws SQLException {
- TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
- connector.executeBatch(this.nativeStmtHandle);
- this.columnDataClearBatch();
- }
-
+
+ switch (col1.type) {
+ case TSDBConstants.TSDB_DATA_TYPE_INT: {
+ for (int j = 0; j < rows; ++j) {
+ Integer val = (Integer) col1.data.get(j);
+ colDataList.putInt(val == null ? Integer.MIN_VALUE : val);
+ isNullList.put((byte) (val == null ? 1 : 0));
+ }
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
+ for (int j = 0; j < rows; ++j) {
+ Byte val = (Byte) col1.data.get(j);
+ colDataList.put(val == null ? 0 : val);
+ isNullList.put((byte) (val == null ? 1 : 0));
+ }
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
+ for (int j = 0; j < rows; ++j) {
+ Boolean val = (Boolean) col1.data.get(j);
+ if (val == null) {
+ colDataList.put((byte) 0);
+ } else {
+ colDataList.put((byte) (val ? 1 : 0));
+ }
+
+ isNullList.put((byte) (val == null ? 1 : 0));
+ }
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
+ for (int j = 0; j < rows; ++j) {
+ Short val = (Short) col1.data.get(j);
+ colDataList.putShort(val == null ? 0 : val);
+ isNullList.put((byte) (val == null ? 1 : 0));
+ }
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
+ case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
+ for (int j = 0; j < rows; ++j) {
+ Long val = (Long) col1.data.get(j);
+ colDataList.putLong(val == null ? 0 : val);
+ isNullList.put((byte) (val == null ? 1 : 0));
+ }
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
+ for (int j = 0; j < rows; ++j) {
+ Float val = (Float) col1.data.get(j);
+ colDataList.putFloat(val == null ? 0 : val);
+ isNullList.put((byte) (val == null ? 1 : 0));
+ }
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
+ for (int j = 0; j < rows; ++j) {
+ Double val = (Double) col1.data.get(j);
+ colDataList.putDouble(val == null ? 0 : val);
+ isNullList.put((byte) (val == null ? 1 : 0));
+ }
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
+ case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
+ String charset = TaosGlobalConfig.getCharset();
+ for (int j = 0; j < rows; ++j) {
+ String val = (String) col1.data.get(j);
+
+ colDataList.position(j * col1.bytes); // seek to the correct position
+ if (val != null) {
+ byte[] b = null;
+ try {
+ if (col1.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) {
+ b = val.getBytes();
+ } else {
+ b = val.getBytes(charset);
+ }
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
+ if (val.length() > col1.bytes) {
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "string data too long");
+ }
+
+ colDataList.put(b);
+ lengthList.putInt(b.length);
+ isNullList.put((byte) 0);
+ } else {
+ lengthList.putInt(0);
+ isNullList.put((byte) 1);
+ }
+ }
+ break;
+ }
+
+ case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
+ case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
+ case TSDBConstants.TSDB_DATA_TYPE_UINT:
+ case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
+ throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types");
+ }
+ }
+ ;
+
+ connector.bindColumnDataArray(this.nativeStmtHandle, colDataList, lengthList, isNullList, col1.type, col1.bytes, rows, i);
+ }
+ }
+
+ public void columnDataExecuteBatch() throws SQLException {
+ TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
+ connector.executeBatch(this.nativeStmtHandle);
+ this.columnDataClearBatch();
+ }
+
public void columnDataClearBatch() {
- int size = this.colData.size();
- this.colData.clear();
-
+ int size = this.colData.size();
+ this.colData.clear();
+
this.colData.addAll(Collections.nCopies(size, null));
this.tableName = null; // clear the table name
}
-
+
public void columnDataCloseBatch() throws SQLException {
- TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
- connector.closeBatch(this.nativeStmtHandle);
-
- this.nativeStmtHandle = 0L;
- this.tableName = null;
+ TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
+ connector.closeBatch(this.nativeStmtHandle);
+
+ this.nativeStmtHandle = 0L;
+ this.tableName = null;
}
}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
index aba29d602b8900d3bedee49ee94e7d226b3bd1f0..59a64ad520f01c8c7f2b85f95057365e2410ecb6 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
@@ -133,9 +133,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return this.blockData.getString(columnIndex - 1);
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
if (!lastWasNull) {
- res = this.rowData.getString(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ res = this.rowData.getString(columnIndex, nativeType);
}
return res;
}
@@ -147,9 +148,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return this.blockData.getBoolean(columnIndex - 1);
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
if (!lastWasNull) {
- res = this.rowData.getBoolean(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ res = this.rowData.getBoolean(columnIndex, nativeType);
}
return res;
}
@@ -161,9 +163,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return (byte) this.blockData.getInt(columnIndex - 1);
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
if (!lastWasNull) {
- res = (byte) this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ res = (byte) this.rowData.getInt(columnIndex, nativeType);
}
return res;
}
@@ -175,9 +178,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return (short) this.blockData.getInt(columnIndex - 1);
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
if (!lastWasNull) {
- res = (short) this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ res = (short) this.rowData.getInt(columnIndex, nativeType);
}
return res;
}
@@ -189,9 +193,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return this.blockData.getInt(columnIndex - 1);
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
+
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
if (!lastWasNull) {
- res = this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ res = this.rowData.getInt(columnIndex, nativeType);
}
return res;
}
@@ -203,13 +209,15 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return this.blockData.getLong(columnIndex - 1);
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
if (!lastWasNull) {
- Object value = this.rowData.get(columnIndex - 1);
- if (value instanceof Timestamp)
+ Object value = this.rowData.getObject(columnIndex);
+ if (value instanceof Timestamp) {
res = ((Timestamp) value).getTime();
- else
- res = this.rowData.getLong(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
+ } else {
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ res = this.rowData.getLong(columnIndex, nativeType);
+ }
}
return res;
}
@@ -221,9 +229,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return (float) this.blockData.getDouble(columnIndex - 1);
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
- if (!lastWasNull)
- res = this.rowData.getFloat(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
+ if (!lastWasNull) {
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ res = this.rowData.getFloat(columnIndex, nativeType);
+ }
return res;
}
@@ -235,9 +245,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return this.blockData.getDouble(columnIndex - 1);
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
if (!lastWasNull) {
- res = this.rowData.getDouble(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType());
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ res = this.rowData.getDouble(columnIndex, nativeType);
}
return res;
}
@@ -245,34 +256,27 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
public byte[] getBytes(int columnIndex) throws SQLException {
checkAvailability(columnIndex, this.columnMetaDataList.size());
- Object value = this.rowData.get(columnIndex - 1);
+ Object value = this.rowData.getObject(columnIndex);
if (value == null)
return null;
- int colType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- switch (colType) {
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ switch (nativeType) {
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
- return Longs.toByteArray((Long) value);
+ return Longs.toByteArray((long) value);
case TSDBConstants.TSDB_DATA_TYPE_INT:
return Ints.toByteArray((int) value);
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
- return Shorts.toByteArray((Short) value);
+ return Shorts.toByteArray((short) value);
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
return new byte[]{(byte) value};
+ case TSDBConstants.TSDB_DATA_TYPE_BINARY:
+ return (byte[]) value;
+ case TSDBConstants.TSDB_DATA_TYPE_BOOL:
+ case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
+ default:
+ return value.toString().getBytes();
}
- return value.toString().getBytes();
- }
-
- @Override
- public Date getDate(int columnIndex) throws SQLException {
- Timestamp timestamp = getTimestamp(columnIndex);
- return timestamp == null ? null : new Date(timestamp.getTime());
- }
-
- @Override
- public Time getTime(int columnIndex) throws SQLException {
- Timestamp timestamp = getTimestamp(columnIndex);
- return timestamp == null ? null : new Time(timestamp.getTime());
}
public Timestamp getTimestamp(int columnIndex) throws SQLException {
@@ -282,9 +286,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return this.blockData.getTimestamp(columnIndex - 1);
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
if (!lastWasNull) {
- res = this.rowData.getTimestamp(columnIndex - 1);
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ res = this.rowData.getTimestamp(columnIndex, nativeType);
}
return res;
}
@@ -304,13 +309,9 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return this.blockData.get(columnIndex - 1);
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
if (!lastWasNull) {
- int colType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- if (colType == TSDBConstants.TSDB_DATA_TYPE_BINARY)
- res = ((String) this.rowData.get(columnIndex - 1)).getBytes();
- else
- res = this.rowData.get(columnIndex - 1);
+ res = this.rowData.getObject(columnIndex);
}
return res;
}
@@ -318,7 +319,7 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
public int findColumn(String columnLabel) throws SQLException {
for (ColumnMetaData colMetaData : this.columnMetaDataList) {
if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) {
- return colMetaData.getColIndex() + 1;
+ return colMetaData.getColIndex();
}
}
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
@@ -329,25 +330,25 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if (this.getBatchFetch())
return new BigDecimal(this.blockData.getLong(columnIndex - 1));
- this.lastWasNull = this.rowData.wasNull(columnIndex - 1);
+ this.lastWasNull = this.rowData.wasNull(columnIndex);
BigDecimal res = null;
if (!lastWasNull) {
- int colType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- switch (colType) {
+ int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
+ switch (nativeType) {
case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
case TSDBConstants.TSDB_DATA_TYPE_INT:
case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
- res = new BigDecimal(Long.valueOf(this.rowData.get(columnIndex - 1).toString()));
+ res = new BigDecimal(Long.valueOf(this.rowData.getObject(columnIndex).toString()));
break;
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
- res = new BigDecimal(Double.valueOf(this.rowData.get(columnIndex - 1).toString()));
+ res = new BigDecimal(Double.valueOf(this.rowData.getObject(columnIndex).toString()));
break;
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
- return new BigDecimal(((Timestamp) this.rowData.get(columnIndex - 1)).getTime());
+ return new BigDecimal(((Timestamp) this.rowData.getObject(columnIndex)).getTime());
default:
- res = new BigDecimal(this.rowData.get(columnIndex - 1).toString());
+ res = new BigDecimal(this.rowData.getObject(columnIndex).toString());
}
}
return res;
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java
index e4ac5303d09f132279e29039bf6b5b812b6c5404..48d42473926b638401cf5d9dd97466695ba452ab 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java
@@ -113,6 +113,7 @@ public class TSDBResultSetMetaData extends WrapperImpl implements ResultSetMetaD
ColumnMetaData columnMetaData = this.colMetaDataList.get(column - 1);
switch (columnMetaData.getColType()) {
+
case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
return 5;
case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java
index 618e896a6ddfe43d63f631b663a356f485575b06..01104440ab00c974aa021f10b4168c3f1332e91a 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java
@@ -14,6 +14,8 @@
*****************************************************************************/
package com.taosdata.jdbc;
+import com.taosdata.jdbc.utils.NullType;
+
import java.math.BigDecimal;
import java.sql.SQLException;
import java.sql.Timestamp;
@@ -22,11 +24,13 @@ import java.util.ArrayList;
import java.util.Collections;
public class TSDBResultSetRowData {
+
private ArrayList