提交 bab798f4 编写于 作者: H Haojun Liao

[td-225] merge develop

CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
IF (CMAKE_VERSION VERSION_LESS 3.0) IF (CMAKE_VERSION VERSION_LESS 3.0)
PROJECT(TDengine CXX) PROJECT(TDengine CXX)
SET(PROJECT_VERSION_MAJOR "${LIB_MAJOR_VERSION}") SET(PROJECT_VERSION_MAJOR "${LIB_MAJOR_VERSION}")
......
...@@ -5,7 +5,7 @@ node { ...@@ -5,7 +5,7 @@ node {
git url: 'https://github.com/taosdata/TDengine.git' git url: 'https://github.com/taosdata/TDengine.git'
} }
def kipstage=0
def abortPreviousBuilds() { def abortPreviousBuilds() {
def currentJobName = env.JOB_NAME def currentJobName = env.JOB_NAME
def currentBuildNumber = env.BUILD_NUMBER.toInteger() def currentBuildNumber = env.BUILD_NUMBER.toInteger()
...@@ -45,7 +45,7 @@ def pre_test(){ ...@@ -45,7 +45,7 @@ def pre_test(){
git pull git pull
git fetch origin +refs/pull/${CHANGE_ID}/merge git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD git checkout -qf FETCH_HEAD
git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD develop)|grep -v -E '.*md|.*src/connector|Jenkinsfile' || exit 0 git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD develop)|grep -v -E '.*md|//src//connector|Jenkinsfile' || exit 0
cd ${WK} cd ${WK}
git reset --hard HEAD~10 git reset --hard HEAD~10
git checkout develop git checkout develop
...@@ -63,6 +63,7 @@ def pre_test(){ ...@@ -63,6 +63,7 @@ def pre_test(){
''' '''
return 1 return 1
} }
pipeline { pipeline {
agent none agent none
...@@ -72,12 +73,36 @@ pipeline { ...@@ -72,12 +73,36 @@ pipeline {
} }
stages { stages {
stage('pre_build'){
agent{label 'master'}
when {
changeRequest()
}
steps {
sh'''
cp -r ${WORKSPACE} ${WORKSPACE}.tes
cd ${WORKSPACE}.tes
git checkout develop
git pull
git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD
'''
script{
skipstage=sh(script:"git --no-pager diff --name-only FETCH_HEAD develop|grep -v -E '.*md|//src//connector|Jenkinsfile|test-all.sh' || echo 0 ",returnStdout:true)
}
sh'''
rm -rf ${WORKSPACE}.tes
'''
}
}
stage('Parallel test stage') { stage('Parallel test stage') {
//only build pr //only build pr
when { when {
changeRequest() changeRequest()
expression {
skipstage != 0
}
} }
parallel { parallel {
stage('python_1_s1') { stage('python_1_s1') {
...@@ -102,12 +127,12 @@ pipeline { ...@@ -102,12 +127,12 @@ pipeline {
pre_test() pre_test()
timeout(time: 45, unit: 'MINUTES'){ timeout(time: 45, unit: 'MINUTES'){
sh ''' sh '''
date date
cd ${WKC}/tests cd ${WKC}/tests
find pytest -name '*'sql|xargs rm -rf find pytest -name '*'sql|xargs rm -rf
./test-all.sh p2 ./test-all.sh p2
date''' date'''
} }
} }
} }
...@@ -127,7 +152,7 @@ pipeline { ...@@ -127,7 +152,7 @@ pipeline {
stage('test_b1_s2') { stage('test_b1_s2') {
agent{label 'b1'} agent{label 'b1'}
steps { steps {
timeout(time: 90, unit: 'MINUTES'){ timeout(time: 45, unit: 'MINUTES'){
pre_test() pre_test()
sh ''' sh '''
cd ${WKC}/tests cd ${WKC}/tests
...@@ -139,6 +164,7 @@ pipeline { ...@@ -139,6 +164,7 @@ pipeline {
stage('test_crash_gen_s3') { stage('test_crash_gen_s3') {
agent{label "b2"} agent{label "b2"}
steps { steps {
pre_test() pre_test()
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
...@@ -150,17 +176,20 @@ pipeline { ...@@ -150,17 +176,20 @@ pipeline {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh ''' sh '''
cd ${WKC}/tests/pytest cd ${WKC}/tests/pytest
rm -rf /var/lib/taos/*
rm -rf /var/log/taos/*
./handle_crash_gen_val_log.sh ./handle_crash_gen_val_log.sh
''' '''
} }
timeout(time: 45, unit: 'MINUTES'){ timeout(time: 45, unit: 'MINUTES'){
sh ''' sh '''
date date
cd ${WKC}/tests cd ${WKC}/tests
./test-all.sh b2fq ./test-all.sh b2fq
date date
''' '''
} }
} }
} }
...@@ -194,6 +223,8 @@ pipeline { ...@@ -194,6 +223,8 @@ pipeline {
date date
cd ${WKC}/tests cd ${WKC}/tests
./test-all.sh b4fq ./test-all.sh b4fq
cd ${WKC}/tests
./test-all.sh p4
date''' date'''
} }
} }
...@@ -240,12 +271,11 @@ pipeline { ...@@ -240,12 +271,11 @@ pipeline {
} }
} }
} }
post { post {
success { success {
emailext ( emailext (
subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' SUCCESS",
body: '''<!DOCTYPE html> body: """<!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
...@@ -261,29 +291,29 @@ pipeline { ...@@ -261,29 +291,29 @@ pipeline {
<td> <td>
<ul> <ul>
<div style="font-size:18px"> <div style="font-size:18px">
<li>构建名称>>分支:${PROJECT_NAME}</li> <li>构建名称>>分支:${env.BRANCH_NAME}</li>
<li>构建结果:<span style="color:green"> Successful </span></li> <li>构建结果:<span style="color:green"> Successful </span></li>
<li>构建编号:${BUILD_NUMBER}</li> <li>构建编号:${BUILD_NUMBER}</li>
<li>触发用户:${CAUSE}</li> <li>触发用户:${env.CHANGE_AUTHOR}</li>
<li>提交信息:${CHANGE_TITLE}</li> <li>提交信息:${env.CHANGE_TITLE}</li>
<li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li> <li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
<li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li> <li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
<li>变更集:${JELLY_SCRIPT}</li>
</div> </div>
</ul> </ul>
</td> </td>
</tr> </tr>
</table></font> </table></font>
</body> </body>
</html>''', </html>""",
to: "${env.CHANGE_AUTHOR_EMAIL}", to: "${env.CHANGE_AUTHOR_EMAIL}",
from: "support@taosdata.com" from: "support@taosdata.com"
) )
} }
failure { failure {
emailext ( emailext (
subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", subject: "PR-result: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' FAIL",
body: '''<!DOCTYPE html> body: """<!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
...@@ -299,21 +329,21 @@ pipeline { ...@@ -299,21 +329,21 @@ pipeline {
<td> <td>
<ul> <ul>
<div style="font-size:18px"> <div style="font-size:18px">
<li>构建名称>>分支:${PROJECT_NAME}</li> <li>构建名称>>分支:${env.BRANCH_NAME}</li>
<li>构建结果:<span style="color:green"> Successful </span></li> <li>构建结果:<span style="color:red"> Failure </span></li>
<li>构建编号:${BUILD_NUMBER}</li> <li>构建编号:${BUILD_NUMBER}</li>
<li>触发用户:${CAUSE}</li> <li>触发用户:${env.CHANGE_AUTHOR}</li>
<li>提交信息:${CHANGE_TITLE}</li> <li>提交信息:${env.CHANGE_TITLE}</li>
<li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li> <li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
<li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li> <li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
<li>变更集:${JELLY_SCRIPT}</li>
</div> </div>
</ul> </ul>
</td> </td>
</tr> </tr>
</table></font> </table></font>
</body> </body>
</html>''', </html>""",
to: "${env.CHANGE_AUTHOR_EMAIL}", to: "${env.CHANGE_AUTHOR_EMAIL}",
from: "support@taosdata.com" from: "support@taosdata.com"
) )
......
...@@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS) ...@@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
#INSTALL(TARGETS taos RUNTIME DESTINATION driver) #INSTALL(TARGETS taos RUNTIME DESTINATION driver)
#INSTALL(TARGETS shell RUNTIME DESTINATION .) #INSTALL(TARGETS shell RUNTIME DESTINATION .)
IF (TD_MVN_INSTALLED) IF (TD_MVN_INSTALLED)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.18-dist.jar DESTINATION connector/jdbc) INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.19-dist.jar DESTINATION connector/jdbc)
ENDIF () ENDIF ()
ELSEIF (TD_DARWIN) ELSEIF (TD_DARWIN)
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh") SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
......
...@@ -13,28 +13,40 @@ ELSE () ...@@ -13,28 +13,40 @@ ELSE ()
SET(TD_VER_COMPATIBLE "2.0.0.0") SET(TD_VER_COMPATIBLE "2.0.0.0")
ENDIF () ENDIF ()
find_program(HAVE_GIT NAMES git)
IF (DEFINED GITINFO) IF (DEFINED GITINFO)
SET(TD_VER_GIT ${GITINFO}) SET(TD_VER_GIT ${GITINFO})
ELSEIF (HAVE_GIT)
execute_process(COMMAND git log -1 --format=%H WORKING_DIRECTORY ${TD_COMMUNITY_DIR} OUTPUT_VARIABLE GIT_COMMITID)
message(STATUS "git log result:${GIT_COMMITID}")
IF (GIT_COMMITID)
string (REGEX REPLACE "[\n\t\r]" "" GIT_COMMITID ${GIT_COMMITID})
SET(TD_VER_GIT ${GIT_COMMITID})
ELSE ()
message(STATUS "not a git repository")
SET(TD_VER_GIT "no git commit id")
ENDIF ()
ELSE () ELSE ()
execute_process( message(STATUS "no git cmd")
COMMAND git log -1 --format=%H SET(TD_VER_GIT "no git commit id")
WORKING_DIRECTORY ${TD_COMMUNITY_DIR}
OUTPUT_VARIABLE GIT_COMMITID
)
string (REGEX REPLACE "[\n\t\r]" "" GIT_COMMITID ${GIT_COMMITID})
SET(TD_VER_GIT ${GIT_COMMITID})
ENDIF () ENDIF ()
IF (DEFINED GITINFOI) IF (DEFINED GITINFOI)
SET(TD_VER_GIT_INTERNAL ${GITINFOI}) SET(TD_VER_GIT_INTERNAL ${GITINFOI})
ELSEIF (HAVE_GIT)
execute_process(COMMAND git log -1 --format=%H WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE GIT_COMMITID)
message(STATUS "git log result:${GIT_COMMITID}")
IF (GIT_COMMITID)
string (REGEX REPLACE "[\n\t\r]" "" GIT_COMMITID ${GIT_COMMITID})
SET(TD_VER_GIT_INTERNAL ${GIT_COMMITID})
ELSE ()
message(STATUS "not a git repository")
SET(TD_VER_GIT "no git commit id")
ENDIF ()
ELSE () ELSE ()
execute_process( message(STATUS "no git cmd")
COMMAND git log -1 --format=%H SET(TD_VER_GIT_INTERNAL "no git commit id")
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMITID
)
string (REGEX REPLACE "[\n\t\r]" "" GIT_COMMITID ${GIT_COMMITID})
SET(TD_VER_GIT_INTERNAL ${GIT_COMMITID})
ENDIF () ENDIF ()
IF (DEFINED VERDATE) IF (DEFINED VERDATE)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
ADD_SUBDIRECTORY(zlib-1.2.11) ADD_SUBDIRECTORY(zlib-1.2.11)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
# MQTT-C build options # MQTT-C build options
option(MQTT_C_OpenSSL_SUPPORT "Build MQTT-C with OpenSSL support?" OFF) option(MQTT_C_OpenSSL_SUPPORT "Build MQTT-C with OpenSSL support?" OFF)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_WINDOWS) IF (TD_WINDOWS)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_WINDOWS) IF (TD_WINDOWS)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_WINDOWS) IF (TD_WINDOWS)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_WINDOWS) IF (TD_WINDOWS)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_WINDOWS) IF (TD_WINDOWS)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_WINDOWS) IF (TD_WINDOWS)
......
...@@ -290,7 +290,7 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic ...@@ -290,7 +290,7 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
- **修改子表标签值** - **修改子表标签值**
```mysql ```mysql
ALTER STABLE tb_name SET TAG tag_name=new_tag_value; ALTER TABLE tb_name SET TAG tag_name=new_tag_value;
``` ```
说明:除了更新标签的值的操作是针对子表进行,其他所有的标签操作(添加标签、删除标签等)均只能作用于 STable,不能对单个子表操作。对 STable 添加标签以后,依托于该 STable 建立的所有表将自动增加了一个标签,所有新增标签的默认值都是 NULL。 说明:除了更新标签的值的操作是针对子表进行,其他所有的标签操作(添加标签、删除标签等)均只能作用于 STable,不能对单个子表操作。对 STable 添加标签以后,依托于该 STable 建立的所有表将自动增加了一个标签,所有新增标签的默认值都是 NULL。
...@@ -757,7 +757,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数 ...@@ -757,7 +757,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。 应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
适用于:表。(从 2.0.15 版本开始,本函数也支持超级表) 适用于:表。(从 2.0.15.1 版本开始,本函数也支持超级表)
示例: 示例:
```mysql ```mysql
......
...@@ -147,8 +147,8 @@ done ...@@ -147,8 +147,8 @@ done
#echo "verType=${verType} interactiveFqdn=${interactiveFqdn}" #echo "verType=${verType} interactiveFqdn=${interactiveFqdn}"
function kill_taosd() { function kill_process() {
pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}')
if [ -n "$pid" ]; then if [ -n "$pid" ]; then
${csudo} kill -9 $pid || : ${csudo} kill -9 $pid || :
fi fi
...@@ -168,7 +168,10 @@ function install_main_path() { ...@@ -168,7 +168,10 @@ function install_main_path() {
if [ "$verMode" == "cluster" ]; then if [ "$verMode" == "cluster" ]; then
${csudo} mkdir -p ${nginx_dir} ${csudo} mkdir -p ${nginx_dir}
fi fi
${csudo} cp ${script_dir}/email ${install_main_dir}/ ||:
if [[ -e ${script_dir}/email ]]; then
${csudo} cp ${script_dir}/email ${install_main_dir}/ ||:
fi
} }
function install_bin() { function install_bin() {
...@@ -680,7 +683,7 @@ function install_service() { ...@@ -680,7 +683,7 @@ function install_service() {
install_service_on_sysvinit install_service_on_sysvinit
else else
# must manual stop taosd # must manual stop taosd
kill_taosd kill_process taosd
fi fi
} }
...@@ -749,9 +752,22 @@ function update_TDengine() { ...@@ -749,9 +752,22 @@ function update_TDengine() {
elif ((${service_mod}==1)); then elif ((${service_mod}==1)); then
${csudo} service taosd stop || : ${csudo} service taosd stop || :
else else
kill_taosd kill_process taosd
fi
sleep 1
fi
if [ "$verMode" == "cluster" ]; then
if pidof nginx &> /dev/null; then
if ((${service_mod}==0)); then
${csudo} systemctl stop nginxd || :
elif ((${service_mod}==1)); then
${csudo} service nginxd stop || :
else
kill_process nginx
fi fi
sleep 1 sleep 1
fi
fi fi
install_main_path install_main_path
......
...@@ -146,8 +146,8 @@ done ...@@ -146,8 +146,8 @@ done
#echo "verType=${verType} interactiveFqdn=${interactiveFqdn}" #echo "verType=${verType} interactiveFqdn=${interactiveFqdn}"
function kill_powerd() { function kill_process() {
pid=$(ps -ef | grep "powerd" | grep -v "grep" | awk '{print $2}') pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}')
if [ -n "$pid" ]; then if [ -n "$pid" ]; then
${csudo} kill -9 $pid || : ${csudo} kill -9 $pid || :
fi fi
...@@ -652,7 +652,7 @@ function install_service() { ...@@ -652,7 +652,7 @@ function install_service() {
install_service_on_sysvinit install_service_on_sysvinit
else else
# must manual stop powerd # must manual stop powerd
kill_powerd kill_process powerd
fi fi
} }
...@@ -721,9 +721,21 @@ function update_PowerDB() { ...@@ -721,9 +721,21 @@ function update_PowerDB() {
elif ((${service_mod}==1)); then elif ((${service_mod}==1)); then
${csudo} service powerd stop || : ${csudo} service powerd stop || :
else else
kill_powerd kill_process powerd
fi fi
sleep 1 sleep 1
fi
if [ "$verMode" == "cluster" ]; then
if pidof nginx &> /dev/null; then
if ((${service_mod}==0)); then
${csudo} systemctl stop nginxd || :
elif ((${service_mod}==1)); then
${csudo} service nginxd stop || :
else
kill_process nginx
fi
sleep 1
fi
fi fi
install_main_path install_main_path
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
# Base compile # Base compile
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/inc)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(inc)
......
...@@ -273,7 +273,8 @@ void tscQueueAsyncError(void(*fp), void *param, int32_t code) { ...@@ -273,7 +273,8 @@ void tscQueueAsyncError(void(*fp), void *param, int32_t code) {
taosScheduleTask(tscQhandle, &schedMsg); taosScheduleTask(tscQhandle, &schedMsg);
} }
void tscAsyncResultOnError(SSqlObj *pSql) { static void tscAsyncResultCallback(SSchedMsg *pMsg) {
SSqlObj* pSql = pMsg->ahandle;
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
tscDebug("%p SqlObj is freed, not add into queue async res", pSql); tscDebug("%p SqlObj is freed, not add into queue async res", pSql);
return; return;
...@@ -291,6 +292,16 @@ void tscAsyncResultOnError(SSqlObj *pSql) { ...@@ -291,6 +292,16 @@ void tscAsyncResultOnError(SSqlObj *pSql) {
(*pSql->fp)(pSql->param, pSql, pRes->code); (*pSql->fp)(pSql->param, pSql, pRes->code);
} }
void tscAsyncResultOnError(SSqlObj* pSql) {
SSchedMsg schedMsg = {0};
schedMsg.fp = tscAsyncResultCallback;
schedMsg.ahandle = pSql;
schedMsg.thandle = (void *)1;
schedMsg.msg = 0;
taosScheduleTask(tscQhandle, &schedMsg);
}
int tscSendMsgToServer(SSqlObj *pSql); int tscSendMsgToServer(SSqlObj *pSql);
void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
......
...@@ -892,7 +892,12 @@ int tscProcessLocalCmd(SSqlObj *pSql) { ...@@ -892,7 +892,12 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
SSqlRes *pRes = &pSql->res; SSqlRes *pRes = &pSql->res;
if (pCmd->command == TSDB_SQL_CFG_LOCAL) { if (pCmd->command == TSDB_SQL_CFG_LOCAL) {
pRes->code = (uint8_t)taosCfgDynamicOptions(pCmd->payload); if (taosCfgDynamicOptions(pCmd->payload)) {
pRes->code = TSDB_CODE_SUCCESS;
} else {
pRes->code = TSDB_CODE_COM_INVALID_CFG_MSG;
}
pRes->numOfRows = 0;
} else if (pCmd->command == TSDB_SQL_DESCRIBE_TABLE) { } else if (pCmd->command == TSDB_SQL_DESCRIBE_TABLE) {
pRes->code = (uint8_t)tscProcessDescribeTable(pSql); pRes->code = (uint8_t)tscProcessDescribeTable(pSql);
} else if (pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) { } else if (pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) {
......
...@@ -233,6 +233,7 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { ...@@ -233,6 +233,7 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
// We extract the lock to tscBuildHeartBeatMsg function. // We extract the lock to tscBuildHeartBeatMsg function.
int64_t now = taosGetTimestampMs();
SSqlObj *pSql = pObj->sqlList; SSqlObj *pSql = pObj->sqlList;
while (pSql) { while (pSql) {
/* /*
...@@ -247,7 +248,8 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { ...@@ -247,7 +248,8 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
tstrncpy(pQdesc->sql, pSql->sqlstr, sizeof(pQdesc->sql)); tstrncpy(pQdesc->sql, pSql->sqlstr, sizeof(pQdesc->sql));
pQdesc->stime = htobe64(pSql->stime); pQdesc->stime = htobe64(pSql->stime);
pQdesc->queryId = htonl(pSql->queryId); pQdesc->queryId = htonl(pSql->queryId);
pQdesc->useconds = htobe64(pSql->res.useconds); //pQdesc->useconds = htobe64(pSql->res.useconds);
pQdesc->useconds = htobe64(now - pSql->stime);
pQdesc->qHandle = htobe64(pSql->res.qhandle); pQdesc->qHandle = htobe64(pSql->res.qhandle);
pHeartbeat->numOfQueries++; pHeartbeat->numOfQueries++;
......
...@@ -129,6 +129,7 @@ static int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo); ...@@ -129,6 +129,7 @@ static int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo);
static int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo); static int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo);
static int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index); static int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index);
static int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pSqlExpr, SQueryInfo* pQueryInfo, SArray* pCols, int64_t *uid); static int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pSqlExpr, SQueryInfo* pQueryInfo, SArray* pCols, int64_t *uid);
static bool validateDebugFlag(int32_t flag);
int16_t getNewResColId(SQueryInfo* pQueryInfo) { int16_t getNewResColId(SQueryInfo* pQueryInfo) {
return pQueryInfo->resColumnId--; return pQueryInfo->resColumnId--;
...@@ -173,6 +174,16 @@ static uint8_t convertOptr(SStrToken *pToken) { ...@@ -173,6 +174,16 @@ static uint8_t convertOptr(SStrToken *pToken) {
} }
} }
static bool validateDebugFlag(int32_t v) {
const static int validFlag[] = {131, 135, 143};
for (int i = 0; i < tListLen(validFlag); i++) {
if (v == validFlag[i]) {
return true;
}
}
return false;
}
/* /*
* Used during parsing query sql. Since the query sql usually small in length, error position * Used during parsing query sql. Since the query sql usually small in length, error position
* is not needed in the final error message. * is not needed in the final error message.
...@@ -565,16 +576,16 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -565,16 +576,16 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
int32_t numOfToken = (int32_t) taosArrayGetSize(pMiscInfo->a); int32_t numOfToken = (int32_t) taosArrayGetSize(pMiscInfo->a);
SStrToken* t = taosArrayGet(pMiscInfo->a, 0); assert(numOfToken >= 1 && numOfToken <= 2);
SStrToken* t1 = taosArrayGet(pMiscInfo->a, 1);
SStrToken* t = taosArrayGet(pMiscInfo->a, 0);
strncpy(pCmd->payload, t->z, t->n); strncpy(pCmd->payload, t->z, t->n);
if (numOfToken == 2) { if (numOfToken == 2) {
SStrToken* t1 = taosArrayGet(pMiscInfo->a, 1);
pCmd->payload[t->n] = ' '; // add sep pCmd->payload[t->n] = ' '; // add sep
strncpy(&pCmd->payload[t->n + 1], t1->z, t1->n); strncpy(&pCmd->payload[t->n + 1], t1->z, t1->n);
} }
return TSDB_CODE_SUCCESS;
break;
} }
case TSDB_SQL_CREATE_TABLE: { case TSDB_SQL_CREATE_TABLE: {
...@@ -5356,13 +5367,15 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) { ...@@ -5356,13 +5367,15 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) {
SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12}, SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12},
{"cDebugFlag", 10}, {"uDebugFlag", 10}, {"debugFlag", 9}}; {"cDebugFlag", 10}, {"uDebugFlag", 10}, {"debugFlag", 9}};
SStrToken* pOptionToken = taosArrayGet(pOptions->a, 0); SStrToken* pOptionToken = taosArrayGet(pOptions->a, 0);
if (numOfToken == 1) { if (numOfToken == 1) {
// reset log does not need value // reset log does not need value
for (int32_t i = 0; i < 1; ++i) { for (int32_t i = 0; i < 1; ++i) {
SDNodeDynConfOption* pOption = &LOCAL_DYNAMIC_CFG_OPTIONS[i]; SDNodeDynConfOption* pOption = &LOCAL_DYNAMIC_CFG_OPTIONS[i];
if ((strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0) && (pOption->len == pOptionToken->n)) { if ((pOption->len == pOptionToken->n) &&
(strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0)) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
} }
...@@ -5370,15 +5383,14 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) { ...@@ -5370,15 +5383,14 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) {
SStrToken* pValToken = taosArrayGet(pOptions->a, 1); SStrToken* pValToken = taosArrayGet(pOptions->a, 1);
int32_t val = strtol(pValToken->z, NULL, 10); int32_t val = strtol(pValToken->z, NULL, 10);
if (val < 131 || val > 199) { if (!validateDebugFlag(val)) {
// options value is out of valid range
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
for (int32_t i = 1; i < tListLen(LOCAL_DYNAMIC_CFG_OPTIONS); ++i) { for (int32_t i = 1; i < tListLen(LOCAL_DYNAMIC_CFG_OPTIONS); ++i) {
SDNodeDynConfOption* pOption = &LOCAL_DYNAMIC_CFG_OPTIONS[i]; SDNodeDynConfOption* pOption = &LOCAL_DYNAMIC_CFG_OPTIONS[i];
if ((strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0) && (pOption->len == pOptionToken->n)) { if ((pOption->len == pOptionToken->n)
// options is valid && (strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0)) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
} }
......
...@@ -609,7 +609,7 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql, int32_t clauseIndex) { ...@@ -609,7 +609,7 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql, int32_t clauseIndex) {
} }
return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + exprSize + tsBufSize + return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + exprSize + tsBufSize +
tableSerialize + sqlLen + 4096; tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen;
} }
static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char *pMsg) { static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char *pMsg) {
......
...@@ -95,11 +95,21 @@ static bool subAndCheckDone(SSqlObj *pSql, SSqlObj *pParentSql, int idx) { ...@@ -95,11 +95,21 @@ static bool subAndCheckDone(SSqlObj *pSql, SSqlObj *pParentSql, int idx) {
pthread_mutex_lock(&subState->mutex); pthread_mutex_lock(&subState->mutex);
bool done = allSubqueryDone(pParentSql);
if (done) {
tscDebug("%p subquery:%p,%d all subs already done", pParentSql, pSql, idx);
pthread_mutex_unlock(&subState->mutex);
return false;
}
tscDebug("%p subquery:%p,%d state set to 1", pParentSql, pSql, idx); tscDebug("%p subquery:%p,%d state set to 1", pParentSql, pSql, idx);
subState->states[idx] = 1; subState->states[idx] = 1;
bool done = allSubqueryDone(pParentSql); done = allSubqueryDone(pParentSql);
pthread_mutex_unlock(&subState->mutex); pthread_mutex_unlock(&subState->mutex);
...@@ -2299,7 +2309,9 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES ...@@ -2299,7 +2309,9 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES
* current query failed, and the retry count is less than the available * current query failed, and the retry count is less than the available
* count, retry query clear previous retrieved data, then launch a new sub query * count, retry query clear previous retrieved data, then launch a new sub query
*/ */
static int32_t tscReissueSubquery(SRetrieveSupport *oriTrs, SSqlObj *pSql, int32_t code) { static int32_t tscReissueSubquery(SRetrieveSupport *oriTrs, SSqlObj *pSql, int32_t code, int32_t *sent) {
*sent = 0;
SRetrieveSupport *trsupport = malloc(sizeof(SRetrieveSupport)); SRetrieveSupport *trsupport = malloc(sizeof(SRetrieveSupport));
if (trsupport == NULL) { if (trsupport == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
...@@ -2331,21 +2343,28 @@ static int32_t tscReissueSubquery(SRetrieveSupport *oriTrs, SSqlObj *pSql, int32 ...@@ -2331,21 +2343,28 @@ static int32_t tscReissueSubquery(SRetrieveSupport *oriTrs, SSqlObj *pSql, int32
SSqlObj *pNew = tscCreateSTableSubquery(trsupport->pParentSql, trsupport, pSql); SSqlObj *pNew = tscCreateSTableSubquery(trsupport->pParentSql, trsupport, pSql);
if (pNew == NULL) { if (pNew == NULL) {
tscError("%p sub:%p failed to create new subquery due to error:%s, abort retry, vgId:%d, orderOfSub:%d", tscError("%p sub:%p failed to create new subquery due to error:%s, abort retry, vgId:%d, orderOfSub:%d",
trsupport->pParentSql, pSql, tstrerror(terrno), pVgroup->vgId, trsupport->subqueryIndex); oriTrs->pParentSql, pSql, tstrerror(terrno), pVgroup->vgId, oriTrs->subqueryIndex);
pParentSql->res.code = terrno; pParentSql->res.code = terrno;
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; oriTrs->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY;
tfree(trsupport);
return pParentSql->res.code; return pParentSql->res.code;
} }
int32_t ret = tscProcessSql(pNew); int32_t ret = tscProcessSql(pNew);
*sent = 1;
// if failed to process sql, let following code handle the pSql // if failed to process sql, let following code handle the pSql
if (ret == TSDB_CODE_SUCCESS) { if (ret == TSDB_CODE_SUCCESS) {
tscFreeRetrieveSup(pSql);
taos_free_result(pSql); taos_free_result(pSql);
return ret; return ret;
} else { } else {
pSql->pSubs[trsupport->subqueryIndex] = pSql;
tscFreeRetrieveSup(pNew);
taos_free_result(pNew);
return ret; return ret;
} }
} }
...@@ -2382,7 +2401,10 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO ...@@ -2382,7 +2401,10 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
subqueryIndex, tstrerror(pParentSql->res.code)); subqueryIndex, tstrerror(pParentSql->res.code));
} else { } else {
if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && pParentSql->res.code == TSDB_CODE_SUCCESS) { if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && pParentSql->res.code == TSDB_CODE_SUCCESS) {
if (tscReissueSubquery(trsupport, pSql, numOfRows) == TSDB_CODE_SUCCESS) { int32_t sent = 0;
tscReissueSubquery(trsupport, pSql, numOfRows, &sent);
if (sent) {
return; return;
} }
} else { // reach the maximum retry count, abort } else { // reach the maximum retry count, abort
...@@ -2504,7 +2526,6 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR ...@@ -2504,7 +2526,6 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
SRetrieveSupport *trsupport = (SRetrieveSupport *)param; SRetrieveSupport *trsupport = (SRetrieveSupport *)param;
if (pSql->param == NULL || param == NULL) { if (pSql->param == NULL || param == NULL) {
tscDebug("%p already freed in dnodecallback", pSql); tscDebug("%p already freed in dnodecallback", pSql);
assert(pSql->res.code == TSDB_CODE_TSC_QUERY_CANCELLED);
return; return;
} }
...@@ -2536,7 +2557,10 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR ...@@ -2536,7 +2557,10 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY) { if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY) {
tscError("%p sub:%p failed code:%s, retry:%d", pParentSql, pSql, tstrerror(numOfRows), trsupport->numOfRetry); tscError("%p sub:%p failed code:%s, retry:%d", pParentSql, pSql, tstrerror(numOfRows), trsupport->numOfRetry);
if (tscReissueSubquery(trsupport, pSql, numOfRows) == TSDB_CODE_SUCCESS) { int32_t sent = 0;
tscReissueSubquery(trsupport, pSql, numOfRows, &sent);
if (sent) {
return; return;
} }
} else { } else {
...@@ -2658,7 +2682,11 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { ...@@ -2658,7 +2682,11 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY) { if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY) {
tscError("%p sub:%p failed code:%s, retry:%d", pParentSql, pSql, tstrerror(code), trsupport->numOfRetry); tscError("%p sub:%p failed code:%s, retry:%d", pParentSql, pSql, tstrerror(code), trsupport->numOfRetry);
if (tscReissueSubquery(trsupport, pSql, code) == TSDB_CODE_SUCCESS) {
int32_t sent = 0;
tscReissueSubquery(trsupport, pSql, code, &sent);
if (sent) {
return; return;
} }
} else { } else {
......
...@@ -154,6 +154,7 @@ void taos_init_imp(void) { ...@@ -154,6 +154,7 @@ void taos_init_imp(void) {
if (tscNumOfThreads < 2) { if (tscNumOfThreads < 2) {
tscNumOfThreads = 2; tscNumOfThreads = 2;
} }
taosTmrThreads = tscNumOfThreads;
tscQhandle = taosInitScheduler(queueSize, tscNumOfThreads, "tsc"); tscQhandle = taosInitScheduler(queueSize, tscNumOfThreads, "tsc");
if (NULL == tscQhandle) { if (NULL == tscQhandle) {
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
FIND_PATH(HEADER_GTEST_INCLUDE_DIR gtest.h /usr/include/gtest /usr/local/include/gtest) FIND_PATH(HEADER_GTEST_INCLUDE_DIR gtest.h /usr/include/gtest /usr/local/include/gtest)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(inc)
......
...@@ -134,6 +134,22 @@ typedef uint64_t TKEY; ...@@ -134,6 +134,22 @@ typedef uint64_t TKEY;
#define tdGetTKEY(key) (((TKEY)ABS(key)) | (TKEY_NEGATIVE_FLAG & (TKEY)(key))) #define tdGetTKEY(key) (((TKEY)ABS(key)) | (TKEY_NEGATIVE_FLAG & (TKEY)(key)))
#define tdGetKey(tkey) (((TSKEY)((tkey)&TKEY_VALUE_FILTER)) * (TKEY_IS_NEGATIVE(tkey) ? -1 : 1)) #define tdGetKey(tkey) (((TSKEY)((tkey)&TKEY_VALUE_FILTER)) * (TKEY_IS_NEGATIVE(tkey) ? -1 : 1))
#define MIN_TS_KEY ((TSKEY)0x8000000000000001)
#define MAX_TS_KEY ((TSKEY)0x3fffffffffffffff)
#define TD_TO_TKEY(key) tdGetTKEY(((key) < MIN_TS_KEY) ? MIN_TS_KEY : (((key) > MAX_TS_KEY) ? MAX_TS_KEY : key))
static FORCE_INLINE TKEY keyToTkey(TSKEY key) {
TSKEY lkey = key;
if (key > MAX_TS_KEY) {
lkey = MAX_TS_KEY;
} else if (key < MIN_TS_KEY) {
lkey = MIN_TS_KEY;
}
return tdGetTKEY(lkey);
}
static FORCE_INLINE int tkeyComparFn(const void *tkey1, const void *tkey2) { static FORCE_INLINE int tkeyComparFn(const void *tkey1, const void *tkey2) {
TSKEY key1 = tdGetKey(*(TKEY *)tkey1); TSKEY key1 = tdGetKey(*(TKEY *)tkey1);
TSKEY key2 = tdGetKey(*(TKEY *)tkey2); TSKEY key2 = tdGetKey(*(TKEY *)tkey2);
......
...@@ -273,7 +273,7 @@ bool taosCfgDynamicOptions(char *msg) { ...@@ -273,7 +273,7 @@ bool taosCfgDynamicOptions(char *msg) {
int32_t vint = 0; int32_t vint = 0;
paGetToken(msg, &option, &olen); paGetToken(msg, &option, &olen);
if (olen == 0) return TSDB_CODE_COM_INVALID_CFG_MSG; if (olen == 0) return false;;
paGetToken(option + olen + 1, &value, &vlen); paGetToken(option + olen + 1, &value, &vlen);
if (vlen == 0) if (vlen == 0)
...@@ -316,11 +316,9 @@ bool taosCfgDynamicOptions(char *msg) { ...@@ -316,11 +316,9 @@ bool taosCfgDynamicOptions(char *msg) {
} }
return true; return true;
} }
if (strncasecmp(cfg->option, "debugFlag", olen) == 0) { if (strncasecmp(cfg->option, "debugFlag", olen) == 0) {
taosSetAllDebugFlag(); taosSetAllDebugFlag();
} }
return true; return true;
} }
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
...@@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED) ...@@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED)
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME} ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
POST_BUILD POST_BUILD
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.18-dist.jar ${LIBRARY_OUTPUT_PATH} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.19-dist.jar ${LIBRARY_OUTPUT_PATH}
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
COMMENT "build jdbc driver") COMMENT "build jdbc driver")
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME}) ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<groupId>com.taosdata.jdbc</groupId> <groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId> <artifactId>taos-jdbcdriver</artifactId>
<version>2.0.18</version> <version>2.0.19</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>JDBCDriver</name> <name>JDBCDriver</name>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.taosdata.jdbc</groupId> <groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId> <artifactId>taos-jdbcdriver</artifactId>
<version>2.0.18</version> <version>2.0.19</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>JDBCDriver</name> <name>JDBCDriver</name>
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url> <url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
...@@ -81,8 +81,6 @@ ...@@ -81,8 +81,6 @@
<artifactId>commons-dbcp2</artifactId> <artifactId>commons-dbcp2</artifactId>
<version>2.7.0</version> <version>2.7.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
...@@ -132,6 +130,7 @@ ...@@ -132,6 +130,7 @@
<exclude>**/AppMemoryLeakTest.java</exclude> <exclude>**/AppMemoryLeakTest.java</exclude>
<exclude>**/TaosInfoMonitorTest.java</exclude> <exclude>**/TaosInfoMonitorTest.java</exclude>
<exclude>**/FailOverTest.java</exclude> <exclude>**/FailOverTest.java</exclude>
<exclude>**/InvalidResultSetPointerTest.java</exclude>
</excludes> </excludes>
<testFailureIgnore>true</testFailureIgnore> <testFailureIgnore>true</testFailureIgnore>
</configuration> </configuration>
......
...@@ -8,7 +8,7 @@ import java.util.List; ...@@ -8,7 +8,7 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
public abstract class AbstractTaosDriver implements Driver { public abstract class AbstractDriver implements Driver {
private static final String TAOS_CFG_FILENAME = "taos.cfg"; private static final String TAOS_CFG_FILENAME = "taos.cfg";
......
package com.taosdata.jdbc;
import java.sql.*;
public abstract class AbstractStatement extends WrapperImpl implements Statement {
private volatile boolean closeOnCompletion;
private int fetchSize;
@Override
public abstract ResultSet executeQuery(String sql) throws SQLException;
@Override
public abstract int executeUpdate(String sql) throws SQLException;
@Override
public abstract void close() throws SQLException;
@Override
public int getMaxFieldSize() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return TSDBConstants.maxFieldSize;
}
@Override
public void setMaxFieldSize(int max) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (max < 0)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
// nothing to do
}
@Override
public int getMaxRows() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return 0;
}
@Override
public void setMaxRows(int max) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (max < 0)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
// nothing to do
}
@Override
public void setEscapeProcessing(boolean enable) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
}
@Override
public int getQueryTimeout() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return 0;
}
@Override
public void setQueryTimeout(int seconds) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (seconds < 0)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
}
@Override
public void cancel() throws SQLException {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public SQLWarning getWarnings() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return null;
}
@Override
public void clearWarnings() throws SQLException {
// nothing to do
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
}
@Override
public void setCursorName(String name) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
}
@Override
public abstract boolean execute(String sql) throws SQLException;
@Override
public abstract ResultSet getResultSet() throws SQLException;
@Override
public abstract int getUpdateCount() throws SQLException;
@Override
public boolean getMoreResults() throws SQLException {
return getMoreResults(CLOSE_CURRENT_RESULT);
}
@Override
public void setFetchDirection(int direction) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
//nothing to do
}
@Override
public int getFetchDirection() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return ResultSet.FETCH_FORWARD;
}
@Override
public void setFetchSize(int rows) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (rows < 0)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
//nothing to do
this.fetchSize = rows;
}
@Override
public int getFetchSize() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return this.fetchSize;
}
@Override
public int getResultSetConcurrency() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return ResultSet.CONCUR_READ_ONLY;
}
@Override
public int getResultSetType() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return ResultSet.TYPE_FORWARD_ONLY;
}
@Override
public abstract void addBatch(String sql) throws SQLException;
@Override
public abstract void clearBatch() throws SQLException;
@Override
public abstract int[] executeBatch() throws SQLException;
@Override
public abstract Connection getConnection() throws SQLException;
@Override
public boolean getMoreResults(int current) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return false;
}
@Override
public ResultSet getGeneratedKeys() throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
}
@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
}
@Override
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
}
@Override
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
}
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
}
@Override
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
}
@Override
public boolean execute(String sql, String[] columnNames) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
}
@Override
public int getResultSetHoldability() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
}
@Override
public abstract boolean isClosed() throws SQLException;
@Override
public void setPoolable(boolean poolable) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
//nothing to do
}
@Override
public boolean isPoolable() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return false;
}
@Override
public void closeOnCompletion() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
this.closeOnCompletion = true;
}
@Override
public boolean isCloseOnCompletion() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
return this.closeOnCompletion;
}
}
...@@ -160,12 +160,12 @@ public class DatabaseMetaDataResultSet implements ResultSet { ...@@ -160,12 +160,12 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override @Override
public Date getDate(int columnIndex) throws SQLException { public Date getDate(int columnIndex) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public Time getTime(int columnIndex) throws SQLException { public Time getTime(int columnIndex) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -176,17 +176,17 @@ public class DatabaseMetaDataResultSet implements ResultSet { ...@@ -176,17 +176,17 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override @Override
public InputStream getAsciiStream(int columnIndex) throws SQLException { public InputStream getAsciiStream(int columnIndex) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public InputStream getUnicodeStream(int columnIndex) throws SQLException { public InputStream getUnicodeStream(int columnIndex) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public InputStream getBinaryStream(int columnIndex) throws SQLException { public InputStream getBinaryStream(int columnIndex) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -256,22 +256,22 @@ public class DatabaseMetaDataResultSet implements ResultSet { ...@@ -256,22 +256,22 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override @Override
public InputStream getAsciiStream(String columnLabel) throws SQLException { public InputStream getAsciiStream(String columnLabel) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public InputStream getUnicodeStream(String columnLabel) throws SQLException { public InputStream getUnicodeStream(String columnLabel) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public InputStream getBinaryStream(String columnLabel) throws SQLException { public InputStream getBinaryStream(String columnLabel) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public SQLWarning getWarnings() throws SQLException { public SQLWarning getWarnings() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -281,7 +281,7 @@ public class DatabaseMetaDataResultSet implements ResultSet { ...@@ -281,7 +281,7 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override @Override
public String getCursorName() throws SQLException { public String getCursorName() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -313,12 +313,12 @@ public class DatabaseMetaDataResultSet implements ResultSet { ...@@ -313,12 +313,12 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override @Override
public Reader getCharacterStream(int columnIndex) throws SQLException { public Reader getCharacterStream(int columnIndex) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public Reader getCharacterStream(String columnLabel) throws SQLException { public Reader getCharacterStream(String columnLabel) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -353,22 +353,22 @@ public class DatabaseMetaDataResultSet implements ResultSet { ...@@ -353,22 +353,22 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override @Override
public void beforeFirst() throws SQLException { public void beforeFirst() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void afterLast() throws SQLException { public void afterLast() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public boolean first() throws SQLException { public boolean first() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public boolean last() throws SQLException { public boolean last() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -383,17 +383,17 @@ public class DatabaseMetaDataResultSet implements ResultSet { ...@@ -383,17 +383,17 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override @Override
public boolean absolute(int row) throws SQLException { public boolean absolute(int row) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public boolean relative(int rows) throws SQLException { public boolean relative(int rows) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public boolean previous() throws SQLException { public boolean previous() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -443,227 +443,227 @@ public class DatabaseMetaDataResultSet implements ResultSet { ...@@ -443,227 +443,227 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override @Override
public void updateNull(int columnIndex) throws SQLException { public void updateNull(int columnIndex) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateBoolean(int columnIndex, boolean x) throws SQLException { public void updateBoolean(int columnIndex, boolean x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateByte(int columnIndex, byte x) throws SQLException { public void updateByte(int columnIndex, byte x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateShort(int columnIndex, short x) throws SQLException { public void updateShort(int columnIndex, short x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateInt(int columnIndex, int x) throws SQLException { public void updateInt(int columnIndex, int x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateLong(int columnIndex, long x) throws SQLException { public void updateLong(int columnIndex, long x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateFloat(int columnIndex, float x) throws SQLException { public void updateFloat(int columnIndex, float x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateDouble(int columnIndex, double x) throws SQLException { public void updateDouble(int columnIndex, double x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateString(int columnIndex, String x) throws SQLException { public void updateString(int columnIndex, String x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateBytes(int columnIndex, byte[] x) throws SQLException { public void updateBytes(int columnIndex, byte[] x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateDate(int columnIndex, Date x) throws SQLException { public void updateDate(int columnIndex, Date x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateTime(int columnIndex, Time x) throws SQLException { public void updateTime(int columnIndex, Time x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateObject(int columnIndex, Object x) throws SQLException { public void updateObject(int columnIndex, Object x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateNull(String columnLabel) throws SQLException { public void updateNull(String columnLabel) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateBoolean(String columnLabel, boolean x) throws SQLException { public void updateBoolean(String columnLabel, boolean x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateByte(String columnLabel, byte x) throws SQLException { public void updateByte(String columnLabel, byte x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateShort(String columnLabel, short x) throws SQLException { public void updateShort(String columnLabel, short x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateInt(String columnLabel, int x) throws SQLException { public void updateInt(String columnLabel, int x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateLong(String columnLabel, long x) throws SQLException { public void updateLong(String columnLabel, long x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateFloat(String columnLabel, float x) throws SQLException { public void updateFloat(String columnLabel, float x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateDouble(String columnLabel, double x) throws SQLException { public void updateDouble(String columnLabel, double x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateString(String columnLabel, String x) throws SQLException { public void updateString(String columnLabel, String x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateBytes(String columnLabel, byte[] x) throws SQLException { public void updateBytes(String columnLabel, byte[] x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateDate(String columnLabel, Date x) throws SQLException { public void updateDate(String columnLabel, Date x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateTime(String columnLabel, Time x) throws SQLException { public void updateTime(String columnLabel, Time x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateObject(String columnLabel, Object x) throws SQLException { public void updateObject(String columnLabel, Object x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void insertRow() throws SQLException { public void insertRow() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void updateRow() throws SQLException { public void updateRow() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void deleteRow() throws SQLException { public void deleteRow() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void refreshRow() throws SQLException { public void refreshRow() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void cancelRowUpdates() throws SQLException { public void cancelRowUpdates() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void moveToInsertRow() throws SQLException { public void moveToInsertRow() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void moveToCurrentRow() throws SQLException { public void moveToCurrentRow() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -673,12 +673,12 @@ public class DatabaseMetaDataResultSet implements ResultSet { ...@@ -673,12 +673,12 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override @Override
public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException { public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public Ref getRef(int columnIndex) throws SQLException { public Ref getRef(int columnIndex) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -1043,12 +1043,12 @@ public class DatabaseMetaDataResultSet implements ResultSet { ...@@ -1043,12 +1043,12 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override @Override
public <T> T getObject(int columnIndex, Class<T> type) throws SQLException { public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException { public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
......
...@@ -20,7 +20,7 @@ import java.util.Map; ...@@ -20,7 +20,7 @@ import java.util.Map;
public abstract class TSDBConstants { public abstract class TSDBConstants {
public static final String STATEMENT_CLOSED = "statement is closed"; public static final String STATEMENT_CLOSED = "statement is closed";
public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!"; public static final String UNSUPPORTED_METHOD_EXCEPTION_MSG = "this operation is NOT supported currently!";
public static final String INVALID_VARIABLES = "invalid variables"; public static final String INVALID_VARIABLES = "invalid variables";
public static final String RESULT_SET_IS_CLOSED = "resultSet is closed"; public static final String RESULT_SET_IS_CLOSED = "resultSet is closed";
...@@ -36,6 +36,7 @@ public abstract class TSDBConstants { ...@@ -36,6 +36,7 @@ public abstract class TSDBConstants {
public static final int JNI_NUM_OF_FIELDS_0 = -4; public static final int JNI_NUM_OF_FIELDS_0 = -4;
public static final int JNI_SQL_NULL = -5; public static final int JNI_SQL_NULL = -5;
public static final int JNI_FETCH_END = -6; public static final int JNI_FETCH_END = -6;
public static final int JNI_OUT_OF_MEMORY = -7;
public static final int TSDB_DATA_TYPE_NULL = 0; public static final int TSDB_DATA_TYPE_NULL = 0;
public static final int TSDB_DATA_TYPE_BOOL = 1; public static final int TSDB_DATA_TYPE_BOOL = 1;
......
...@@ -37,7 +37,7 @@ import java.util.logging.Logger; ...@@ -37,7 +37,7 @@ import java.util.logging.Logger;
* register it with the DriverManager. This means that a user can load and * register it with the DriverManager. This means that a user can load and
* register a driver by doing Class.forName("foo.bah.Driver") * register a driver by doing Class.forName("foo.bah.Driver")
*/ */
public class TSDBDriver extends AbstractTaosDriver { public class TSDBDriver extends AbstractDriver {
@Deprecated @Deprecated
private static final String URL_PREFIX1 = "jdbc:TSDB://"; private static final String URL_PREFIX1 = "jdbc:TSDB://";
......
package com.taosdata.jdbc; package com.taosdata.jdbc;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -13,8 +14,23 @@ public class TSDBError { ...@@ -13,8 +14,23 @@ public class TSDBError {
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_VARIABLE, "invalid variables"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_VARIABLE, "invalid variables");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED, "statement is closed"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED, "statement is closed");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED, "resultSet is closed"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED, "resultSet is closed");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY, "Batch is empty!");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY, "Can not issue data manipulation statements with executeQuery()");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEUPDATE, "Can not issue SELECT via executeUpdate()");
/**************************************************/
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error");
/**************************************************/ /**************************************************/
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SUBSCRIBE_FAILED, "failed to create subscription"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SUBSCRIBE_FAILED, "failed to create subscription");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING, "Unsupported encoding");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_TDENGINE_ERROR, "internal error of database!");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, "JNI connection already closed!");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL, "invalid JNI result set!");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0, "invalid num of fields!");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_SQL_NULL, "empty sql string!");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_FETCH_END, "fetch to the end of resultset");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY, "JNI alloc memory failed!");
} }
public static String wrapErrMsg(String msg) { public static String wrapErrMsg(String msg) {
...@@ -22,10 +38,24 @@ public class TSDBError { ...@@ -22,10 +38,24 @@ public class TSDBError {
} }
public static SQLException createSQLException(int errorNumber) { public static SQLException createSQLException(int errorNumber) {
// JDBC exception code is less than 0x2350 return createSQLException(errorNumber, null);
if (errorNumber <= 0x2350) }
return new SQLException(TSDBErrorMap.get(errorNumber));
// JNI exception code is public static SQLException createSQLException(int errorNumber, String message) {
return new SQLException(wrapErrMsg(TSDBErrorMap.get(errorNumber))); if (message == null || message.isEmpty()) {
if (TSDBErrorNumbers.contains(errorNumber))
message = TSDBErrorMap.get(errorNumber);
else
message = TSDBErrorMap.get(TSDBErrorNumbers.ERROR_UNKNOWN);
}
if (errorNumber == TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD)
return new SQLFeatureNotSupportedException(message);
if (errorNumber < TSDBErrorNumbers.ERROR_UNKNOWN)
// JDBC exception's error number is less than 0x2350
return new SQLException("ERROR (" + Integer.toHexString(errorNumber) + "): " + message);
// JNI exception's error number is large than 0x2350
return new SQLException("TDengine ERROR (" + Integer.toHexString(errorNumber) + "): " + message);
} }
} }
package com.taosdata.jdbc; package com.taosdata.jdbc;
import java.util.HashSet;
public class TSDBErrorNumbers { public class TSDBErrorNumbers {
public static final int ERROR_CONNECTION_CLOSED = 0x2301; // connection already closed public static final int ERROR_CONNECTION_CLOSED = 0x2301; // connection already closed
...@@ -7,9 +9,52 @@ public class TSDBErrorNumbers { ...@@ -7,9 +9,52 @@ public class TSDBErrorNumbers {
public static final int ERROR_INVALID_VARIABLE = 0x2303; //invalid variables public static final int ERROR_INVALID_VARIABLE = 0x2303; //invalid variables
public static final int ERROR_STATEMENT_CLOSED = 0x2304; //statement already closed public static final int ERROR_STATEMENT_CLOSED = 0x2304; //statement already closed
public static final int ERROR_RESULTSET_CLOSED = 0x2305; //resultSet is closed public static final int ERROR_RESULTSET_CLOSED = 0x2305; //resultSet is closed
public static final int ERROR_BATCH_IS_EMPTY = 0x2306; //Batch is empty!
public static final int ERROR_INVALID_WITH_EXECUTEQUERY = 0x2307; //Can not issue data manipulation statements with executeQuery()
public static final int ERROR_INVALID_WITH_EXECUTEUPDATE = 0x2308; //Can not issue SELECT via executeUpdate()
public static final int ERROR_UNKNOWN = 0x2350; //unknown error
public static final int ERROR_SUBSCRIBE_FAILED = 0x2351; //failed to create subscription
public static final int ERROR_UNSUPPORTED_ENCODING = 0x2352; //Unsupported encoding
public static final int ERROR_JNI_TDENGINE_ERROR = 0x2353;
public static final int ERROR_JNI_CONNECTION_NULL = 0x2354; //invalid tdengine connection!
public static final int ERROR_JNI_RESULT_SET_NULL = 0x2355;
public static final int ERROR_JNI_NUM_OF_FIELDS_0 = 0x2356;
public static final int ERROR_JNI_SQL_NULL = 0x2357;
public static final int ERROR_JNI_FETCH_END = 0x2358;
public static final int ERROR_JNI_OUT_OF_MEMORY = 0x2359;
private static final HashSet<Integer> errorNumbers;
public static final int ERROR_SUBSCRIBE_FAILED = 0x2350; //failed to create subscription static {
errorNumbers = new HashSet();
errorNumbers.add(ERROR_CONNECTION_CLOSED);
errorNumbers.add(ERROR_UNSUPPORTED_METHOD);
errorNumbers.add(ERROR_INVALID_VARIABLE);
errorNumbers.add(ERROR_STATEMENT_CLOSED);
errorNumbers.add(ERROR_RESULTSET_CLOSED);
errorNumbers.add(ERROR_INVALID_WITH_EXECUTEQUERY);
errorNumbers.add(ERROR_INVALID_WITH_EXECUTEUPDATE);
/*****************************************************/
errorNumbers.add(ERROR_SUBSCRIBE_FAILED);
errorNumbers.add(ERROR_UNSUPPORTED_ENCODING);
errorNumbers.add(ERROR_JNI_TDENGINE_ERROR);
errorNumbers.add(ERROR_JNI_CONNECTION_NULL);
errorNumbers.add(ERROR_JNI_RESULT_SET_NULL);
errorNumbers.add(ERROR_JNI_NUM_OF_FIELDS_0);
errorNumbers.add(ERROR_JNI_SQL_NULL);
errorNumbers.add(ERROR_JNI_FETCH_END);
errorNumbers.add(ERROR_JNI_OUT_OF_MEMORY);
}
private TSDBErrorNumbers() { private TSDBErrorNumbers() {
} }
public static boolean contains(int errorNumber) {
return errorNumbers.contains(errorNumber);
}
} }
...@@ -38,7 +38,7 @@ public class TSDBJNIConnector { ...@@ -38,7 +38,7 @@ public class TSDBJNIConnector {
/** /**
* Result set pointer for the current connection * Result set pointer for the current connection
*/ */
private long taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER; // private long taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER;
/** /**
* result set status in current connection * result set status in current connection
...@@ -119,9 +119,9 @@ public class TSDBJNIConnector { ...@@ -119,9 +119,9 @@ public class TSDBJNIConnector {
public long executeQuery(String sql) throws SQLException { public long executeQuery(String sql) throws SQLException {
// close previous result set if the user forgets to invoke the // close previous result set if the user forgets to invoke the
// free method to close previous result set. // free method to close previous result set.
if (!this.isResultsetClosed) { // if (!this.isResultsetClosed) {
freeResultSet(taosResultSetPointer); // freeResultSet(taosResultSetPointer);
} // }
Long pSql = 0l; Long pSql = 0l;
try { try {
...@@ -130,21 +130,32 @@ public class TSDBJNIConnector { ...@@ -130,21 +130,32 @@ public class TSDBJNIConnector {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
this.freeResultSetImp(this.taos, pSql); this.freeResultSetImp(this.taos, pSql);
throw new SQLException(TSDBConstants.WrapErrMsg("Unsupported encoding")); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING);
}
if (pSql == TSDBConstants.JNI_CONNECTION_NULL) {
this.freeResultSetImp(this.taos, pSql);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
}
if (pSql == TSDBConstants.JNI_SQL_NULL) {
this.freeResultSetImp(this.taos, pSql);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_SQL_NULL);
}
if (pSql == TSDBConstants.JNI_OUT_OF_MEMORY) {
this.freeResultSetImp(this.taos, pSql);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY);
} }
int code = this.getErrCode(pSql); int code = this.getErrCode(pSql);
if (code != 0) { if (code != TSDBConstants.JNI_SUCCESS) {
affectedRows = -1; affectedRows = -1;
String msg = this.getErrMsg(pSql); String msg = this.getErrMsg(pSql);
this.freeResultSetImp(this.taos, pSql); this.freeResultSetImp(this.taos, pSql);
throw new SQLException(TSDBConstants.WrapErrMsg(msg), "", code); throw TSDBError.createSQLException(code, msg);
} }
// Try retrieving result set for the executed SQL using the current connection pointer. // Try retrieving result set for the executed SQL using the current connection pointer.
taosResultSetPointer = this.getResultSetImp(this.taos, pSql); pSql = this.getResultSetImp(this.taos, pSql);
isResultsetClosed = (taosResultSetPointer == TSDBConstants.JNI_NULL_POINTER); isResultsetClosed = (pSql == TSDBConstants.JNI_NULL_POINTER);
return pSql; return pSql;
} }
...@@ -173,9 +184,9 @@ public class TSDBJNIConnector { ...@@ -173,9 +184,9 @@ public class TSDBJNIConnector {
* Get resultset pointer * Get resultset pointer
* Each connection should have a single open result set at a time * Each connection should have a single open result set at a time
*/ */
public long getResultSet() { // public long getResultSet() {
return taosResultSetPointer; // return taosResultSetPointer;
} // }
private native long getResultSetImp(long connection, long pSql); private native long getResultSetImp(long connection, long pSql);
...@@ -188,16 +199,16 @@ public class TSDBJNIConnector { ...@@ -188,16 +199,16 @@ public class TSDBJNIConnector {
/** /**
* Free resultset operation from C to release resultset pointer by JNI * Free resultset operation from C to release resultset pointer by JNI
*/ */
public int freeResultSet(long result) { public int freeResultSet(long pSql) {
int res = TSDBConstants.JNI_SUCCESS; int res = TSDBConstants.JNI_SUCCESS;
if (result != taosResultSetPointer && taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) { // if (result != taosResultSetPointer && taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) {
throw new RuntimeException("Invalid result set pointer"); // throw new RuntimeException("Invalid result set pointer");
} // }
if (taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) { // if (taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) {
res = this.freeResultSetImp(this.taos, result); res = this.freeResultSetImp(this.taos, pSql);
taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER; // taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER;
} // }
isResultsetClosed = true; isResultsetClosed = true;
return res; return res;
...@@ -207,15 +218,15 @@ public class TSDBJNIConnector { ...@@ -207,15 +218,15 @@ public class TSDBJNIConnector {
* Close the open result set which is associated to the current connection. If the result set is already * Close the open result set which is associated to the current connection. If the result set is already
* closed, return 0 for success. * closed, return 0 for success.
*/ */
public int freeResultSet() { // public int freeResultSet() {
int resCode = TSDBConstants.JNI_SUCCESS; // int resCode = TSDBConstants.JNI_SUCCESS;
if (!isResultsetClosed) { // if (!isResultsetClosed) {
resCode = this.freeResultSetImp(this.taos, this.taosResultSetPointer); // resCode = this.freeResultSetImp(this.taos, this.taosResultSetPointer);
taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER; // taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER;
isResultsetClosed = true; // isResultsetClosed = true;
} // }
return resCode; // return resCode;
} // }
private native int freeResultSetImp(long connection, long result); private native int freeResultSetImp(long connection, long result);
......
...@@ -264,17 +264,17 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat ...@@ -264,17 +264,17 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override @Override
public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -284,7 +284,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat ...@@ -284,7 +284,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override @Override
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -321,156 +321,156 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat ...@@ -321,156 +321,156 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override @Override
public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setRef(int parameterIndex, Ref x) throws SQLException { public void setRef(int parameterIndex, Ref x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setBlob(int parameterIndex, Blob x) throws SQLException { public void setBlob(int parameterIndex, Blob x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setClob(int parameterIndex, Clob x) throws SQLException { public void setClob(int parameterIndex, Clob x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setArray(int parameterIndex, Array x) throws SQLException { public void setArray(int parameterIndex, Array x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public ResultSetMetaData getMetaData() throws SQLException { public ResultSetMetaData getMetaData() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setURL(int parameterIndex, URL x) throws SQLException { public void setURL(int parameterIndex, URL x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public ParameterMetaData getParameterMetaData() throws SQLException { public ParameterMetaData getParameterMetaData() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setRowId(int parameterIndex, RowId x) throws SQLException { public void setRowId(int parameterIndex, RowId x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setNString(int parameterIndex, String value) throws SQLException { public void setNString(int parameterIndex, String value) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setNClob(int parameterIndex, NClob value) throws SQLException { public void setNClob(int parameterIndex, NClob value) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setClob(int parameterIndex, Reader reader) throws SQLException { public void setClob(int parameterIndex, Reader reader) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void setNClob(int parameterIndex, Reader reader) throws SQLException { public void setNClob(int parameterIndex, Reader reader) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
} }
...@@ -29,11 +29,11 @@ public class TSDBResultSetMetaData implements ResultSetMetaData { ...@@ -29,11 +29,11 @@ public class TSDBResultSetMetaData implements ResultSetMetaData {
} }
public <T> T unwrap(Class<T> iface) throws SQLException { public <T> T unwrap(Class<T> iface) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
public boolean isWrapperFor(Class<?> iface) throws SQLException { public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
public int getColumnCount() throws SQLException { public int getColumnCount() throws SQLException {
...@@ -94,7 +94,7 @@ public class TSDBResultSetMetaData implements ResultSetMetaData { ...@@ -94,7 +94,7 @@ public class TSDBResultSetMetaData implements ResultSetMetaData {
} }
public String getSchemaName(int column) throws SQLException { public String getSchemaName(int column) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
public int getPrecision(int column) throws SQLException { public int getPrecision(int column) throws SQLException {
...@@ -125,11 +125,11 @@ public class TSDBResultSetMetaData implements ResultSetMetaData { ...@@ -125,11 +125,11 @@ public class TSDBResultSetMetaData implements ResultSetMetaData {
} }
public String getTableName(int column) throws SQLException { public String getTableName(int column) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
public String getCatalogName(int column) throws SQLException { public String getCatalogName(int column) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
public int getColumnType(int column) throws SQLException { public int getColumnType(int column) throws SQLException {
...@@ -173,7 +173,7 @@ public class TSDBResultSetMetaData implements ResultSetMetaData { ...@@ -173,7 +173,7 @@ public class TSDBResultSetMetaData implements ResultSetMetaData {
} }
public boolean isDefinitelyWritable(int column) throws SQLException { public boolean isDefinitelyWritable(int column) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
public String getColumnClassName(int column) throws SQLException { public String getColumnClassName(int column) throws SQLException {
......
...@@ -1153,11 +1153,11 @@ public class TSDBResultSetWrapper implements ResultSet { ...@@ -1153,11 +1153,11 @@ public class TSDBResultSetWrapper implements ResultSet {
} }
public <T> T getObject(int columnIndex, Class<T> type) throws SQLException { public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException { public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
......
...@@ -14,34 +14,24 @@ ...@@ -14,34 +14,24 @@
*****************************************************************************/ *****************************************************************************/
package com.taosdata.jdbc; package com.taosdata.jdbc;
import com.taosdata.jdbc.utils.TaosInfo;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class TSDBStatement implements Statement { public class TSDBStatement extends AbstractStatement {
private TSDBJNIConnector connector;
private TSDBJNIConnector connector;
/** /**
* To store batched commands * To store batched commands
*/ */
protected List<String> batchedArgs; protected List<String> batchedArgs;
/**
* Timeout for a query
*/
protected int queryTimeout = 0;
private Long pSql = 0l;
/** /**
* Status of current statement * Status of current statement
*/ */
private boolean isClosed = true; private boolean isClosed;
private int affectedRows = 0; private int affectedRows = -1;
private TSDBConnection connection; private TSDBConnection connection;
private TSDBResultSet resultSet;
public void setConnection(TSDBConnection connection) { public void setConnection(TSDBConnection connection) {
this.connection = connection; this.connection = connection;
...@@ -50,220 +40,89 @@ public class TSDBStatement implements Statement { ...@@ -50,220 +40,89 @@ public class TSDBStatement implements Statement {
TSDBStatement(TSDBConnection connection, TSDBJNIConnector connector) { TSDBStatement(TSDBConnection connection, TSDBJNIConnector connector) {
this.connection = connection; this.connection = connection;
this.connector = connector; this.connector = connector;
this.isClosed = false;
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
try {
return iface.cast(this);
} catch (ClassCastException cce) {
throw new SQLException("Unable to unwrap to " + iface.toString());
}
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return iface.isInstance(this);
} }
public ResultSet executeQuery(String sql) throws SQLException { public ResultSet executeQuery(String sql) throws SQLException {
if (isClosed()) { // check if closed
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
} //TODO: 如果在executeQuery方法中执行insert语句,那么先执行了SQL,再通过pSql来检查是否为一个insert语句,但这个insert SQL已经执行成功了
// TODO make sure it is not a update query // execute query
pSql = this.connector.executeQuery(sql); long pSql = this.connector.executeQuery(sql);
long resultSetPointer = this.connector.getResultSet(); // if pSql is create/insert/update/delete/alter SQL
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { if (this.connector.isUpdateQuery(pSql)) {
this.connector.freeResultSet(pSql); this.connector.freeResultSet(pSql);
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
}
// create/insert/update/delete/alter
if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
this.connector.freeResultSet(pSql);
return null;
}
if (!this.connector.isUpdateQuery(pSql)) {
TSDBResultSet res = new TSDBResultSet(this.connector, resultSetPointer);
res.setBatchFetch(this.connection.getBatchFetch());
return res;
} else {
this.connector.freeResultSet(pSql);
return null;
} }
TSDBResultSet res = new TSDBResultSet(this, this.connector, pSql);
res.setBatchFetch(this.connection.getBatchFetch());
return res;
} }
public int executeUpdate(String sql) throws SQLException { public int executeUpdate(String sql) throws SQLException {
if (isClosed()) { if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
}
// TODO check if current query is update query long pSql = this.connector.executeQuery(sql);
pSql = this.connector.executeQuery(sql); // if pSql is create/insert/update/delete/alter SQL
long resultSetPointer = this.connector.getResultSet(); if (!this.connector.isUpdateQuery(pSql)) {
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
this.connector.freeResultSet(pSql); this.connector.freeResultSet(pSql);
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEUPDATE);
} }
int affectedRows = this.connector.getAffectedRows(pSql);
this.affectedRows = this.connector.getAffectedRows(pSql);
this.connector.freeResultSet(pSql); this.connector.freeResultSet(pSql);
return affectedRows;
return this.affectedRows;
}
public String getErrorMsg(long pSql) {
return this.connector.getErrMsg(pSql);
} }
public void close() throws SQLException { public void close() throws SQLException {
if (!isClosed) { if (!isClosed) {
if (!this.connector.isResultsetClosed()) { if (this.resultSet != null)
this.connector.freeResultSet(); this.resultSet.close();
}
isClosed = true; isClosed = true;
} }
} }
public int getMaxFieldSize() throws SQLException {
if (isClosed()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
}
return 0;
}
public void setMaxFieldSize(int max) throws SQLException {
if (isClosed()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
}
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public int getMaxRows() throws SQLException {
if (isClosed()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
}
// always set maxRows to zero, meaning unlimitted rows in a resultSet
return 0;
}
public void setMaxRows(int max) throws SQLException {
if (isClosed()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
}
// always set maxRows to zero, meaning unlimited rows in a resultSet
}
public void setEscapeProcessing(boolean enable) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public int getQueryTimeout() throws SQLException {
return queryTimeout;
}
public void setQueryTimeout(int seconds) throws SQLException {
this.queryTimeout = seconds;
}
public void cancel() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public SQLWarning getWarnings() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public void clearWarnings() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public void setCursorName(String name) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public boolean execute(String sql) throws SQLException { public boolean execute(String sql) throws SQLException {
if (isClosed) { // check if closed
throw new SQLException("Invalid method call on a closed statement."); if (isClosed())
} throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
boolean res = true; // execute query
pSql = this.connector.executeQuery(sql); long pSql = this.connector.executeQuery(sql);
long resultSetPointer = this.connector.getResultSet(); // if pSql is create/insert/update/delete/alter SQL
if (this.connector.isUpdateQuery(pSql)) {
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { this.affectedRows = this.connector.getAffectedRows(pSql);
this.connector.freeResultSet(pSql);
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
// no result set is retrieved
this.connector.freeResultSet(pSql); this.connector.freeResultSet(pSql);
res = false; return false;
} }
return res; this.resultSet = new TSDBResultSet(this, this.connector, pSql);
this.resultSet.setBatchFetch(this.connection.getBatchFetch());
return true;
} }
public ResultSet getResultSet() throws SQLException { public ResultSet getResultSet() throws SQLException {
if (isClosed) { if (isClosed())
throw new SQLException("Invalid method call on a closed statement."); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
} // long resultSetPointer = connector.getResultSet();
long resultSetPointer = connector.getResultSet(); // TSDBResultSet resSet = null;
TSDBResultSet resSet = null; // if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) {
if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) { // resSet = new TSDBResultSet(connector, resultSetPointer);
resSet = new TSDBResultSet(connector, resultSetPointer); // }
} return this.resultSet;
return resSet;
} }
public int getUpdateCount() throws SQLException { public int getUpdateCount() throws SQLException {
if (isClosed) { if (isClosed())
throw new SQLException("Invalid method call on a closed statement."); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
}
return this.affectedRows; return this.affectedRows;
} }
public boolean getMoreResults() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public void setFetchDirection(int direction) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public int getFetchDirection() throws SQLException {
return ResultSet.FETCH_FORWARD;
// throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
/*
* used by spark
*/
public void setFetchSize(int rows) throws SQLException {
}
/*
* used by spark
*/
public int getFetchSize() throws SQLException {
return 4096;
}
public int getResultSetConcurrency() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public int getResultSetType() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public void addBatch(String sql) throws SQLException { public void addBatch(String sql) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (batchedArgs == null) { if (batchedArgs == null) {
batchedArgs = new ArrayList<>(); batchedArgs = new ArrayList<>();
} }
...@@ -271,83 +130,41 @@ public class TSDBStatement implements Statement { ...@@ -271,83 +130,41 @@ public class TSDBStatement implements Statement {
} }
public void clearBatch() throws SQLException { public void clearBatch() throws SQLException {
batchedArgs.clear(); if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (batchedArgs != null)
batchedArgs.clear();
} }
public int[] executeBatch() throws SQLException { public int[] executeBatch() throws SQLException {
if (isClosed) { if (isClosed())
throw new SQLException("Invalid method call on a closed statement."); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
} if (batchedArgs == null || batchedArgs.isEmpty())
if (batchedArgs == null) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY);
throw new SQLException(TSDBConstants.WrapErrMsg("Batch is empty!"));
} else { int[] res = new int[batchedArgs.size()];
int[] res = new int[batchedArgs.size()]; for (int i = 0; i < batchedArgs.size(); i++) {
for (int i = 0; i < batchedArgs.size(); i++) { boolean isSelect = execute(batchedArgs.get(i));
res[i] = executeUpdate(batchedArgs.get(i)); if (isSelect) {
res[i] = SUCCESS_NO_INFO;
} else {
res[i] = getUpdateCount();
} }
return res;
} }
return res;
} }
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
if (this.connector != null) if (isClosed())
return this.connection; throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); if (this.connector == null)
} throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
return this.connection;
public boolean getMoreResults(int current) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public ResultSet getGeneratedKeys() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public boolean execute(String sql, String[] columnNames) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public int getResultSetHoldability() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
} }
public boolean isClosed() throws SQLException { public boolean isClosed() throws SQLException {
return isClosed; return isClosed;
} }
public void setPoolable(boolean poolable) throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public boolean isPoolable() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public void closeOnCompletion() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
public boolean isCloseOnCompletion() throws SQLException {
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
}
} }
...@@ -50,7 +50,7 @@ public class TSDBSubscribe { ...@@ -50,7 +50,7 @@ public class TSDBSubscribe {
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) { } else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
return null; return null;
} else { } else {
return new TSDBResultSet(this.connecter, resultSetPointer); return new TSDBResultSet(null, this.connecter, resultSetPointer);
} }
} }
......
package com.taosdata.jdbc;
import java.sql.SQLException;
import java.sql.Wrapper;
public class WrapperImpl implements Wrapper {
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
try {
return iface.cast(this);
} catch (ClassCastException cce) {
throw new SQLException("Unable to unwrap to " + iface.toString());
}
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return iface.isInstance(this);
}
}
...@@ -47,7 +47,7 @@ public class RestfulConnection implements Connection { ...@@ -47,7 +47,7 @@ public class RestfulConnection implements Connection {
if (isClosed()) if (isClosed())
throw new SQLException(CONNECTION_IS_CLOSED); throw new SQLException(CONNECTION_IS_CLOSED);
//TODO: prepareStatement //TODO: prepareStatement
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -55,7 +55,7 @@ public class RestfulConnection implements Connection { ...@@ -55,7 +55,7 @@ public class RestfulConnection implements Connection {
if (isClosed()) if (isClosed())
throw new SQLException(CONNECTION_IS_CLOSED); throw new SQLException(CONNECTION_IS_CLOSED);
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -72,7 +72,7 @@ public class RestfulConnection implements Connection { ...@@ -72,7 +72,7 @@ public class RestfulConnection implements Connection {
if (isClosed()) if (isClosed())
throw new SQLException(CONNECTION_IS_CLOSED); throw new SQLException(CONNECTION_IS_CLOSED);
if (!autoCommit) if (!autoCommit)
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -162,7 +162,7 @@ public class RestfulConnection implements Connection { ...@@ -162,7 +162,7 @@ public class RestfulConnection implements Connection {
case Connection.TRANSACTION_READ_COMMITTED: case Connection.TRANSACTION_READ_COMMITTED:
case Connection.TRANSACTION_REPEATABLE_READ: case Connection.TRANSACTION_REPEATABLE_READ:
case Connection.TRANSACTION_SERIALIZABLE: case Connection.TRANSACTION_SERIALIZABLE:
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
default: default:
throw new SQLException(TSDBConstants.INVALID_VARIABLES); throw new SQLException(TSDBConstants.INVALID_VARIABLES);
} }
...@@ -197,10 +197,10 @@ public class RestfulConnection implements Connection { ...@@ -197,10 +197,10 @@ public class RestfulConnection implements Connection {
throw new SQLException(CONNECTION_IS_CLOSED); throw new SQLException(CONNECTION_IS_CLOSED);
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) { if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
return createStatement(); return createStatement();
} }
...@@ -221,7 +221,7 @@ public class RestfulConnection implements Connection { ...@@ -221,7 +221,7 @@ public class RestfulConnection implements Connection {
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES); throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES);
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -252,7 +252,7 @@ public class RestfulConnection implements Connection { ...@@ -252,7 +252,7 @@ public class RestfulConnection implements Connection {
if (isClosed()) if (isClosed())
throw new SQLException(CONNECTION_IS_CLOSED); throw new SQLException(CONNECTION_IS_CLOSED);
if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT) if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -269,7 +269,7 @@ public class RestfulConnection implements Connection { ...@@ -269,7 +269,7 @@ public class RestfulConnection implements Connection {
if (getAutoCommit()) if (getAutoCommit())
throw new SQLException(TSDBConstants.INVALID_VARIABLES); throw new SQLException(TSDBConstants.INVALID_VARIABLES);
//nothing to do //nothing to do
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -279,7 +279,7 @@ public class RestfulConnection implements Connection { ...@@ -279,7 +279,7 @@ public class RestfulConnection implements Connection {
if (getAutoCommit()) if (getAutoCommit())
throw new SQLException(TSDBConstants.INVALID_VARIABLES); throw new SQLException(TSDBConstants.INVALID_VARIABLES);
//nothing to do //nothing to do
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -289,68 +289,68 @@ public class RestfulConnection implements Connection { ...@@ -289,68 +289,68 @@ public class RestfulConnection implements Connection {
if (getAutoCommit()) if (getAutoCommit())
throw new SQLException(TSDBConstants.INVALID_VARIABLES); throw new SQLException(TSDBConstants.INVALID_VARIABLES);
//nothing to do //nothing to do
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException { public void releaseSavepoint(Savepoint savepoint) throws SQLException {
if (isClosed()) if (isClosed())
throw new SQLException(CONNECTION_IS_CLOSED); throw new SQLException(CONNECTION_IS_CLOSED);
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
return createStatement(resultSetType, resultSetConcurrency); return createStatement(resultSetType, resultSetConcurrency);
} }
@Override @Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
return prepareStatement(sql, resultSetType, resultSetConcurrency); return prepareStatement(sql, resultSetType, resultSetConcurrency);
} }
@Override @Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public Clob createClob() throws SQLException { public Clob createClob() throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public Blob createBlob() throws SQLException { public Blob createBlob() throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public NClob createNClob() throws SQLException { public NClob createNClob() throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public SQLXML createSQLXML() throws SQLException { public SQLXML createSQLXML() throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -399,12 +399,12 @@ public class RestfulConnection implements Connection { ...@@ -399,12 +399,12 @@ public class RestfulConnection implements Connection {
@Override @Override
public Array createArrayOf(String typeName, Object[] elements) throws SQLException { public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
...@@ -442,7 +442,7 @@ public class RestfulConnection implements Connection { ...@@ -442,7 +442,7 @@ public class RestfulConnection implements Connection {
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
if (isClosed()) if (isClosed())
throw new SQLException(CONNECTION_IS_CLOSED); throw new SQLException(CONNECTION_IS_CLOSED);
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
} }
@Override @Override
......
...@@ -2,7 +2,7 @@ package com.taosdata.jdbc.rs; ...@@ -2,7 +2,7 @@ package com.taosdata.jdbc.rs;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.taosdata.jdbc.AbstractTaosDriver; import com.taosdata.jdbc.AbstractDriver;
import com.taosdata.jdbc.TSDBConstants; import com.taosdata.jdbc.TSDBConstants;
import com.taosdata.jdbc.TSDBDriver; import com.taosdata.jdbc.TSDBDriver;
import com.taosdata.jdbc.rs.util.HttpClientPoolUtil; import com.taosdata.jdbc.rs.util.HttpClientPoolUtil;
...@@ -11,7 +11,7 @@ import java.sql.*; ...@@ -11,7 +11,7 @@ import java.sql.*;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Logger; import java.util.logging.Logger;
public class RestfulDriver extends AbstractTaosDriver { public class RestfulDriver extends AbstractDriver {
private static final String URL_PREFIX = "jdbc:TAOS-RS://"; private static final String URL_PREFIX = "jdbc:TAOS-RS://";
......
...@@ -8,9 +8,6 @@ import org.junit.Test; ...@@ -8,9 +8,6 @@ import org.junit.Test;
import java.sql.*; import java.sql.*;
import java.util.Properties; import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class StatementTest { public class StatementTest {
static Connection connection = null; static Connection connection = null;
static Statement statement = null; static Statement statement = null;
...@@ -58,12 +55,12 @@ public class StatementTest { ...@@ -58,12 +55,12 @@ public class StatementTest {
statement.executeUpdate("create database if not exists " + dbName); statement.executeUpdate("create database if not exists " + dbName);
statement.executeUpdate("create table if not exists " + dbName + "." + tName + "(ts timestamp, k1 int)"); statement.executeUpdate("create table if not exists " + dbName + "." + tName + "(ts timestamp, k1 int)");
statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", 1)"); statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
statement.executeQuery("select * from " + dbName + "." + tName); statement.execute("select * from " + dbName + "." + tName);
ResultSet resultSet = statement.getResultSet(); ResultSet resultSet = statement.getResultSet();
assertTrue(null != resultSet); Assert.assertNotNull(resultSet);
boolean isClosed = statement.isClosed(); boolean isClosed = statement.isClosed();
assertEquals(false, isClosed); Assert.assertEquals(false, isClosed);
} }
@Test(expected = SQLException.class) @Test(expected = SQLException.class)
......
...@@ -9,13 +9,14 @@ import java.sql.DriverManager; ...@@ -9,13 +9,14 @@ import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.TimeUnit;
public class SubscribeTest { public class SubscribeTest {
Connection connection; Connection connection;
Statement statement; Statement statement;
String dbName = "test"; String dbName = "test";
String tName = "t0"; String tName = "t0";
String host = "localhost"; String host = "127.0.0.1";
String topic = "test"; String topic = "test";
@Before @Before
...@@ -23,15 +24,15 @@ public class SubscribeTest { ...@@ -23,15 +24,15 @@ public class SubscribeTest {
try { try {
Class.forName("com.taosdata.jdbc.TSDBDriver"); Class.forName("com.taosdata.jdbc.TSDBDriver");
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
statement = connection.createStatement(); statement = connection.createStatement();
statement.executeUpdate("create database if not exists " + dbName); statement.execute("drop database if exists " + dbName);
statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); statement.execute("create database if not exists " + dbName);
statement.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
ts += i; ts += i;
...@@ -45,44 +46,40 @@ public class SubscribeTest { ...@@ -45,44 +46,40 @@ public class SubscribeTest {
} }
@Test @Test
public void subscribe() throws Exception { public void subscribe() {
TSDBSubscribe subscribe = null;
try { try {
String rawSql = "select * from " + dbName + "." + tName + ";"; String rawSql = "select * from " + dbName + "." + tName + ";";
System.out.println(rawSql); System.out.println(rawSql);
subscribe = ((TSDBConnection) connection).subscribe(topic, rawSql, false); TSDBSubscribe subscribe = ((TSDBConnection) connection).subscribe(topic, rawSql, false);
int a = 0; int a = 0;
while (true) { while (true) {
Thread.sleep(900); TimeUnit.MILLISECONDS.sleep(1000);
TSDBResultSet resSet = subscribe.consume(); TSDBResultSet resSet = subscribe.consume();
while (resSet.next()) { while (resSet.next()) {
for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) { for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
System.out.printf(i + ": " + resSet.getString(i) + "\t"); System.out.printf(i + ": " + resSet.getString(i) + "\t");
} }
System.out.println("\n======" + a + "=========="); System.out.println("\n======" + a + "==========");
} }
resSet.close();
a++; a++;
if (a >= 2) { if (a >= 2) {
break; break;
} }
// resSet.close();
} }
subscribe.close(true);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
if (null != subscribe) {
subscribe.close(true);
}
} }
} }
@After @After
public void close() { public void close() {
try { try {
statement.executeQuery("drop database " + dbName); statement.execute("drop database " + dbName);
if (statement != null) if (statement != null)
statement.close(); statement.close();
if (connection != null) if (connection != null)
......
...@@ -259,10 +259,12 @@ public class RestfulResultSetTest { ...@@ -259,10 +259,12 @@ public class RestfulResultSetTest {
rs.previous(); rs.previous();
} }
@Test(expected = SQLException.class) @Test
public void setFetchDirection() throws SQLException { public void setFetchDirection() throws SQLException {
rs.setFetchDirection(ResultSet.FETCH_FORWARD); rs.setFetchDirection(ResultSet.FETCH_FORWARD);
Assert.assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection());
rs.setFetchDirection(ResultSet.FETCH_UNKNOWN); rs.setFetchDirection(ResultSet.FETCH_UNKNOWN);
Assert.assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection());
} }
@Test @Test
...@@ -270,14 +272,15 @@ public class RestfulResultSetTest { ...@@ -270,14 +272,15 @@ public class RestfulResultSetTest {
Assert.assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection()); Assert.assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection());
} }
@Test(expected = SQLException.class) @Test
public void setFetchSize() throws SQLException { public void setFetchSize() throws SQLException {
rs.setFetchSize(0); rs.setFetchSize(0);
Assert.assertEquals(0, rs.getFetchSize());
} }
@Test @Test
public void getFetchSize() throws SQLException { public void getFetchSize() throws SQLException {
Assert.assertEquals(1, rs.getFetchSize()); Assert.assertEquals(0, rs.getFetchSize());
} }
@Test @Test
...@@ -526,9 +529,12 @@ public class RestfulResultSetTest { ...@@ -526,9 +529,12 @@ public class RestfulResultSetTest {
rs.updateSQLXML(1, null); rs.updateSQLXML(1, null);
} }
@Test(expected = SQLFeatureNotSupportedException.class) @Test
public void getNString() throws SQLException { public void getNString() throws SQLException {
rs.getNString("f1"); String f10 = rs.getNString("f10");
Assert.assertEquals("涛思数据", f10);
f10 = rs.getNString(10);
Assert.assertEquals("涛思数据", f10);
} }
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_LINUX_64) IF (TD_LINUX_64)
......
CMAKE_MINIMUM_REQUIRED(VERSION 3.5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_LINUX_64) IF (TD_LINUX_64)
......
Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
This program is free software: you can use, redistribute, and/or modify
it under the terms of the GNU Affero General Public License, version 3
or later ("AGPL"), as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
# TDengine python client interface
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册