Merge branch 'develop' into test/testcase
This commit is contained in:
commit
0cad363d6f
33
.travis.yml
33
.travis.yml
|
@ -270,19 +270,20 @@ matrix:
|
|||
fi
|
||||
- make > /dev/null
|
||||
|
||||
# - os: osx
|
||||
# language: c
|
||||
# compiler: clang
|
||||
# env: DESC="mac/clang build"
|
||||
# git:
|
||||
# - depth: 1
|
||||
# addons:
|
||||
# homebrew:
|
||||
# - cmake
|
||||
#
|
||||
# script:
|
||||
# - cd ${TRAVIS_BUILD_DIR}
|
||||
# - mkdir debug
|
||||
# - cd debug
|
||||
# - cmake .. > /dev/null
|
||||
# - make > /dev/null
|
||||
- os: osx
|
||||
osx_image: xcode11.4
|
||||
language: c
|
||||
compiler: clang
|
||||
env: DESC="mac/clang build"
|
||||
git:
|
||||
- depth: 1
|
||||
addons:
|
||||
homebrew:
|
||||
- cmake
|
||||
|
||||
script:
|
||||
- cd ${TRAVIS_BUILD_DIR}
|
||||
- mkdir debug
|
||||
- cd debug
|
||||
- cmake .. > /dev/null
|
||||
- make > /dev/null
|
||||
|
|
|
@ -13,7 +13,7 @@ ENDIF ()
|
|||
SET(TD_ACCOUNT FALSE)
|
||||
SET(TD_ADMIN FALSE)
|
||||
SET(TD_GRANT FALSE)
|
||||
SET(TD_MQTT TRUE)
|
||||
SET(TD_MQTT FALSE)
|
||||
SET(TD_TSDB_PLUGINS FALSE)
|
||||
|
||||
SET(TD_COVER FALSE)
|
||||
|
@ -29,6 +29,11 @@ MESSAGE(STATUS "Community directory: " ${TD_COMMUNITY_DIR})
|
|||
|
||||
INCLUDE(cmake/input.inc)
|
||||
INCLUDE(cmake/platform.inc)
|
||||
|
||||
IF (TD_WINDOWS OR TD_DARWIN)
|
||||
SET(TD_SOMODE_STATIC TRUE)
|
||||
ENDIF ()
|
||||
|
||||
INCLUDE(cmake/define.inc)
|
||||
INCLUDE(cmake/env.inc)
|
||||
INCLUDE(cmake/version.inc)
|
||||
|
|
29
README.md
29
README.md
|
@ -126,44 +126,57 @@ cmake .. -DCPUTYPE=aarch32 && cmake --build .
|
|||
|
||||
If you use the Visual Studio 2013, please open a command window by executing "cmd.exe".
|
||||
Please specify "x86_amd64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat.
|
||||
```
|
||||
```cmd
|
||||
mkdir debug && cd debug
|
||||
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" < x86_amd64 | x86 >
|
||||
cmake .. -G "NMake Makefiles"
|
||||
nmake
|
||||
```
|
||||
|
||||
If you use the Visual Studio 2019, please open a command window by executing "cmd.exe".
|
||||
If you use the Visual Studio 2019 or 2017:
|
||||
|
||||
please open a command window by executing "cmd.exe".
|
||||
Please specify "x64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat.
|
||||
```
|
||||
|
||||
```cmd
|
||||
mkdir debug && cd debug
|
||||
"c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" < x64 | x86 >
|
||||
cmake .. -G "NMake Makefiles"
|
||||
nmake
|
||||
```
|
||||
|
||||
Or, you can open a command window by clicking Visual Studio 2019 menu "Tools -> Command Line -> Developer Command Prompt" or "Tools -> Command Line -> Developer PowerShell" then execute commands as follows:
|
||||
```
|
||||
Or, you can simply open a command window by clicking Windows Start -> "Visual Studio < 2019 | 2017 >" folder -> "x64 Native Tools Command Prompt for VS < 2019 | 2017 >" or "x86 Native Tools Command Prompt for VS < 2019 | 2017 >" depends what architecture your Windows is, then execute commands as follows:
|
||||
```cmd
|
||||
mkdir debug && cd debug
|
||||
cmake .. -G "NMake Makefiles"
|
||||
nmake
|
||||
```
|
||||
|
||||
### On Mac OS X platform
|
||||
|
||||
Please install XCode command line tools and cmake. Verified with XCode 11.4+ on Catalina and Big Sur.
|
||||
|
||||
```shell
|
||||
mkdir debug && cd debug
|
||||
cmake .. && cmake --build .
|
||||
```
|
||||
|
||||
# Quick Run
|
||||
|
||||
# Quick Run
|
||||
To quickly start a TDengine server after building, run the command below in terminal:
|
||||
```cmd
|
||||
```bash
|
||||
./build/bin/taosd -c test/cfg
|
||||
```
|
||||
In another terminal, use the TDengine shell to connect the server:
|
||||
```
|
||||
```bash
|
||||
./build/bin/taos -c test/cfg
|
||||
```
|
||||
option "-c test/cfg" specifies the system configuration file directory.
|
||||
|
||||
# Installing
|
||||
After building successfully, TDengine can be installed by:
|
||||
```cmd
|
||||
```bash
|
||||
make install
|
||||
```
|
||||
Users can find more information about directories installed on the system in the [directory and files](https://www.taosdata.com/en/documentation/administrator/#Directory-and-Files) section. It should be noted that installing from source code does not configure service management for TDengine.
|
||||
|
|
|
@ -128,6 +128,8 @@ IF (TD_DARWIN_64)
|
|||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||
SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
|
||||
SET(RELEASE_FLAGS "-Og")
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc)
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
|
@ -139,6 +141,9 @@ IF (TD_WINDOWS)
|
|||
SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
|
||||
IF (NOT TD_GODLL)
|
||||
SET(COMMON_FLAGS "/nologo /WX /wd4018 /wd2220 /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
|
||||
IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
|
||||
SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
|
||||
ENDIF ()
|
||||
SET(DEBUG_FLAGS "/Zi /W3 /GL")
|
||||
SET(RELEASE_FLAGS "/W0 /O3 /GL")
|
||||
ENDIF ()
|
||||
|
|
|
@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
|
|||
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
|
||||
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
|
||||
IF (TD_MVN_INSTALLED)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.17-dist.jar DESTINATION connector/jdbc)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.18-dist.jar DESTINATION connector/jdbc)
|
||||
ENDIF ()
|
||||
ELSEIF (TD_DARWIN)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
|
||||
|
|
|
@ -13,3 +13,7 @@ ADD_SUBDIRECTORY(MsvcLibX)
|
|||
IF (TD_LINUX AND TD_MQTT)
|
||||
ADD_SUBDIRECTORY(MQTT-C)
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_DARWIN AND TD_MQTT)
|
||||
ADD_SUBDIRECTORY(MQTT-C)
|
||||
ENDIF ()
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
#include <stdint.h>
|
||||
#include "gzguts.h"
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
|
||||
# define LSEEK _lseeki64
|
||||
#else
|
||||
|
@ -240,9 +244,9 @@ local gzFile gz_open(path, fd, mode)
|
|||
/* open the file with the appropriate flags (or just use fd) */
|
||||
state->fd = fd > -1 ? fd : (
|
||||
#ifdef WIDECHAR
|
||||
fd == -2 ? _wopen(path, oflag, 0666) :
|
||||
fd == -2 ? _wopen(path, oflag | O_BINARY, 0666) :
|
||||
#endif
|
||||
open((const char *)path, oflag, 0666));
|
||||
open((const char *)path, oflag | O_BINARY, 0666));
|
||||
if (state->fd == -1) {
|
||||
free(state->path);
|
||||
free(state);
|
||||
|
|
|
@ -179,7 +179,7 @@ taos> select avg(f1), max(f2), min(f3) from test.t10 interval(10s);
|
|||
|
||||
|
||||
|
||||
## **支持平台列表**
|
||||
## 支持平台列表
|
||||
|
||||
### TDengine服务器支持的平台列表
|
||||
|
||||
|
|
|
@ -698,13 +698,13 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
```mysql
|
||||
SELECT TWA(field_name) FROM tb_name WHERE clause;
|
||||
```
|
||||
功能说明:时间加权平均函数。统计表/超级表中某列在一段时间内的时间加权平均。
|
||||
功能说明:时间加权平均函数。统计表中某列在一段时间内的时间加权平均。
|
||||
|
||||
返回结果数据类型:双精度浮点数Double。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:表、超级表。
|
||||
适用于:表。
|
||||
|
||||
- **SUM**
|
||||
```mysql
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
TDengine 提供了遵循 JDBC 标准(3.0)API 规范的 `taos-jdbcdriver` 实现,可在 maven 的中央仓库 [Sonatype Repository][1] 搜索下载。
|
||||
|
||||
`taos-jdbcdriver` 的实现包括 2 种形式: JDBC-JNI 和 JDBC-RESTful(taos-jdbcdriver-2.0.17 开始支持 JDBC-RESTful)。 JDBC-JNI 通过调用客户端 libtaos.so(或 taos.dll )的本地方法实现, JDBC-RESTful 则在内部封装了 RESTful 接口实现。
|
||||
`taos-jdbcdriver` 的实现包括 2 种形式: JDBC-JNI 和 JDBC-RESTful(taos-jdbcdriver-2.0.18 开始支持 JDBC-RESTful)。 JDBC-JNI 通过调用客户端 libtaos.so(或 taos.dll )的本地方法实现, JDBC-RESTful 则在内部封装了 RESTful 接口实现。
|
||||
|
||||

|
||||
|
||||
|
@ -67,7 +67,7 @@ maven 项目中使用如下 pom.xml 配置即可:
|
|||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.17</version>
|
||||
<version>2.0.18</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
@ -334,16 +334,17 @@ conn.close();
|
|||
```java
|
||||
public static void main(String[] args) throws SQLException {
|
||||
HikariConfig config = new HikariConfig();
|
||||
// jdbc properties
|
||||
config.setJdbcUrl("jdbc:TAOS://127.0.0.1:6030/log");
|
||||
config.setUsername("root");
|
||||
config.setPassword("taosdata");
|
||||
|
||||
config.setMinimumIdle(3); //minimum number of idle connection
|
||||
// connection pool configurations
|
||||
config.setMinimumIdle(10); //minimum number of idle connection
|
||||
config.setMaximumPoolSize(10); //maximum number of connection in the pool
|
||||
config.setConnectionTimeout(10000); //maximum wait milliseconds for get connection from pool
|
||||
config.setIdleTimeout(60000); // max idle time for recycle idle connection
|
||||
config.setConnectionTestQuery("describe log.dn"); //validation query
|
||||
config.setValidationTimeout(3000); //validation query timeout
|
||||
config.setConnectionTimeout(30000); //maximum wait milliseconds for get connection from pool
|
||||
config.setMaxLifetime(0); // maximum life time for each connection
|
||||
config.setIdleTimeout(0); // max idle time for recycle idle connection
|
||||
config.setConnectionTestQuery("select server_status()"); //validation query
|
||||
|
||||
HikariDataSource ds = new HikariDataSource(config); //create datasource
|
||||
|
||||
|
@ -375,32 +376,22 @@ conn.close();
|
|||
* 使用示例如下:
|
||||
```java
|
||||
public static void main(String[] args) throws Exception {
|
||||
Properties properties = new Properties();
|
||||
properties.put("driverClassName","com.taosdata.jdbc.TSDBDriver");
|
||||
properties.put("url","jdbc:TAOS://127.0.0.1:6030/log");
|
||||
properties.put("username","root");
|
||||
properties.put("password","taosdata");
|
||||
|
||||
properties.put("maxActive","10"); //maximum number of connection in the pool
|
||||
properties.put("initialSize","3");//initial number of connection
|
||||
properties.put("maxWait","10000");//maximum wait milliseconds for get connection from pool
|
||||
properties.put("minIdle","3");//minimum number of connection in the pool
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
// jdbc properties
|
||||
dataSource.setDriverClassName("com.taosdata.jdbc.TSDBDriver");
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername("root");
|
||||
dataSource.setPassword("taosdata");
|
||||
// pool configurations
|
||||
dataSource.setInitialSize(10);
|
||||
dataSource.setMinIdle(10);
|
||||
dataSource.setMaxActive(10);
|
||||
dataSource.setMaxWait(30000);
|
||||
dataSource.setValidationQuery("select server_status()");
|
||||
|
||||
properties.put("timeBetweenEvictionRunsMillis","3000");// the interval milliseconds to test connection
|
||||
|
||||
properties.put("minEvictableIdleTimeMillis","60000");//the minimum milliseconds to keep idle
|
||||
properties.put("maxEvictableIdleTimeMillis","90000");//the maximum milliseconds to keep idle
|
||||
|
||||
properties.put("validationQuery","describe log.dn"); //validation query
|
||||
properties.put("testWhileIdle","true"); // test connection while idle
|
||||
properties.put("testOnBorrow","false"); // don't need while testWhileIdle is true
|
||||
properties.put("testOnReturn","false"); // don't need while testWhileIdle is true
|
||||
|
||||
//create druid datasource
|
||||
DataSource ds = DruidDataSourceFactory.createDataSource(properties);
|
||||
Connection connection = ds.getConnection(); // get connection
|
||||
Connection connection = dataSource.getConnection(); // get connection
|
||||
Statement statement = connection.createStatement(); // get statement
|
||||
|
||||
//query or insert
|
||||
// ...
|
||||
|
||||
|
@ -427,7 +418,7 @@ Query OK, 1 row(s) in set (0.000141s)
|
|||
## 与框架使用
|
||||
|
||||
* Spring JdbcTemplate 中使用 taos-jdbcdriver,可参考 [SpringJdbcTemplate][11]
|
||||
* Springboot + Mybatis 中使用,可参考 [springbootdemo
|
||||
* Springboot + Mybatis 中使用,可参考 [springbootdemo][12]
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ mkdir -p ${pkg_dir}${install_home_path}/include
|
|||
mkdir -p ${pkg_dir}${install_home_path}/init.d
|
||||
mkdir -p ${pkg_dir}${install_home_path}/script
|
||||
|
||||
echo "" > ${pkg_dir}${install_home_path}/email
|
||||
cp ${compile_dir}/../packaging/cfg/taos.cfg ${pkg_dir}${install_home_path}/cfg
|
||||
cp ${compile_dir}/../packaging/deb/taosd ${pkg_dir}${install_home_path}/init.d
|
||||
cp ${compile_dir}/../packaging/tools/post.sh ${pkg_dir}${install_home_path}/script
|
||||
|
|
|
@ -51,6 +51,7 @@ mkdir -p %{buildroot}%{homepath}/include
|
|||
mkdir -p %{buildroot}%{homepath}/init.d
|
||||
mkdir -p %{buildroot}%{homepath}/script
|
||||
|
||||
echo "" > %{buildroot}%{homepath}/email
|
||||
cp %{_compiledir}/../packaging/cfg/taos.cfg %{buildroot}%{homepath}/cfg
|
||||
cp %{_compiledir}/../packaging/rpm/taosd %{buildroot}%{homepath}/init.d
|
||||
cp %{_compiledir}/../packaging/tools/post.sh %{buildroot}%{homepath}/script
|
||||
|
|
|
@ -21,7 +21,7 @@ else
|
|||
cd ${script_dir}
|
||||
script_dir="$(pwd)"
|
||||
data_dir="/var/lib/taos"
|
||||
log_dir="~/TDengineLog"
|
||||
log_dir=~/TDengine/log
|
||||
fi
|
||||
|
||||
log_link_dir="/usr/local/taos/log"
|
||||
|
|
|
@ -24,7 +24,7 @@ data_dir="/var/lib/taos"
|
|||
if [ "$osType" != "Darwin" ]; then
|
||||
log_dir="/var/log/taos"
|
||||
else
|
||||
log_dir="~/TDengineLog"
|
||||
log_dir=~/TDengine/log
|
||||
fi
|
||||
|
||||
data_link_dir="/usr/local/taos/data"
|
||||
|
@ -178,7 +178,9 @@ function install_bin() {
|
|||
function install_lib() {
|
||||
# Remove links
|
||||
${csudo} rm -f ${lib_link_dir}/libtaos.* || :
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo} rm -f ${lib64_link_dir}/libtaos.* || :
|
||||
fi
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo} cp ${binary_dir}/build/lib/libtaos.so.${verNumber} ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/*
|
||||
|
@ -190,12 +192,14 @@ function install_lib() {
|
|||
${csudo} ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so
|
||||
fi
|
||||
else
|
||||
${csudo} cp ${binary_dir}/build/lib/libtaos.* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/*
|
||||
${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib
|
||||
${csudo} cp -Rf ${binary_dir}/build/lib/libtaos.* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/*
|
||||
${csudo} ln -sf ${install_main_dir}/driver/libtaos.1.dylib ${lib_link_dir}/libtaos.1.dylib
|
||||
${csudo} ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib
|
||||
fi
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo} ldconfig
|
||||
fi
|
||||
}
|
||||
|
||||
function install_header() {
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
# Usage:
|
||||
# sudo gdb -x ./taosd-dump-cfg.gdb
|
||||
|
||||
define attach_pidof
|
||||
if $argc != 1
|
||||
help attach_pidof
|
||||
else
|
||||
shell echo -e "\
|
||||
set \$PID = "$(echo $(pidof $arg0) 0 | cut -d " " -f 1)"\n\
|
||||
if \$PID > 0\n\
|
||||
attach "$(pidof -s $arg0)"\n\
|
||||
else\n\
|
||||
print \"Process '"$arg0"' not found\"\n\
|
||||
end" > /tmp/gdb.pidof
|
||||
source /tmp/gdb.pidof
|
||||
end
|
||||
end
|
||||
|
||||
document attach_pidof
|
||||
Attach to process by name
|
||||
Usage: attach_pidof PROG_NAME
|
||||
end
|
||||
|
||||
set $TAOS_CFG_VTYPE_INT8 = 0
|
||||
set $TAOS_CFG_VTYPE_INT16 = 1
|
||||
set $TAOS_CFG_VTYPE_INT32 = 2
|
||||
set $TAOS_CFG_VTYPE_FLOAT = 3
|
||||
set $TAOS_CFG_VTYPE_STRING = 4
|
||||
set $TAOS_CFG_VTYPE_IPSTR = 5
|
||||
set $TAOS_CFG_VTYPE_DIRECTORY = 6
|
||||
|
||||
set $TSDB_CFG_CTYPE_B_CONFIG = 1U
|
||||
set $TSDB_CFG_CTYPE_B_SHOW = 2U
|
||||
set $TSDB_CFG_CTYPE_B_LOG = 4U
|
||||
set $TSDB_CFG_CTYPE_B_CLIENT = 8U
|
||||
set $TSDB_CFG_CTYPE_B_OPTION = 16U
|
||||
set $TSDB_CFG_CTYPE_B_NOT_PRINT = 32U
|
||||
|
||||
set $TSDB_CFG_PRINT_LEN = 53
|
||||
|
||||
define print_blank
|
||||
if $argc == 1
|
||||
set $blank_len = $arg0
|
||||
while $blank_len > 0
|
||||
printf "%s", " "
|
||||
set $blank_len = $blank_len - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
define dump_cfg
|
||||
if $argc != 1
|
||||
help dump_cfg
|
||||
else
|
||||
set $blen = $TSDB_CFG_PRINT_LEN - (int)strlen($arg0.option)
|
||||
if $blen < 0
|
||||
$blen = 0
|
||||
end
|
||||
#printf "%s: %d\n", "******blen: ", $blen
|
||||
printf "%s: ", $arg0.option
|
||||
print_blank $blen
|
||||
|
||||
if $arg0.valType == $TAOS_CFG_VTYPE_INT8
|
||||
printf "%d\n", *((int8_t *) $arg0.ptr)
|
||||
else
|
||||
if $arg0.valType == $TAOS_CFG_VTYPE_INT16
|
||||
printf "%d\n", *((int16_t *) $arg0.ptr)
|
||||
else
|
||||
if $arg0.valType == $TAOS_CFG_VTYPE_INT32
|
||||
printf "%d\n", *((int32_t *) $arg0.ptr)
|
||||
else
|
||||
if $arg0.valType == $TAOS_CFG_VTYPE_FLOAT
|
||||
printf "%f\n", *((float *) $arg0.ptr)
|
||||
else
|
||||
printf "%s\n", $arg0.ptr
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
document dump_cfg
|
||||
Dump a cfg entry
|
||||
Usage: dump_cfg cfg
|
||||
end
|
||||
|
||||
set pagination off
|
||||
|
||||
attach_pidof taosd
|
||||
|
||||
set $idx=0
|
||||
#print tsGlobalConfigNum
|
||||
#set $end=$1
|
||||
set $end=tsGlobalConfigNum
|
||||
|
||||
p "*=*=*=*=*=*=*=*=*= taos global config:"
|
||||
#while ($idx .lt. $end)
|
||||
while ($idx < $end)
|
||||
# print tsGlobalConfig[$idx].option
|
||||
set $cfg = tsGlobalConfig[$idx]
|
||||
set $tsce = tscEmbedded
|
||||
# p "1"
|
||||
if ($tsce == 0)
|
||||
if !($cfg.cfgType & $TSDB_CFG_CTYPE_B_CLIENT)
|
||||
end
|
||||
else
|
||||
if $cfg.cfgType & $TSDB_CFG_CTYPE_B_NOT_PRINT
|
||||
else
|
||||
if !($cfg.cfgType & $TSDB_CFG_CTYPE_B_SHOW)
|
||||
else
|
||||
dump_cfg $cfg
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
set $idx=$idx+1
|
||||
end
|
||||
|
||||
set $idx=0
|
||||
|
||||
p "*=*=*=*=*=*=*=*=*= taos local config:"
|
||||
while ($idx < $end)
|
||||
set $cfg = tsGlobalConfig[$idx]
|
||||
set $tsce = tscEmbedded
|
||||
if ($tsce == 0)
|
||||
if !($cfg.cfgType & $TSDB_CFG_CTYPE_B_CLIENT)
|
||||
end
|
||||
else
|
||||
if $cfg.cfgType & $TSDB_CFG_CTYPE_B_NOT_PRINT
|
||||
else
|
||||
if ($cfg.cfgType & $TSDB_CFG_CTYPE_B_SHOW)
|
||||
else
|
||||
dump_cfg $cfg
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
set $idx=$idx+1
|
||||
end
|
||||
|
||||
detach
|
||||
|
||||
quit
|
|
@ -8,6 +8,4 @@ INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc)
|
|||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
|
||||
IF (TD_LINUX)
|
||||
ADD_LIBRARY(balance ${SRC})
|
||||
ENDIF ()
|
||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
|||
int32_t bnInitThread();
|
||||
void bnCleanupThread();
|
||||
void bnNotify();
|
||||
void bnStartTimer(int64_t mseconds);
|
||||
void bnStartTimer(int32_t mseconds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "mnodeVgroup.h"
|
||||
|
||||
extern int64_t tsDnodeRid;
|
||||
extern int64_t tsSdbRid;
|
||||
extern int32_t tsSdbRid;
|
||||
static SBnMgmt tsBnMgmt;
|
||||
static void bnMonitorDnodeModule();
|
||||
|
||||
|
|
|
@ -271,23 +271,23 @@ static int32_t bnRetrieveScores(SShowObj *pShow, char *data, int32_t rows, void
|
|||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(float *)pWrite = systemScore;
|
||||
*(float *)pWrite = (float)systemScore;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(float *)pWrite = pDnode->customScore;
|
||||
*(float *)pWrite = (float)pDnode->customScore;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(float *)pWrite = (int32_t)moduleScore;
|
||||
*(float *)pWrite = (float)moduleScore;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(float *)pWrite = (int32_t)vnodeScore;
|
||||
*(float *)pWrite = (float)vnodeScore;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(float *)pWrite = (int32_t)(vnodeScore + moduleScore + pDnode->customScore + systemScore);
|
||||
*(float *)pWrite = (float)(vnodeScore + moduleScore + pDnode->customScore + systemScore);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
|
|
|
@ -119,13 +119,13 @@ static void bnProcessTimer(void *handle, void *tmrId) {
|
|||
}
|
||||
}
|
||||
|
||||
void bnStartTimer(int64_t mseconds) {
|
||||
void bnStartTimer(int32_t mseconds) {
|
||||
if (tsBnThread.stop) return;
|
||||
|
||||
bool updateSoon = (mseconds != -1);
|
||||
if (updateSoon) {
|
||||
mTrace("balance function will be called after %" PRId64 " ms", mseconds);
|
||||
taosTmrReset(bnProcessTimer, mseconds, (void *)mseconds, tsMnodeTmr, &tsBnThread.timer);
|
||||
mTrace("balance function will be called after %d ms", mseconds);
|
||||
taosTmrReset(bnProcessTimer, mseconds, (void *)(int64_t)mseconds, tsMnodeTmr, &tsBnThread.timer);
|
||||
} else {
|
||||
taosTmrReset(bnProcessTimer, tsStatusInterval * 1000, NULL, tsMnodeTmr, &tsBnThread.timer);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,28 @@ IF (TD_LINUX)
|
|||
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
|
||||
ELSEIF (TD_DARWIN)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux)
|
||||
|
||||
# set the static lib name
|
||||
ADD_LIBRARY(taos_static STATIC ${SRC})
|
||||
TARGET_LINK_LIBRARIES(taos_static common query trpc tutil pthread m)
|
||||
SET_TARGET_PROPERTIES(taos_static PROPERTIES OUTPUT_NAME "taos_static")
|
||||
SET_TARGET_PROPERTIES(taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
|
||||
# generate dynamic library (*.dylib)
|
||||
ADD_LIBRARY(taos SHARED ${SRC})
|
||||
TARGET_LINK_LIBRARIES(taos common query trpc tutil pthread m)
|
||||
SET_TARGET_PROPERTIES(taos PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
|
||||
#set version of .dylib
|
||||
#VERSION dylib version
|
||||
#SOVERSION dylib version
|
||||
#MESSAGE(STATUS "build version ${TD_VER_NUMBER}")
|
||||
SET_TARGET_PROPERTIES(taos PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1)
|
||||
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
|
||||
ELSEIF (TD_WINDOWS)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows/win32)
|
||||
|
@ -49,12 +71,12 @@ ELSEIF (TD_DARWIN)
|
|||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux)
|
||||
|
||||
ADD_LIBRARY(taos_static STATIC ${SRC})
|
||||
TARGET_LINK_LIBRARIES(taos_static trpc tutil pthread m)
|
||||
TARGET_LINK_LIBRARIES(taos_static query trpc tutil pthread m)
|
||||
SET_TARGET_PROPERTIES(taos_static PROPERTIES OUTPUT_NAME "taos_static")
|
||||
|
||||
# generate dynamic library (*.dylib)
|
||||
ADD_LIBRARY(taos SHARED ${SRC})
|
||||
TARGET_LINK_LIBRARIES(taos trpc tutil pthread m)
|
||||
TARGET_LINK_LIBRARIES(taos query trpc tutil pthread m)
|
||||
|
||||
SET_TARGET_PROPERTIES(taos PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
|
||||
|
|
|
@ -99,14 +99,14 @@ static FORCE_INLINE SQueryInfo* tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t sub
|
|||
}
|
||||
|
||||
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, SName* name, STableMeta* pTableMeta, STableDataBlocks** dataBlocks);
|
||||
void tscDestroyDataBlock(STableDataBlocks* pDataBlock);
|
||||
void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta);
|
||||
void tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf);
|
||||
|
||||
SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, int16_t bytes,
|
||||
uint32_t offset);
|
||||
|
||||
void* tscDestroyBlockArrayList(SArray* pDataBlockList);
|
||||
void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable);
|
||||
void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable, bool removeMeta);
|
||||
|
||||
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock);
|
||||
int32_t tscMergeTableDataBlocks(SSqlObj* pSql, bool freeBlockMap);
|
||||
|
|
|
@ -22,15 +22,15 @@ extern "C" {
|
|||
|
||||
#include "os.h"
|
||||
|
||||
#include "qAggMain.h"
|
||||
#include "taos.h"
|
||||
#include "taosdef.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tarray.h"
|
||||
#include "tglobal.h"
|
||||
#include "tsqlfunction.h"
|
||||
#include "tutil.h"
|
||||
#include "tcache.h"
|
||||
#include "tglobal.h"
|
||||
#include "tref.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#include "qExecutor.h"
|
||||
#include "qSqlparser.h"
|
||||
|
@ -223,6 +223,8 @@ typedef struct SQueryInfo {
|
|||
|
||||
int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
|
||||
int16_t resColumnId; // result column id
|
||||
bool distinctTag; // distinct tag or not
|
||||
|
||||
} SQueryInfo;
|
||||
|
||||
typedef struct {
|
||||
|
@ -411,7 +413,7 @@ void tscRestoreSQLFuncForSTableQuery(SQueryInfo *pQueryInfo);
|
|||
int32_t tscCreateResPointerInfo(SSqlRes *pRes, SQueryInfo *pQueryInfo);
|
||||
void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo);
|
||||
|
||||
void tscResetSqlCmdObj(SSqlCmd *pCmd);
|
||||
void tscResetSqlCmd(SSqlCmd *pCmd, bool removeMeta);
|
||||
|
||||
/**
|
||||
* free query result of the sql object
|
||||
|
|
|
@ -351,7 +351,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
if (pCmd->command == TSDB_SQL_SELECT) {
|
||||
tscDebug("%p redo parse sql string and proceed", pSql);
|
||||
pCmd->parseFinished = false;
|
||||
tscResetSqlCmdObj(pCmd);
|
||||
tscResetSqlCmd(pCmd, true);
|
||||
|
||||
code = tsParseSql(pSql, true);
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
|
|
|
@ -749,7 +749,10 @@ static int32_t tscProcessCurrentUser(SSqlObj *pSql) {
|
|||
|
||||
static int32_t tscProcessCurrentDB(SSqlObj *pSql) {
|
||||
char db[TSDB_DB_NAME_LEN] = {0};
|
||||
|
||||
pthread_mutex_lock(&pSql->pTscObj->mutex);
|
||||
extractDBName(pSql->pTscObj->db, db);
|
||||
pthread_mutex_unlock(&pSql->pTscObj->mutex);
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "tscLocalMerge.h"
|
||||
#include "tscSubquery.h"
|
||||
#include "os.h"
|
||||
#include "qAst.h"
|
||||
#include "texpr.h"
|
||||
#include "tlosertree.h"
|
||||
#include "tscLog.h"
|
||||
#include "tscUtil.h"
|
||||
|
@ -1101,7 +1101,7 @@ static int64_t getNumOfResultLocal(SQueryInfo *pQueryInfo, SQLFunctionCtx *pCtx)
|
|||
* the number of output result is decided by main output
|
||||
*/
|
||||
int32_t functionId = pCtx[j].functionId;
|
||||
if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAGPRJ) {
|
||||
if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TAG) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1183,7 +1183,7 @@ bool needToMerge(SQueryInfo *pQueryInfo, SLocalMerger *pLocalMerge, tFilePage *t
|
|||
int16_t functionId = pLocalMerge->pCtx[0].functionId;
|
||||
|
||||
// todo opt performance
|
||||
if ((/*functionId == TSDB_FUNC_PRJ || */functionId == TSDB_FUNC_ARITHM) || (tscIsProjectionQueryOnSTable(pQueryInfo, 0))) { // column projection query
|
||||
if ((/*functionId == TSDB_FUNC_PRJ || */functionId == TSDB_FUNC_ARITHM) || (tscIsProjectionQueryOnSTable(pQueryInfo, 0) && pQueryInfo->distinctTag == false)) { // column projection query
|
||||
ret = 1; // disable merge procedure
|
||||
} else {
|
||||
tOrderDescriptor *pDesc = pLocalMerge->pDesc;
|
||||
|
|
|
@ -905,6 +905,13 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
|||
return tscInvalidSQLErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z);
|
||||
}
|
||||
|
||||
index = 0;
|
||||
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
||||
sql += index;
|
||||
if (sToken.type != TK_LP) {
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, NULL, sToken.z);
|
||||
}
|
||||
|
||||
SKVRowBuilder kvRowBuilder = {0};
|
||||
if (tdInitKVRowBuilder(&kvRowBuilder) < 0) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
@ -1036,11 +1043,7 @@ static int32_t validateDataSource(SSqlCmd *pCmd, int8_t type, const char *sql) {
|
|||
}
|
||||
|
||||
/**
|
||||
* usage: insert into table1 values() () table2 values()()
|
||||
*
|
||||
* @param str
|
||||
* @param acct
|
||||
* @param db
|
||||
* parse insert sql
|
||||
* @param pSql
|
||||
* @return
|
||||
*/
|
||||
|
@ -1343,10 +1346,11 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
|
|||
// make a backup as tsParseInsertSql may modify the string
|
||||
char* sqlstr = strdup(pSql->sqlstr);
|
||||
ret = tsParseInsertSql(pSql);
|
||||
if (sqlstr == NULL || pSql->parseRetry >= 1 || ret != TSDB_CODE_TSC_INVALID_SQL) {
|
||||
if ((sqlstr == NULL) || (pSql->parseRetry >= 1) ||
|
||||
(ret != TSDB_CODE_TSC_SQL_SYNTAX_ERROR && ret != TSDB_CODE_TSC_INVALID_SQL)) {
|
||||
free(sqlstr);
|
||||
} else {
|
||||
tscResetSqlCmdObj(pCmd);
|
||||
tscResetSqlCmd(pCmd, true);
|
||||
free(pSql->sqlstr);
|
||||
pSql->sqlstr = sqlstr;
|
||||
pSql->parseRetry++;
|
||||
|
@ -1358,7 +1362,7 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
|
|||
SSqlInfo SQLInfo = qSQLParse(pSql->sqlstr);
|
||||
ret = tscToSQLCmd(pSql, &SQLInfo);
|
||||
if (ret == TSDB_CODE_TSC_INVALID_SQL && pSql->parseRetry == 0 && SQLInfo.type == TSDB_SQL_NULL) {
|
||||
tscResetSqlCmdObj(pCmd);
|
||||
tscResetSqlCmd(pCmd, true);
|
||||
pSql->parseRetry++;
|
||||
ret = tscToSQLCmd(pSql, &SQLInfo);
|
||||
}
|
||||
|
@ -1551,12 +1555,13 @@ void tscImportDataFromFile(SSqlObj *pSql) {
|
|||
SSqlObj *pNew = createSubqueryObj(pSql, 0, parseFileSendDataBlock, pSupporter, TSDB_SQL_INSERT, NULL);
|
||||
pCmd->count = 1;
|
||||
|
||||
FILE *fp = fopen(pCmd->payload, "r");
|
||||
FILE *fp = fopen(pCmd->payload, "rb");
|
||||
if (fp == NULL) {
|
||||
pSql->res.code = TAOS_SYSTEM_ERROR(errno);
|
||||
tscError("%p failed to open file %s to load data from file, code:%s", pSql, pCmd->payload, tstrerror(pSql->res.code));
|
||||
|
||||
tfree(pSupporter);
|
||||
taos_free_result(pNew);
|
||||
tscAsyncResultOnError(pSql);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,14 +13,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __APPLE__
|
||||
#define _BSD_SOURCE
|
||||
#define _XOPEN_SOURCE 500
|
||||
#define _DEFAULT_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif // __APPLE__
|
||||
|
||||
#include "os.h"
|
||||
#include "ttype.h"
|
||||
#include "qAst.h"
|
||||
#include "texpr.h"
|
||||
#include "taos.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tcompare.h"
|
||||
|
@ -41,7 +43,7 @@
|
|||
#define COLUMN_INDEX_INITIAL_VAL (-3)
|
||||
#define COLUMN_INDEX_INITIALIZER \
|
||||
{ COLUMN_INDEX_INITIAL_VAL, COLUMN_INDEX_INITIAL_VAL }
|
||||
#define COLUMN_INDEX_VALIDE(index) (((index).tableIndex >= 0) && ((index).columnIndex >= TSDB_TBNAME_COLUMN_INDEX))
|
||||
#define COLUMN_INDEX_VALIDE(index) (((index).tableIndex >= 0) && ((index).columnIndex >= TSDB_BLOCK_DIST_COLUMN_INDEX))
|
||||
#define TBNAME_LIST_SEP ","
|
||||
|
||||
typedef struct SColumnList { // todo refactor
|
||||
|
@ -60,7 +62,7 @@ static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo);
|
|||
static char* getAccountId(SSqlObj* pSql);
|
||||
|
||||
static bool has(SArray* pFieldList, int32_t startIdx, const char* name);
|
||||
static char* getCurrentDBName(SSqlObj* pSql);
|
||||
static char* cloneCurrentDBName(SSqlObj* pSql);
|
||||
static bool hasSpecifyDB(SStrToken* pTableName);
|
||||
static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd);
|
||||
static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pCmd);
|
||||
|
@ -902,12 +904,16 @@ int32_t parseSlidingClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
|||
|
||||
int32_t tscSetTableFullName(STableMetaInfo* pTableMetaInfo, SStrToken* pTableName, SSqlObj* pSql) {
|
||||
const char* msg1 = "name too long";
|
||||
const char* msg2 = "acctId too long";
|
||||
|
||||
SSqlCmd* pCmd = &pSql->cmd;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (hasSpecifyDB(pTableName)) { // db has been specified in sql string so we ignore current db path
|
||||
tNameSetAcctId(&pTableMetaInfo->name, getAccountId(pSql));
|
||||
code = tNameSetAcctId(&pTableMetaInfo->name, getAccountId(pSql));
|
||||
if (code != 0) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
}
|
||||
|
||||
char name[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
strncpy(name, pTableName->z, pTableName->n);
|
||||
|
@ -917,16 +923,19 @@ int32_t tscSetTableFullName(STableMetaInfo* pTableMetaInfo, SStrToken* pTableNam
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
} else { // get current DB name first, and then set it into path
|
||||
char* t = getCurrentDBName(pSql);
|
||||
char* t = cloneCurrentDBName(pSql);
|
||||
if (strlen(t) == 0) {
|
||||
return TSDB_CODE_TSC_DB_NOT_SELECTED;
|
||||
}
|
||||
|
||||
code = tNameFromString(&pTableMetaInfo->name, t, T_NAME_ACCT | T_NAME_DB);
|
||||
if (code != 0) {
|
||||
free(t);
|
||||
return TSDB_CODE_TSC_DB_NOT_SELECTED;
|
||||
}
|
||||
|
||||
free(t);
|
||||
|
||||
if (pTableName->n >= TSDB_TABLE_NAME_LEN) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
@ -1240,8 +1249,12 @@ static bool has(SArray* pFieldList, int32_t startIdx, const char* name) {
|
|||
|
||||
static char* getAccountId(SSqlObj* pSql) { return pSql->pTscObj->acctId; }
|
||||
|
||||
static char* getCurrentDBName(SSqlObj* pSql) {
|
||||
return pSql->pTscObj->db;
|
||||
static char* cloneCurrentDBName(SSqlObj* pSql) {
|
||||
pthread_mutex_lock(&pSql->pTscObj->mutex);
|
||||
char *p = strdup(pSql->pTscObj->db);
|
||||
pthread_mutex_unlock(&pSql->pTscObj->mutex);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/* length limitation, strstr cannot be applied */
|
||||
|
@ -1354,7 +1367,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
|
|||
int32_t ret = exprTreeFromSqlExpr(pCmd, &pNode, pItem->pNode, pQueryInfo, colList, NULL);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(colList);
|
||||
tExprTreeDestroy(&pNode, NULL);
|
||||
tExprTreeDestroy(pNode, NULL);
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
}
|
||||
|
||||
|
@ -1363,9 +1376,9 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
|
|||
for(int32_t k = 0; k < numOfNode; ++k) {
|
||||
SColIndex* pIndex = taosArrayGet(colList, k);
|
||||
if (TSDB_COL_IS_TAG(pIndex->flag)) {
|
||||
tExprTreeDestroy(&pNode, NULL);
|
||||
tExprTreeDestroy(pNode, NULL);
|
||||
taosArrayDestroy(colList);
|
||||
tExprTreeDestroy(&pNode, NULL);
|
||||
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||
}
|
||||
}
|
||||
|
@ -1392,7 +1405,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
|
|||
|
||||
tbufCloseWriter(&bw);
|
||||
taosArrayDestroy(colList);
|
||||
tExprTreeDestroy(&pNode, NULL);
|
||||
tExprTreeDestroy(pNode, NULL);
|
||||
} else {
|
||||
columnList.num = 0;
|
||||
columnList.ids[0] = (SColumnIndex) {0, 0};
|
||||
|
@ -1424,7 +1437,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
|
|||
|
||||
int32_t ret = exprTreeFromSqlExpr(pCmd, &pArithExprInfo->pExpr, pItem->pNode, pQueryInfo, NULL, &pArithExprInfo->uid);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
tExprTreeDestroy(&pArithExprInfo->pExpr, NULL);
|
||||
tExprTreeDestroy(pArithExprInfo->pExpr, NULL);
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "invalid expression in select clause");
|
||||
}
|
||||
|
||||
|
@ -1501,23 +1514,39 @@ static void addPrimaryTsColIntoResult(SQueryInfo* pQueryInfo) {
|
|||
pQueryInfo->type |= TSDB_QUERY_TYPE_PROJECTION_QUERY;
|
||||
}
|
||||
|
||||
bool isValidDistinctSql(SQueryInfo* pQueryInfo) {
|
||||
if (pQueryInfo == NULL) {
|
||||
return false;
|
||||
}
|
||||
if ((pQueryInfo->type & TSDB_QUERY_TYPE_STABLE_QUERY) != TSDB_QUERY_TYPE_STABLE_QUERY) {
|
||||
return false;
|
||||
}
|
||||
if (tscQueryTags(pQueryInfo) && tscSqlExprNumOfExprs(pQueryInfo) == 1){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSelection, bool isSTable, bool joinQuery, bool intervalQuery) {
|
||||
assert(pSelection != NULL && pCmd != NULL);
|
||||
|
||||
const char* msg2 = "functions can not be mixed up";
|
||||
const char* msg3 = "not support query expression";
|
||||
const char* msg5 = "invalid function name";
|
||||
const char* msg6 = "only support distinct one tag";
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex);
|
||||
|
||||
if (pQueryInfo->colList == NULL) {
|
||||
pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES);
|
||||
}
|
||||
|
||||
bool hasDistinct = false;
|
||||
for (int32_t i = 0; i < pSelection->nExpr; ++i) {
|
||||
int32_t outputIndex = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
|
||||
tSqlExprItem* pItem = &pSelection->a[i];
|
||||
|
||||
if (hasDistinct == false) {
|
||||
hasDistinct = (pItem->distinct == true);
|
||||
}
|
||||
// project on all fields
|
||||
int32_t optr = pItem->pNode->nSQLOptr;
|
||||
|
||||
|
@ -1551,6 +1580,13 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
|
|||
}
|
||||
}
|
||||
|
||||
if (hasDistinct == true) {
|
||||
if (!isValidDistinctSql(pQueryInfo)) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
|
||||
}
|
||||
pQueryInfo->distinctTag = true;
|
||||
}
|
||||
|
||||
// there is only one user-defined column in the final result field, add the timestamp column.
|
||||
size_t numOfSrcCols = taosArrayGetSize(pQueryInfo->colList);
|
||||
if (numOfSrcCols <= 0 && !tscQueryTags(pQueryInfo)) {
|
||||
|
@ -1727,6 +1763,9 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
|
|||
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
SSchema colSchema = tGetTableNameColumnSchema();
|
||||
tscAddSpecialColumnForSelect(pQueryInfo, startPos, TSDB_FUNC_TAGPRJ, &index, &colSchema, TSDB_COL_TAG);
|
||||
} else if (index.columnIndex == TSDB_BLOCK_DIST_COLUMN_INDEX) {
|
||||
SSchema colSchema = tGetBlockDistColumnSchema();
|
||||
tscAddSpecialColumnForSelect(pQueryInfo, startPos, TSDB_FUNC_PRJ, &index, &colSchema, TSDB_COL_TAG);
|
||||
} else {
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
|
||||
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
|
||||
|
@ -2194,6 +2233,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
|
|||
if (getColumnIndexByName(pCmd, &pParamElem->pNode->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||
}
|
||||
|
||||
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
|
||||
}
|
||||
|
@ -2402,6 +2442,14 @@ static bool isTablenameToken(SStrToken* token) {
|
|||
|
||||
return (strncasecmp(TSQL_TBNAME_L, tmpToken.z, tmpToken.n) == 0 && tmpToken.n == strlen(TSQL_TBNAME_L));
|
||||
}
|
||||
static bool isTableBlockDistToken(SStrToken* token) {
|
||||
SStrToken tmpToken = *token;
|
||||
SStrToken tableToken = {0};
|
||||
|
||||
extractTableNameFromToken(&tmpToken, &tableToken);
|
||||
|
||||
return (strncasecmp(TSQL_BLOCK_DIST, tmpToken.z, tmpToken.n) == 0 && tmpToken.n == strlen(TSQL_BLOCK_DIST_L));
|
||||
}
|
||||
|
||||
static int16_t doGetColumnIndex(SQueryInfo* pQueryInfo, int32_t index, SStrToken* pToken) {
|
||||
STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, index)->pTableMeta;
|
||||
|
@ -2431,6 +2479,8 @@ int32_t doGetColumnIndexByName(SSqlCmd* pCmd, SStrToken* pToken, SQueryInfo* pQu
|
|||
|
||||
if (isTablenameToken(pToken)) {
|
||||
pIndex->columnIndex = TSDB_TBNAME_COLUMN_INDEX;
|
||||
} else if (isTableBlockDistToken(pToken)) {
|
||||
pIndex->columnIndex = TSDB_BLOCK_DIST_COLUMN_INDEX;
|
||||
} else if (strncasecmp(pToken->z, DEFAULT_PRIMARY_TIMESTAMP_COL_NAME, pToken->n) == 0) {
|
||||
pIndex->columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX;
|
||||
} else {
|
||||
|
@ -2672,7 +2722,6 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -4260,6 +4309,77 @@ static void doAddJoinTagsColumnsIntoTagList(SSqlCmd* pCmd, SQueryInfo* pQueryInf
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t validateTagCondExpr(SSqlCmd* pCmd, tExprNode *p) {
|
||||
const char *msg1 = "invalid tag operator";
|
||||
const char* msg2 = "not supported filter condition";
|
||||
|
||||
do {
|
||||
if (p->nodeType != TSQL_NODE_EXPR) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!p->_node.pLeft || !p->_node.pRight) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (IS_ARITHMETIC_OPTR(p->_node.optr)) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
if (!IS_RELATION_OPTR(p->_node.optr)) {
|
||||
break;
|
||||
}
|
||||
|
||||
tVariant * vVariant = NULL;
|
||||
int32_t schemaType = -1;
|
||||
|
||||
if (p->_node.pLeft->nodeType == TSQL_NODE_VALUE && p->_node.pRight->nodeType == TSQL_NODE_COL) {
|
||||
if (!p->_node.pRight->pSchema) {
|
||||
break;
|
||||
}
|
||||
|
||||
vVariant = p->_node.pLeft->pVal;
|
||||
schemaType = p->_node.pRight->pSchema->type;
|
||||
} else if (p->_node.pLeft->nodeType == TSQL_NODE_COL && p->_node.pRight->nodeType == TSQL_NODE_VALUE) {
|
||||
if (!p->_node.pLeft->pSchema) {
|
||||
break;
|
||||
}
|
||||
|
||||
vVariant = p->_node.pRight->pVal;
|
||||
schemaType = p->_node.pLeft->pSchema->type;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if (schemaType >= TSDB_DATA_TYPE_TINYINT && schemaType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
schemaType = TSDB_DATA_TYPE_BIGINT;
|
||||
} else if (schemaType == TSDB_DATA_TYPE_FLOAT || schemaType == TSDB_DATA_TYPE_DOUBLE) {
|
||||
schemaType = TSDB_DATA_TYPE_DOUBLE;
|
||||
}
|
||||
|
||||
int32_t retVal = TSDB_CODE_SUCCESS;
|
||||
if (schemaType == TSDB_DATA_TYPE_BINARY) {
|
||||
char *tmp = calloc(1, vVariant->nLen + TSDB_NCHAR_SIZE);
|
||||
retVal = tVariantDump(vVariant, tmp, schemaType, false);
|
||||
free(tmp);
|
||||
} else if (schemaType == TSDB_DATA_TYPE_NCHAR) {
|
||||
// pRight->val.nLen + 1 is larger than the actual nchar string length
|
||||
char *tmp = calloc(1, (vVariant->nLen + 1) * TSDB_NCHAR_SIZE);
|
||||
retVal = tVariantDump(vVariant, tmp, schemaType, false);
|
||||
free(tmp);
|
||||
} else {
|
||||
double tmp;
|
||||
retVal = tVariantDump(vVariant, (char*)&tmp, schemaType, false);
|
||||
}
|
||||
|
||||
if (retVal != TSDB_CODE_SUCCESS) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
}
|
||||
}while (0);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondExpr* pCondExpr, tSQLExpr** pExpr) {
|
||||
int32_t ret = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -4302,13 +4422,21 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
|
|||
tsSetSTableQueryCond(&pQueryInfo->tagCond, uid, &bw);
|
||||
doCompactQueryExpr(pExpr);
|
||||
|
||||
if (ret == TSDB_CODE_SUCCESS) {
|
||||
ret = validateTagCondExpr(pCmd, p);
|
||||
}
|
||||
|
||||
tSqlExprDestroy(p1);
|
||||
tExprTreeDestroy(&p, NULL);
|
||||
tExprTreeDestroy(p, NULL);
|
||||
|
||||
taosArrayDestroy(colList);
|
||||
if (pQueryInfo->tagCond.pCond != NULL && taosArrayGetSize(pQueryInfo->tagCond.pCond) > 0 && !UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "filter on tag not supported for normal table");
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pCondExpr->pTagCond = NULL;
|
||||
|
@ -4524,10 +4652,10 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
}
|
||||
|
||||
size_t size = tscNumOfFields(pQueryInfo);
|
||||
size_t numOfFields = tscNumOfFields(pQueryInfo);
|
||||
|
||||
if (pQueryInfo->fillVal == NULL) {
|
||||
pQueryInfo->fillVal = calloc(size, sizeof(int64_t));
|
||||
pQueryInfo->fillVal = calloc(numOfFields, sizeof(int64_t));
|
||||
if (pQueryInfo->fillVal == NULL) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -4537,7 +4665,7 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery
|
|||
pQueryInfo->fillType = TSDB_FILL_NONE;
|
||||
} else if (strncasecmp(pItem->pVar.pz, "null", 4) == 0 && pItem->pVar.nLen == 4) {
|
||||
pQueryInfo->fillType = TSDB_FILL_NULL;
|
||||
for (int32_t i = START_INTERPO_COL_IDX; i < size; ++i) {
|
||||
for (int32_t i = START_INTERPO_COL_IDX; i < numOfFields; ++i) {
|
||||
TAOS_FIELD* pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
setNull((char*)&pQueryInfo->fillVal[i], pField->type, pField->bytes);
|
||||
}
|
||||
|
@ -4551,7 +4679,7 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery
|
|||
pQueryInfo->fillType = TSDB_FILL_SET_VALUE;
|
||||
|
||||
size_t num = taosArrayGetSize(pFillToken);
|
||||
if (num == 1) {
|
||||
if (num == 1) { // no actual value, return with error code
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
|
@ -4562,11 +4690,11 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery
|
|||
if (tscIsPointInterpQuery(pQueryInfo)) {
|
||||
startPos = 0;
|
||||
|
||||
if (numOfFillVal > size) {
|
||||
numOfFillVal = (int32_t)size;
|
||||
if (numOfFillVal > numOfFields) {
|
||||
numOfFillVal = (int32_t)numOfFields;
|
||||
}
|
||||
} else {
|
||||
numOfFillVal = (int16_t)((num > (int32_t)size) ? (int32_t)size : num);
|
||||
numOfFillVal = (int16_t)((num > (int32_t)numOfFields) ? (int32_t)numOfFields : num);
|
||||
}
|
||||
|
||||
int32_t j = 1;
|
||||
|
@ -4586,10 +4714,10 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery
|
|||
}
|
||||
}
|
||||
|
||||
if ((num < size) || ((num - 1 < size) && (tscIsPointInterpQuery(pQueryInfo)))) {
|
||||
if ((num < numOfFields) || ((num - 1 < numOfFields) && (tscIsPointInterpQuery(pQueryInfo)))) {
|
||||
tVariantListItem* lastItem = taosArrayGetLast(pFillToken);
|
||||
|
||||
for (int32_t i = numOfFillVal; i < size; ++i) {
|
||||
for (int32_t i = numOfFillVal; i < numOfFields; ++i) {
|
||||
TAOS_FIELD* pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
if (pField->type == TSDB_DATA_TYPE_BINARY || pField->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
|
@ -4640,6 +4768,12 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
|||
setDefaultOrderInfo(pQueryInfo);
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
|
||||
if (pQueryInfo->distinctTag == true) {
|
||||
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||
pQueryInfo->order.orderColId = 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (pQuerySql->pSortOrder == NULL) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -1251,7 +1251,9 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||
|
||||
if (tNameIsEmpty(&pTableMetaInfo->name)) {
|
||||
pthread_mutex_lock(&pObj->mutex);
|
||||
tstrncpy(pShowMsg->db, pObj->db, sizeof(pShowMsg->db));
|
||||
pthread_mutex_unlock(&pObj->mutex);
|
||||
} else {
|
||||
tNameGetFullDbName(&pTableMetaInfo->name, pShowMsg->db);
|
||||
}
|
||||
|
@ -1611,9 +1613,14 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
// TODO refactor full_name
|
||||
char *db; // ugly code to move the space
|
||||
|
||||
pthread_mutex_lock(&pObj->mutex);
|
||||
db = strstr(pObj->db, TS_PATH_DELIMITER);
|
||||
|
||||
db = (db == NULL) ? pObj->db : db + 1;
|
||||
tstrncpy(pConnect->db, db, sizeof(pConnect->db));
|
||||
pthread_mutex_unlock(&pObj->mutex);
|
||||
|
||||
tstrncpy(pConnect->clientVersion, version, sizeof(pConnect->clientVersion));
|
||||
tstrncpy(pConnect->msgVersion, "", sizeof(pConnect->msgVersion));
|
||||
|
||||
|
@ -2131,10 +2138,13 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
|
|||
|
||||
SConnectRsp *pConnect = (SConnectRsp *)pRes->pRsp;
|
||||
tstrncpy(pObj->acctId, pConnect->acctId, sizeof(pObj->acctId)); // copy acctId from response
|
||||
|
||||
pthread_mutex_lock(&pObj->mutex);
|
||||
int32_t len = sprintf(temp, "%s%s%s", pObj->acctId, TS_PATH_DELIMITER, pObj->db);
|
||||
|
||||
assert(len <= sizeof(pObj->db));
|
||||
tstrncpy(pObj->db, temp, sizeof(pObj->db));
|
||||
pthread_mutex_unlock(&pObj->mutex);
|
||||
|
||||
if (pConnect->epSet.numOfEps > 0) {
|
||||
tscEpSetHtons(&pConnect->epSet);
|
||||
|
@ -2161,11 +2171,18 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
|
|||
int tscProcessUseDbRsp(SSqlObj *pSql) {
|
||||
STscObj * pObj = pSql->pTscObj;
|
||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
||||
return tNameExtractFullName(&pTableMetaInfo->name, pObj->db);
|
||||
|
||||
pthread_mutex_lock(&pObj->mutex);
|
||||
int ret = tNameExtractFullName(&pTableMetaInfo->name, pObj->db);
|
||||
pthread_mutex_unlock(&pObj->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int tscProcessDropDbRsp(SSqlObj *pSql) {
|
||||
pSql->pTscObj->db[0] = 0;
|
||||
//TODO LOCK DB WHEN MODIFY IT
|
||||
//pSql->pTscObj->db[0] = 0;
|
||||
|
||||
taosHashEmpty(tscTableMetaInfo);
|
||||
return 0;
|
||||
}
|
||||
|
@ -2228,6 +2245,8 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
|
|||
SSqlRes *pRes = &pSql->res;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
assert(pRes->rspLen >= sizeof(SRetrieveTableRsp));
|
||||
|
||||
SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *)pRes->pRsp;
|
||||
if (pRetrieve == NULL) {
|
||||
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "hash.h"
|
||||
#include "os.h"
|
||||
#include "qAst.h"
|
||||
#include "texpr.h"
|
||||
#include "tkey.h"
|
||||
#include "tcache.h"
|
||||
#include "tnote.h"
|
||||
|
@ -110,6 +110,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
|
|||
rpcClose(pDnodeConn);
|
||||
free(pObj->tscCorMgmtEpSet);
|
||||
free(pObj);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(pObj->tscCorMgmtEpSet, &corMgmtEpSet, sizeof(SRpcCorEpSet));
|
||||
|
||||
|
@ -294,6 +295,10 @@ void taos_close(TAOS *taos) {
|
|||
|
||||
tscDebug("%p HB is freed", pHb);
|
||||
taosReleaseRef(tscObjRef, pHb->self);
|
||||
#ifdef __APPLE__
|
||||
// to satisfy later tsem_destroy in taos_free_result
|
||||
tsem_init(&pHb->rspSem, 0, 0);
|
||||
#endif // __APPLE__
|
||||
taos_free_result(pHb);
|
||||
}
|
||||
}
|
||||
|
@ -936,7 +941,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
|
|||
|
||||
static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t tblListLen) {
|
||||
// must before clean the sqlcmd object
|
||||
tscResetSqlCmdObj(&pSql->cmd);
|
||||
tscResetSqlCmd(&pSql->cmd, false);
|
||||
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
|
|
|
@ -191,9 +191,10 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
|||
|
||||
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0);
|
||||
|
||||
assert(0);
|
||||
// char* name = pTableMetaInfo->name;
|
||||
// taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
|
||||
char name[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
tNameExtractFullName(&pTableMetaInfo->name, name);
|
||||
|
||||
taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
|
||||
pTableMetaInfo->vgroupList = tscVgroupInfoClear(pTableMetaInfo->vgroupList);
|
||||
|
||||
tscSetRetryTimer(pStream, pStream->pSql, retryDelay);
|
||||
|
@ -292,8 +293,8 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
pStream->stime += 1;
|
||||
}
|
||||
|
||||
// tscDebug("%p stream:%p, query on:%s, fetch result completed, fetched rows:%" PRId64, pSql, pStream, pTableMetaInfo->name,
|
||||
// pStream->numOfRes);
|
||||
tscDebug("%p stream:%p, query on:%s, fetch result completed, fetched rows:%" PRId64, pSql, pStream, tNameGetTableName(&pTableMetaInfo->name),
|
||||
pStream->numOfRes);
|
||||
|
||||
tfree(pTableMetaInfo->pTableMeta);
|
||||
|
||||
|
@ -556,8 +557,8 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) {
|
|||
|
||||
taosTmrReset(tscProcessStreamTimer, (int32_t)starttime, pStream, tscTmr, &pStream->pTimer);
|
||||
|
||||
// tscDebug("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql,
|
||||
// pStream, pTableMetaInfo->name, pStream->interval.interval, pStream->interval.sliding, starttime, pSql->sqlstr);
|
||||
tscDebug("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql,
|
||||
pStream, tNameGetTableName(&pTableMetaInfo->name), pStream->interval.interval, pStream->interval.sliding, starttime, pSql->sqlstr);
|
||||
}
|
||||
|
||||
void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable) {
|
||||
|
|
|
@ -313,7 +313,7 @@ static int tscLoadSubscriptionProgress(SSub* pSub) {
|
|||
char buf[TSDB_MAX_SQL_LEN];
|
||||
sprintf(buf, "%s/subscribe/%s", tsDataDir, pSub->topic);
|
||||
|
||||
FILE* fp = fopen(buf, "r");
|
||||
FILE* fp = fopen(buf, "rb");
|
||||
if (fp == NULL) {
|
||||
tscDebug("subscription progress file does not exist: %s", pSub->topic);
|
||||
return 1;
|
||||
|
@ -368,7 +368,7 @@ void tscSaveSubscriptionProgress(void* sub) {
|
|||
}
|
||||
|
||||
sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic);
|
||||
FILE* fp = fopen(path, "w+");
|
||||
FILE* fp = fopen(path, "wb+");
|
||||
if (fp == NULL) {
|
||||
tscError("failed to create progress file for subscription: %s", pSub->topic);
|
||||
return;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "os.h"
|
||||
|
||||
#include "qAst.h"
|
||||
#include "texpr.h"
|
||||
#include "qTsbuf.h"
|
||||
#include "tcompare.h"
|
||||
#include "tscLog.h"
|
||||
|
@ -582,13 +582,14 @@ void freeJoinSubqueryObj(SSqlObj* pSql) {
|
|||
pSql->subState.numOfSub = 0;
|
||||
}
|
||||
|
||||
static void quitAllSubquery(SSqlObj* pSqlSub, SSqlObj* pSqlObj, SJoinSupporter* pSupporter) {
|
||||
static int32_t quitAllSubquery(SSqlObj* pSqlSub, SSqlObj* pSqlObj, SJoinSupporter* pSupporter) {
|
||||
if (subAndCheckDone(pSqlSub, pSqlObj, pSupporter->subqueryIndex)) {
|
||||
tscError("%p all subquery return and query failed, global code:%s", pSqlObj, tstrerror(pSqlObj->res.code));
|
||||
freeJoinSubqueryObj(pSqlObj);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
//tscDestroyJoinSupporter(pSupporter);
|
||||
}
|
||||
|
||||
|
@ -835,7 +836,9 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
|
||||
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
|
||||
tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, numOfRows, pParentSql->res.code);
|
||||
quitAllSubquery(pSql, pParentSql, pSupporter);
|
||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
|
||||
|
@ -850,7 +853,9 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex);
|
||||
|
||||
pParentSql->res.code = numOfRows;
|
||||
quitAllSubquery(pSql, pParentSql, pSupporter);
|
||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
return;
|
||||
|
@ -867,7 +872,9 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
tscError("%p failed to malloc memory", pSql);
|
||||
|
||||
pParentSql->res.code = TAOS_SYSTEM_ERROR(errno);
|
||||
quitAllSubquery(pSql, pParentSql, pSupporter);
|
||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
return;
|
||||
|
@ -985,7 +992,9 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
|
||||
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
|
||||
tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, numOfRows, pParentSql->res.code);
|
||||
quitAllSubquery(pSql, pParentSql, pSupporter);
|
||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)){
|
||||
return;
|
||||
}
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
|
||||
|
@ -999,7 +1008,9 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex);
|
||||
|
||||
pParentSql->res.code = numOfRows;
|
||||
quitAllSubquery(pSql, pParentSql, pSupporter);
|
||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)){
|
||||
return;
|
||||
}
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
return;
|
||||
|
@ -1007,14 +1018,16 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
|
||||
if (numOfRows > 0) { // write the compressed timestamp to disk file
|
||||
if(pSupporter->f == NULL) {
|
||||
pSupporter->f = fopen(pSupporter->path, "w");
|
||||
pSupporter->f = fopen(pSupporter->path, "wb");
|
||||
|
||||
if (pSupporter->f == NULL) {
|
||||
tscError("%p failed to create tmp file:%s, reason:%s", pSql, pSupporter->path, strerror(errno));
|
||||
|
||||
pParentSql->res.code = TAOS_SYSTEM_ERROR(errno);
|
||||
|
||||
quitAllSubquery(pSql, pParentSql, pSupporter);
|
||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
|
||||
|
@ -1032,7 +1045,9 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
|
||||
pParentSql->res.code = TAOS_SYSTEM_ERROR(errno);
|
||||
|
||||
quitAllSubquery(pSql, pParentSql, pSupporter);
|
||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)){
|
||||
return;
|
||||
}
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
|
||||
|
@ -1051,7 +1066,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
// continue to retrieve ts-comp data from vnode
|
||||
if (!pRes->completed) {
|
||||
taosGetTmpfilePath("ts-join", pSupporter->path);
|
||||
pSupporter->f = fopen(pSupporter->path, "w");
|
||||
pSupporter->f = fopen(pSupporter->path, "wb");
|
||||
pRes->row = pRes->numOfRows;
|
||||
|
||||
taos_fetch_rows_a(tres, tsCompRetrieveCallback, param);
|
||||
|
@ -1077,7 +1092,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
taosGetTmpfilePath("ts-join", pSupporter->path);
|
||||
|
||||
// TODO check for failure
|
||||
pSupporter->f = fopen(pSupporter->path, "w");
|
||||
pSupporter->f = fopen(pSupporter->path, "wb");
|
||||
pRes->row = pRes->numOfRows;
|
||||
|
||||
// set the callback function
|
||||
|
@ -1129,7 +1144,9 @@ static void joinRetrieveFinalResCallback(void* param, TAOS_RES* tres, int numOfR
|
|||
|
||||
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
|
||||
tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, numOfRows, pParentSql->res.code);
|
||||
quitAllSubquery(pSql, pParentSql, pSupporter);
|
||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
|
||||
|
@ -1472,7 +1489,9 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
|
|||
// retrieve actual query results from vnode during the second stage join subquery
|
||||
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
|
||||
tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, code, pParentSql->res.code);
|
||||
quitAllSubquery(pSql, pParentSql, pSupporter);
|
||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
|
||||
|
@ -1486,7 +1505,10 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
|
|||
tscError("%p abort query, code:%s, global code:%s", pSql, tstrerror(code), tstrerror(pParentSql->res.code));
|
||||
pParentSql->res.code = code;
|
||||
|
||||
quitAllSubquery(pSql, pParentSql, pSupporter);
|
||||
if (quitAllSubquery(pSql, pParentSql, pSupporter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
|
||||
return;
|
||||
|
@ -2441,7 +2463,7 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
|
|||
|
||||
pParentObj->cmd.parseFinished = false;
|
||||
|
||||
tscResetSqlCmdObj(&pParentObj->cmd);
|
||||
tscResetSqlCmd(&pParentObj->cmd, false);
|
||||
|
||||
// in case of insert, redo parsing the sql string and build new submit data block for two reasons:
|
||||
// 1. the table Id(tid & uid) may have been update, the submit block needs to be updated accordingly.
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "tscUtil.h"
|
||||
#include "hash.h"
|
||||
#include "os.h"
|
||||
#include "qAst.h"
|
||||
#include "texpr.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tkey.h"
|
||||
#include "tmd5.h"
|
||||
|
@ -381,7 +381,7 @@ void tscFreeQueryInfo(SSqlCmd* pCmd) {
|
|||
tfree(pCmd->pQueryInfo);
|
||||
}
|
||||
|
||||
void tscResetSqlCmdObj(SSqlCmd* pCmd) {
|
||||
void tscResetSqlCmd(SSqlCmd* pCmd, bool removeMeta) {
|
||||
pCmd->command = 0;
|
||||
pCmd->numOfCols = 0;
|
||||
pCmd->count = 0;
|
||||
|
@ -399,7 +399,7 @@ void tscResetSqlCmdObj(SSqlCmd* pCmd) {
|
|||
pCmd->numOfTables = 0;
|
||||
tfree(pCmd->pTableNameList);
|
||||
|
||||
pCmd->pTableBlockHashList = tscDestroyBlockHashTable(pCmd->pTableBlockHashList);
|
||||
pCmd->pTableBlockHashList = tscDestroyBlockHashTable(pCmd->pTableBlockHashList, removeMeta);
|
||||
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
||||
tscFreeQueryInfo(pCmd);
|
||||
}
|
||||
|
@ -501,7 +501,7 @@ void tscFreeSqlObj(SSqlObj* pSql) {
|
|||
pSql->self = 0;
|
||||
|
||||
tscFreeSqlResult(pSql);
|
||||
tscResetSqlCmdObj(pCmd);
|
||||
tscResetSqlCmd(pCmd, false);
|
||||
|
||||
tfree(pCmd->tagData.data);
|
||||
pCmd->tagData.dataLen = 0;
|
||||
|
@ -515,7 +515,7 @@ void tscFreeSqlObj(SSqlObj* pSql) {
|
|||
free(pSql);
|
||||
}
|
||||
|
||||
void tscDestroyDataBlock(STableDataBlocks* pDataBlock) {
|
||||
void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) {
|
||||
if (pDataBlock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -528,6 +528,13 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock) {
|
|||
tfree(pDataBlock->pTableMeta);
|
||||
}
|
||||
|
||||
if (removeMeta) {
|
||||
char name[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
tNameExtractFullName(&pDataBlock->tableName, name);
|
||||
|
||||
taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
|
||||
}
|
||||
|
||||
tfree(pDataBlock);
|
||||
}
|
||||
|
||||
|
@ -563,21 +570,21 @@ void* tscDestroyBlockArrayList(SArray* pDataBlockList) {
|
|||
size_t size = taosArrayGetSize(pDataBlockList);
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
void* d = taosArrayGetP(pDataBlockList, i);
|
||||
tscDestroyDataBlock(d);
|
||||
tscDestroyDataBlock(d, false);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pDataBlockList);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable) {
|
||||
void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable, bool removeMeta) {
|
||||
if (pBlockHashTable == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STableDataBlocks** p = taosHashIterate(pBlockHashTable, NULL);
|
||||
while(p) {
|
||||
tscDestroyDataBlock(*p);
|
||||
tscDestroyDataBlock(*p, removeMeta);
|
||||
p = taosHashIterate(pBlockHashTable, p);
|
||||
}
|
||||
|
||||
|
@ -791,7 +798,7 @@ static void extractTableNameList(SSqlCmd* pCmd, bool freeBlockMap) {
|
|||
}
|
||||
|
||||
if (freeBlockMap) {
|
||||
pCmd->pTableBlockHashList = tscDestroyBlockHashTable(pCmd->pTableBlockHashList);
|
||||
pCmd->pTableBlockHashList = tscDestroyBlockHashTable(pCmd->pTableBlockHashList, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1047,7 +1054,7 @@ void tscFieldInfoClear(SFieldInfo* pFieldInfo) {
|
|||
SInternalField* pInfo = taosArrayGet(pFieldInfo->internalField, i);
|
||||
|
||||
if (pInfo->pArithExprInfo != NULL) {
|
||||
tExprTreeDestroy(&pInfo->pArithExprInfo->pExpr, NULL);
|
||||
tExprTreeDestroy(pInfo->pArithExprInfo->pExpr, NULL);
|
||||
|
||||
SSqlFuncMsg* pFuncMsg = &pInfo->pArithExprInfo->base;
|
||||
for(int32_t j = 0; j < pFuncMsg->numOfParams; ++j) {
|
||||
|
@ -1080,6 +1087,8 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol
|
|||
// set the correct columnIndex index
|
||||
if (pColIndex->columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
pExpr->colInfo.colId = TSDB_TBNAME_COLUMN_INDEX;
|
||||
} else if (pColIndex->columnIndex == TSDB_BLOCK_DIST_COLUMN_INDEX) {
|
||||
pExpr->colInfo.colId = TSDB_BLOCK_DIST_COLUMN_INDEX;
|
||||
} else if (pColIndex->columnIndex <= TSDB_UD_COLUMN_INDEX) {
|
||||
pExpr->colInfo.colId = pColIndex->columnIndex;
|
||||
} else {
|
||||
|
@ -1496,7 +1505,7 @@ bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId, int32_t
|
|||
return false;
|
||||
}
|
||||
|
||||
if (colId == TSDB_TBNAME_COLUMN_INDEX || (colId <= TSDB_UD_COLUMN_INDEX && numOfParams == 2)) {
|
||||
if (colId == TSDB_TBNAME_COLUMN_INDEX || colId == TSDB_BLOCK_DIST_COLUMN_INDEX || (colId <= TSDB_UD_COLUMN_INDEX && numOfParams == 2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1933,6 +1942,10 @@ SSqlObj* createSimpleSubObj(SSqlObj* pSql, __async_cb_func_t fp, void* param, in
|
|||
}
|
||||
|
||||
if (tscAddSubqueryInfo(pCmd) != TSDB_CODE_SUCCESS) {
|
||||
#ifdef __APPLE__
|
||||
// to satisfy later tsem_destroy in taos_free_result
|
||||
tsem_init(&pNew->rspSem, 0, 0);
|
||||
#endif // __APPLE__
|
||||
tscFreeSqlObj(pNew);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2499,7 +2512,11 @@ bool tscSetSqlOwner(SSqlObj* pSql) {
|
|||
SSqlRes* pRes = &pSql->res;
|
||||
|
||||
// set the sql object owner
|
||||
#ifdef __APPLE__
|
||||
pthread_t threadId = (pthread_t)taosGetSelfPthreadId();
|
||||
#else // __APPLE__
|
||||
uint64_t threadId = taosGetSelfPthreadId();
|
||||
#endif // __APPLE__
|
||||
if (atomic_val_compare_exchange_64(&pSql->owner, 0, threadId) != 0) {
|
||||
pRes->code = TSDB_CODE_QRY_IN_EXEC;
|
||||
return false;
|
||||
|
|
|
@ -29,7 +29,7 @@ extern "C" {
|
|||
|
||||
#define STR_TO_VARSTR(x, str) \
|
||||
do { \
|
||||
VarDataLenT __len = strlen(str); \
|
||||
VarDataLenT __len = (VarDataLenT)strlen(str); \
|
||||
*(VarDataLenT *)(x) = __len; \
|
||||
memcpy(varDataVal(x), (str), __len); \
|
||||
} while (0);
|
||||
|
@ -42,7 +42,7 @@ extern "C" {
|
|||
|
||||
#define STR_WITH_SIZE_TO_VARSTR(x, str, _size) \
|
||||
do { \
|
||||
*(VarDataLenT *)(x) = (_size); \
|
||||
*(VarDataLenT *)(x) = (VarDataLenT)(_size); \
|
||||
memcpy(varDataVal(x), (str), (_size)); \
|
||||
} while (0);
|
||||
|
||||
|
|
|
@ -31,6 +31,15 @@ extern "C" {
|
|||
struct tExprNode;
|
||||
struct SSchema;
|
||||
|
||||
#define QUERY_COND_REL_PREFIX_IN "IN|"
|
||||
#define QUERY_COND_REL_PREFIX_LIKE "LIKE|"
|
||||
|
||||
#define QUERY_COND_REL_PREFIX_IN_LEN 3
|
||||
#define QUERY_COND_REL_PREFIX_LIKE_LEN 5
|
||||
|
||||
typedef bool (*__result_filter_fn_t)(const void *, void *);
|
||||
typedef void (*__do_filter_suppl_fn_t)(void *, void *);
|
||||
|
||||
enum {
|
||||
TSQL_NODE_DUMMY = 0x0,
|
||||
TSQL_NODE_EXPR = 0x1,
|
||||
|
@ -38,9 +47,6 @@ enum {
|
|||
TSQL_NODE_VALUE = 0x4,
|
||||
};
|
||||
|
||||
typedef bool (*__result_filter_fn_t)(const void *, void *);
|
||||
typedef void (*__do_filter_suppl_fn_t)(void *, void *);
|
||||
|
||||
/**
|
||||
* this structure is used to filter data in tags, so the offset of filtered tag column in tagdata string is required
|
||||
*/
|
||||
|
@ -52,12 +58,6 @@ typedef struct tQueryInfo {
|
|||
bool indexed; // indexed columns
|
||||
} tQueryInfo;
|
||||
|
||||
typedef struct SExprTraverseSupp {
|
||||
__result_filter_fn_t nodeFilterFn;
|
||||
__do_filter_suppl_fn_t setupInfoFn;
|
||||
void * pExtInfo;
|
||||
} SExprTraverseSupp;
|
||||
|
||||
typedef struct tExprNode {
|
||||
uint8_t nodeType;
|
||||
union {
|
||||
|
@ -74,19 +74,27 @@ typedef struct tExprNode {
|
|||
};
|
||||
} tExprNode;
|
||||
|
||||
void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
char *(*cb)(void *, const char*, int32_t));
|
||||
typedef struct SExprTraverseSupp {
|
||||
__result_filter_fn_t nodeFilterFn;
|
||||
__do_filter_suppl_fn_t setupInfoFn;
|
||||
void * pExtInfo;
|
||||
} SExprTraverseSupp;
|
||||
|
||||
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
|
||||
|
||||
tExprNode* exprTreeFromBinary(const void* data, size_t size);
|
||||
tExprNode* exprTreeFromTableName(const char* tbnameCond);
|
||||
|
||||
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
|
||||
|
||||
void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *));
|
||||
void tExprTreeDestroy(tExprNode **pExprs, void (*fp)(void*));
|
||||
|
||||
bool exprTreeApplayFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *param);
|
||||
|
||||
typedef void (*_arithmetic_operator_fn_t)(void *left, int32_t numLeft, int32_t leftType, void *right, int32_t numRight,
|
||||
int32_t rightType, void *output, int32_t order);
|
||||
|
||||
void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
char *(*cb)(void *, const char*, int32_t));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -88,8 +88,8 @@ extern int32_t tsMinRowsInFileBlock;
|
|||
extern int32_t tsMaxRowsInFileBlock;
|
||||
extern int16_t tsCommitTime; // seconds
|
||||
extern int32_t tsTimePrecision;
|
||||
extern int16_t tsCompression;
|
||||
extern int16_t tsWAL;
|
||||
extern int8_t tsCompression;
|
||||
extern int8_t tsWAL;
|
||||
extern int32_t tsFsyncPeriod;
|
||||
extern int32_t tsReplications;
|
||||
extern int32_t tsQuorum;
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_NAME_H
|
||||
#define TDENGINE_NAME_H
|
||||
|
||||
|
@ -45,6 +60,8 @@ void extractTableNameFromToken(SStrToken *pToken, SStrToken* pTable);
|
|||
|
||||
SSchema tGetTableNameColumnSchema();
|
||||
|
||||
SSchema tGetBlockDistColumnSchema();
|
||||
|
||||
SSchema tGetUserSpecifiedColumnSchema(tVariant* pVal, SStrToken* exprStr, const char* name);
|
||||
|
||||
bool tscValidateTableNameLength(size_t len);
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
|
||||
#include "os.h"
|
||||
|
||||
#include "qArithmeticOperator.h"
|
||||
#include "ttype.h"
|
||||
#include "tutil.h"
|
||||
#include "tarithoperator.h"
|
||||
|
||||
#define ARRAY_LIST_OP(left, right, _left_type, _right_type, len1, len2, out, op, _res_type, _ord) \
|
||||
{ \
|
|
@ -16,18 +16,15 @@
|
|||
#include "os.h"
|
||||
|
||||
#include "exception.h"
|
||||
#include "qArithmeticOperator.h"
|
||||
#include "qAst.h"
|
||||
#include "taosdef.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tarray.h"
|
||||
#include "tbuffer.h"
|
||||
#include "tcompare.h"
|
||||
#include "tname.h"
|
||||
#include "tschemautil.h"
|
||||
#include "tsdb.h"
|
||||
#include "tskiplist.h"
|
||||
#include "tsqlfunction.h"
|
||||
#include "texpr.h"
|
||||
#include "tarithoperator.h"
|
||||
|
||||
static uint8_t UNUSED_FUNC isQueryOnPrimaryKey(const char *primaryColumnName, const tExprNode *pLeft, const tExprNode *pRight) {
|
||||
if (pLeft->nodeType == TSQL_NODE_COL) {
|
||||
|
@ -102,13 +99,15 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf
|
|||
}
|
||||
}
|
||||
|
||||
void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *)) {
|
||||
static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *));
|
||||
|
||||
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) {
|
||||
if (pNode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pNode->nodeType == TSQL_NODE_EXPR) {
|
||||
tExprTreeDestroy(&pNode, fp);
|
||||
doExprTreeDestroy(&pNode, fp);
|
||||
} else if (pNode->nodeType == TSQL_NODE_VALUE) {
|
||||
tVariantDestroy(pNode->pVal);
|
||||
} else if (pNode->nodeType == TSQL_NODE_COL) {
|
||||
|
@ -118,14 +117,14 @@ void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *)) {
|
|||
free(pNode);
|
||||
}
|
||||
|
||||
void tExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
|
||||
static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
|
||||
if (*pExpr == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((*pExpr)->nodeType == TSQL_NODE_EXPR) {
|
||||
tExprTreeDestroy(&(*pExpr)->_node.pLeft, fp);
|
||||
tExprTreeDestroy(&(*pExpr)->_node.pRight, fp);
|
||||
doExprTreeDestroy(&(*pExpr)->_node.pLeft, fp);
|
||||
doExprTreeDestroy(&(*pExpr)->_node.pRight, fp);
|
||||
|
||||
if (fp != NULL) {
|
||||
fp((*pExpr)->_node.info);
|
||||
|
@ -270,8 +269,9 @@ void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
|
|||
}
|
||||
}
|
||||
|
||||
free(pLeftOutput);
|
||||
free(pRightOutput);
|
||||
tfree(pdata);
|
||||
tfree(pLeftOutput);
|
||||
tfree(pRightOutput);
|
||||
}
|
||||
|
||||
static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) {
|
||||
|
@ -342,7 +342,7 @@ static tExprNode* exprTreeFromBinaryImpl(SBufferReader* br) {
|
|||
}
|
||||
|
||||
tExprNode* pExpr = exception_calloc(1, sizeof(tExprNode));
|
||||
CLEANUP_PUSH_VOID_PTR_PTR(true, tExprNodeDestroy, pExpr, NULL);
|
||||
CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, pExpr, NULL);
|
||||
pExpr->nodeType = tbufReadUint8(br);
|
||||
|
||||
if (pExpr->nodeType == TSQL_NODE_VALUE) {
|
||||
|
@ -396,7 +396,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
|
|||
int32_t anchor = CLEANUP_GET_ANCHOR();
|
||||
|
||||
tExprNode* expr = exception_calloc(1, sizeof(tExprNode));
|
||||
CLEANUP_PUSH_VOID_PTR_PTR(true, tExprNodeDestroy, expr, NULL);
|
||||
CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, expr, NULL);
|
||||
|
||||
expr->nodeType = TSQL_NODE_EXPR;
|
||||
|
|
@ -121,8 +121,8 @@ int32_t tsMinRowsInFileBlock = TSDB_DEFAULT_MIN_ROW_FBLOCK;
|
|||
int32_t tsMaxRowsInFileBlock = TSDB_DEFAULT_MAX_ROW_FBLOCK;
|
||||
int16_t tsCommitTime = TSDB_DEFAULT_COMMIT_TIME; // seconds
|
||||
int32_t tsTimePrecision = TSDB_DEFAULT_PRECISION;
|
||||
int16_t tsCompression = TSDB_DEFAULT_COMP_LEVEL;
|
||||
int16_t tsWAL = TSDB_DEFAULT_WAL_LEVEL;
|
||||
int8_t tsCompression = TSDB_DEFAULT_COMP_LEVEL;
|
||||
int8_t tsWAL = TSDB_DEFAULT_WAL_LEVEL;
|
||||
int32_t tsFsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD;
|
||||
int32_t tsReplications = TSDB_DEFAULT_DB_REPLICA_OPTION;
|
||||
int32_t tsQuorum = TSDB_DEFAULT_DB_QUORUM_OPTION;
|
||||
|
@ -137,7 +137,7 @@ int32_t tsTableIncStepPerVnode = TSDB_TABLES_STEP;
|
|||
int8_t tsEnableBalance = 1;
|
||||
int8_t tsAlternativeRole = 0;
|
||||
int32_t tsBalanceInterval = 300; // seconds
|
||||
int32_t tsOfflineThreshold = 86400 * 100; // seconds 10days
|
||||
int32_t tsOfflineThreshold = 86400 * 100; // seconds 100 days
|
||||
int32_t tsMnodeEqualVnodeNum = 4;
|
||||
int8_t tsEnableFlowCtrl = 1;
|
||||
int8_t tsEnableSlaveQuery = 1;
|
||||
|
@ -550,7 +550,7 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 3;
|
||||
cfg.maxValue = 7200000;
|
||||
cfg.maxValue = 86400 * 365;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_SECOND;
|
||||
taosInitConfigOption(cfg);
|
||||
|
@ -758,7 +758,7 @@ static void doInitGlobalConfig(void) {
|
|||
|
||||
cfg.option = "comp";
|
||||
cfg.ptr = &tsCompression;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT16;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT8;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_COMP_LEVEL;
|
||||
cfg.maxValue = TSDB_MAX_COMP_LEVEL;
|
||||
|
@ -768,7 +768,7 @@ static void doInitGlobalConfig(void) {
|
|||
|
||||
cfg.option = "walLevel";
|
||||
cfg.ptr = &tsWAL;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT16;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT8;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_WAL_LEVEL;
|
||||
cfg.maxValue = TSDB_MAX_WAL_LEVEL;
|
||||
|
|
|
@ -39,6 +39,14 @@ SSchema tGetTableNameColumnSchema() {
|
|||
tstrncpy(s.name, TSQL_TBNAME_L, TSDB_COL_NAME_LEN);
|
||||
return s;
|
||||
}
|
||||
SSchema tGetBlockDistColumnSchema() {
|
||||
SSchema s = {0};
|
||||
s.bytes = TSDB_MAX_BINARY_LEN;;
|
||||
s.type = TSDB_DATA_TYPE_BINARY;
|
||||
s.colId = TSDB_BLOCK_DIST_COLUMN_INDEX;
|
||||
tstrncpy(s.name, TSQL_BLOCK_DIST_L, TSDB_COL_NAME_LEN);
|
||||
return s;
|
||||
}
|
||||
|
||||
SSchema tGetUserSpecifiedColumnSchema(tVariant* pVal, SStrToken* exprStr, const char* name) {
|
||||
SSchema s = {0};
|
||||
|
@ -367,6 +375,9 @@ int32_t tNameSetAcctId(SName* dst, const char* acct) {
|
|||
}
|
||||
|
||||
tstrncpy(dst->acctId, acct, tListLen(dst->acctId));
|
||||
|
||||
assert(strlen(dst->acctId) > 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -383,12 +394,14 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
int32_t len = (int32_t)(p - str);
|
||||
|
||||
// too long account id or too long db name
|
||||
if (len >= tListLen(dst->acctId) || len == 0) {
|
||||
if ((len >= tListLen(dst->acctId)) || (len <= 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy (dst->acctId, str, len);
|
||||
dst->acctId[len] = 0;
|
||||
|
||||
assert(strlen(dst->acctId) > 0);
|
||||
}
|
||||
|
||||
if ((type & T_NAME_DB) == T_NAME_DB) {
|
||||
|
@ -404,7 +417,7 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
}
|
||||
|
||||
// too long account id or too long db name
|
||||
if (len >= tListLen(dst->dbname) || len == 0) {
|
||||
if ((len >= tListLen(dst->dbname)) || (len <= 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -419,7 +432,7 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
int32_t len = (int32_t) strlen(start);
|
||||
|
||||
// too long account id or too long db name
|
||||
if (len >= tListLen(dst->tname) || len == 0) {
|
||||
if ((len >= tListLen(dst->tname)) || (len <= 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -430,7 +430,7 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
|
|||
}
|
||||
|
||||
errno = 0;
|
||||
if (IS_SIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||
if (IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || (pVariant->nType == TSDB_DATA_TYPE_BOOL)) {
|
||||
*result = pVariant->i64;
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||
*result = pVariant->u64;
|
||||
|
@ -775,7 +775,7 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
|
|||
return -1;
|
||||
}
|
||||
} else {
|
||||
wcsncpy((wchar_t *)p, pVariant->wpz, pVariant->nLen);
|
||||
memcpy(p, pVariant->wpz, pVariant->nLen);
|
||||
newlen = pVariant->nLen;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED)
|
|||
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
|
||||
POST_BUILD
|
||||
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.17-dist.jar ${LIBRARY_OUTPUT_PATH}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.18-dist.jar ${LIBRARY_OUTPUT_PATH}
|
||||
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
|
||||
COMMENT "build jdbc driver")
|
||||
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.17</version>
|
||||
<version>2.0.18</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>JDBCDriver</name>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.17</version>
|
||||
<version>2.0.18</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>JDBCDriver</name>
|
||||
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
||||
|
@ -74,6 +74,14 @@
|
|||
<version>1.2.58</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -118,7 +126,7 @@
|
|||
<include>**/*Test.java</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/BatchInsertTest.java</exclude>
|
||||
<exclude>**/AppMemoryLeakTest.java</exclude>
|
||||
<exclude>**/FailOverTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
|
|
|
@ -1,28 +1,13 @@
|
|||
/***************************************************************************
|
||||
* 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/>.
|
||||
*****************************************************************************/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
||||
public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrapper {
|
||||
|
||||
private final static String PRODUCT_NAME = "TDengine";
|
||||
private final static String PRODUCT_VESION = "2.0.x.x";
|
||||
private final static String DRIVER_NAME = "taos-jdbcdriver";
|
||||
private final static String DRIVER_VERSION = "2.0.x";
|
||||
private final static int DRIVER_MAJAR_VERSION = 2;
|
||||
private final static int DRIVER_MINOR_VERSION = 0;
|
||||
|
@ -67,9 +52,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
return PRODUCT_VESION;
|
||||
}
|
||||
|
||||
public String getDriverName() throws SQLException {
|
||||
return DRIVER_NAME;
|
||||
}
|
||||
public abstract String getDriverName() throws SQLException;
|
||||
|
||||
public String getDriverVersion() throws SQLException {
|
||||
return DRIVER_VERSION;
|
||||
|
@ -92,6 +75,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
}
|
||||
|
||||
public boolean supportsMixedCaseIdentifiers() throws SQLException {
|
||||
//像database、table这些对象的标识符,在存储时是否采用大小写混合的模式
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -100,7 +84,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
}
|
||||
|
||||
public boolean storesLowerCaseIdentifiers() throws SQLException {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean storesMixedCaseIdentifiers() throws SQLException {
|
||||
|
@ -168,10 +152,12 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
}
|
||||
|
||||
public boolean nullPlusNonNullIsNull() throws SQLException {
|
||||
// null + non-null != null
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean supportsConvert() throws SQLException {
|
||||
// 是否支持转换函数convert
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -196,7 +182,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
}
|
||||
|
||||
public boolean supportsGroupBy() throws SQLException {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean supportsGroupByUnrelated() throws SQLException {
|
||||
|
@ -468,7 +454,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
}
|
||||
|
||||
public int getDefaultTransactionIsolation() throws SQLException {
|
||||
return 0;
|
||||
return Connection.TRANSACTION_NONE;
|
||||
}
|
||||
|
||||
public boolean supportsTransactions() throws SQLException {
|
||||
|
@ -476,6 +462,8 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
}
|
||||
|
||||
public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
|
||||
if (level == Connection.TRANSACTION_NONE)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -495,18 +483,113 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
return false;
|
||||
}
|
||||
|
||||
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
|
||||
throws SQLException {
|
||||
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern,
|
||||
String columnNamePattern) throws SQLException {
|
||||
public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
|
||||
throws SQLException;
|
||||
public abstract ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException;
|
||||
|
||||
protected ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types, Connection connection) throws SQLException {
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
if (catalog == null || catalog.isEmpty())
|
||||
return null;
|
||||
|
||||
ResultSet databases = stmt.executeQuery("show databases");
|
||||
String dbname = null;
|
||||
while (databases.next()) {
|
||||
dbname = databases.getString("name");
|
||||
if (dbname.equalsIgnoreCase(catalog))
|
||||
break;
|
||||
}
|
||||
databases.close();
|
||||
if (dbname == null)
|
||||
return null;
|
||||
|
||||
stmt.execute("use " + dbname);
|
||||
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
|
||||
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
||||
ColumnMetaData col1 = new ColumnMetaData();
|
||||
col1.setColIndex(1);
|
||||
col1.setColName("TABLE_CAT");
|
||||
col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col1);
|
||||
ColumnMetaData col2 = new ColumnMetaData();
|
||||
col2.setColIndex(2);
|
||||
col2.setColName("TABLE_SCHEM");
|
||||
col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col2);
|
||||
ColumnMetaData col3 = new ColumnMetaData();
|
||||
col3.setColIndex(3);
|
||||
col3.setColName("TABLE_NAME");
|
||||
col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col3);
|
||||
ColumnMetaData col4 = new ColumnMetaData();
|
||||
col4.setColIndex(4);
|
||||
col4.setColName("TABLE_TYPE");
|
||||
col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col4);
|
||||
ColumnMetaData col5 = new ColumnMetaData();
|
||||
col5.setColIndex(5);
|
||||
col5.setColName("REMARKS");
|
||||
col5.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col5);
|
||||
ColumnMetaData col6 = new ColumnMetaData();
|
||||
col6.setColIndex(6);
|
||||
col6.setColName("TYPE_CAT");
|
||||
col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col6);
|
||||
ColumnMetaData col7 = new ColumnMetaData();
|
||||
col7.setColIndex(7);
|
||||
col7.setColName("TYPE_SCHEM");
|
||||
col7.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col7);
|
||||
ColumnMetaData col8 = new ColumnMetaData();
|
||||
col8.setColIndex(8);
|
||||
col8.setColName("TYPE_NAME");
|
||||
col8.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col8);
|
||||
ColumnMetaData col9 = new ColumnMetaData();
|
||||
col9.setColIndex(9);
|
||||
col9.setColName("SELF_REFERENCING_COL_NAME");
|
||||
col9.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col9);
|
||||
ColumnMetaData col10 = new ColumnMetaData();
|
||||
col10.setColIndex(10);
|
||||
col10.setColName("REF_GENERATION");
|
||||
col10.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col10);
|
||||
resultSet.setColumnMetaDataList(columnMetaDataList);
|
||||
|
||||
List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
|
||||
ResultSet tables = stmt.executeQuery("show tables");
|
||||
while (tables.next()) {
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData(10);
|
||||
rowData.setString(0, dbname); //table_cat
|
||||
rowData.setString(1, null); //TABLE_SCHEM
|
||||
rowData.setString(2, tables.getString("table_name")); //TABLE_NAME
|
||||
rowData.setString(3, "TABLE"); //TABLE_TYPE
|
||||
rowData.setString(4, ""); //REMARKS
|
||||
rowDataList.add(rowData);
|
||||
}
|
||||
|
||||
ResultSet stables = stmt.executeQuery("show stables");
|
||||
while (stables.next()) {
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData(10);
|
||||
rowData.setString(0, dbname); //TABLE_CAT
|
||||
rowData.setString(1, null); //TABLE_SCHEM
|
||||
rowData.setString(2, stables.getString("name")); //TABLE_NAME
|
||||
rowData.setString(3, "TABLE"); //TABLE_TYPE
|
||||
rowData.setString(4, "STABLE"); //REMARKS
|
||||
rowDataList.add(rowData);
|
||||
}
|
||||
resultSet.setRowDataList(rowDataList);
|
||||
return resultSet;
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet getSchemas() throws SQLException {
|
||||
return getEmptyResultSet();
|
||||
|
@ -516,32 +599,239 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
|
||||
public ResultSet getTableTypes() throws SQLException {
|
||||
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
|
||||
|
||||
// set up ColumnMetaDataList
|
||||
List<ColumnMetaData> columnMetaDataList = new ArrayList<ColumnMetaData>(1);
|
||||
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
||||
ColumnMetaData colMetaData = new ColumnMetaData();
|
||||
colMetaData.setColIndex(0);
|
||||
colMetaData.setColName("TABLE_TYPE");
|
||||
colMetaData.setColSize(10);
|
||||
colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY);
|
||||
colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(colMetaData);
|
||||
resultSet.setColumnMetaDataList(columnMetaDataList);
|
||||
|
||||
// set up rowDataList
|
||||
List<TSDBResultSetRowData> rowDataList = new ArrayList<TSDBResultSetRowData>(2);
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData();
|
||||
List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData(1);
|
||||
rowData.setString(0, "TABLE");
|
||||
rowDataList.add(rowData);
|
||||
rowData = new TSDBResultSetRowData();
|
||||
rowData = new TSDBResultSetRowData(1);
|
||||
rowData.setString(0, "STABLE");
|
||||
rowDataList.add(rowData);
|
||||
|
||||
resultSet.setColumnMetaDataList(columnMetaDataList);
|
||||
resultSet.setRowDataList(rowDataList);
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
public abstract ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;
|
||||
|
||||
protected ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern, Connection conn) {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
if (catalog == null || catalog.isEmpty())
|
||||
return null;
|
||||
|
||||
ResultSet databases = stmt.executeQuery("show databases");
|
||||
String dbname = null;
|
||||
while (databases.next()) {
|
||||
dbname = databases.getString("name");
|
||||
if (dbname.equalsIgnoreCase(catalog))
|
||||
break;
|
||||
}
|
||||
databases.close();
|
||||
if (dbname == null)
|
||||
return null;
|
||||
|
||||
stmt.execute("use " + dbname);
|
||||
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
|
||||
// set up ColumnMetaDataList
|
||||
|
||||
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
||||
// TABLE_CAT
|
||||
ColumnMetaData col1 = new ColumnMetaData();
|
||||
col1.setColIndex(1);
|
||||
col1.setColName("TABLE_CAT");
|
||||
col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col1);
|
||||
// TABLE_SCHEM
|
||||
ColumnMetaData col2 = new ColumnMetaData();
|
||||
col2.setColIndex(2);
|
||||
col2.setColName("TABLE_SCHEM");
|
||||
col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col2);
|
||||
// TABLE_NAME
|
||||
ColumnMetaData col3 = new ColumnMetaData();
|
||||
col3.setColIndex(3);
|
||||
col3.setColName("TABLE_NAME");
|
||||
col3.setColSize(193);
|
||||
col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col3);
|
||||
// COLUMN_NAME
|
||||
ColumnMetaData col4 = new ColumnMetaData();
|
||||
col4.setColIndex(4);
|
||||
col4.setColName("COLUMN_NAME");
|
||||
col4.setColSize(65);
|
||||
col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col4);
|
||||
// DATA_TYPE
|
||||
ColumnMetaData col5 = new ColumnMetaData();
|
||||
col5.setColIndex(5);
|
||||
col5.setColName("DATA_TYPE");
|
||||
col5.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(col5);
|
||||
// TYPE_NAME
|
||||
ColumnMetaData col6 = new ColumnMetaData();
|
||||
col6.setColIndex(6);
|
||||
col6.setColName("TYPE_NAME");
|
||||
col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col6);
|
||||
// COLUMN_SIZE
|
||||
ColumnMetaData col7 = new ColumnMetaData();
|
||||
col7.setColIndex(7);
|
||||
col7.setColName("COLUMN_SIZE");
|
||||
col7.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(col7);
|
||||
// BUFFER_LENGTH, not used
|
||||
ColumnMetaData col8 = new ColumnMetaData();
|
||||
col8.setColIndex(8);
|
||||
col8.setColName("BUFFER_LENGTH");
|
||||
columnMetaDataList.add(col8);
|
||||
// DECIMAL_DIGITS
|
||||
ColumnMetaData col9 = new ColumnMetaData();
|
||||
col9.setColIndex(9);
|
||||
col9.setColName("DECIMAL_DIGITS");
|
||||
col9.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(col9);
|
||||
// add NUM_PREC_RADIX
|
||||
ColumnMetaData col10 = new ColumnMetaData();
|
||||
col10.setColIndex(10);
|
||||
col10.setColName("NUM_PREC_RADIX");
|
||||
col10.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(col10);
|
||||
// NULLABLE
|
||||
ColumnMetaData col11 = new ColumnMetaData();
|
||||
col11.setColIndex(11);
|
||||
col11.setColName("NULLABLE");
|
||||
col11.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(col11);
|
||||
// REMARKS
|
||||
ColumnMetaData col12 = new ColumnMetaData();
|
||||
col12.setColIndex(12);
|
||||
col12.setColName("REMARKS");
|
||||
col12.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col12);
|
||||
// COLUMN_DEF
|
||||
ColumnMetaData col13 = new ColumnMetaData();
|
||||
col13.setColIndex(13);
|
||||
col13.setColName("COLUMN_DEF");
|
||||
col13.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col13);
|
||||
//SQL_DATA_TYPE
|
||||
ColumnMetaData col14 = new ColumnMetaData();
|
||||
col14.setColIndex(14);
|
||||
col14.setColName("SQL_DATA_TYPE");
|
||||
col14.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(col14);
|
||||
//SQL_DATETIME_SUB
|
||||
ColumnMetaData col15 = new ColumnMetaData();
|
||||
col15.setColIndex(15);
|
||||
col15.setColName("SQL_DATETIME_SUB");
|
||||
col15.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(col15);
|
||||
//CHAR_OCTET_LENGTH
|
||||
ColumnMetaData col16 = new ColumnMetaData();
|
||||
col16.setColIndex(16);
|
||||
col16.setColName("CHAR_OCTET_LENGTH");
|
||||
col16.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(col16);
|
||||
//ORDINAL_POSITION
|
||||
ColumnMetaData col17 = new ColumnMetaData();
|
||||
col17.setColIndex(17);
|
||||
col17.setColName("ORDINAL_POSITION");
|
||||
col17.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(col17);
|
||||
// IS_NULLABLE
|
||||
ColumnMetaData col18 = new ColumnMetaData();
|
||||
col18.setColIndex(18);
|
||||
col18.setColName("IS_NULLABLE");
|
||||
col18.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col18);
|
||||
//SCOPE_CATALOG
|
||||
ColumnMetaData col19 = new ColumnMetaData();
|
||||
col19.setColIndex(19);
|
||||
col19.setColName("SCOPE_CATALOG");
|
||||
col19.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col19);
|
||||
//SCOPE_SCHEMA
|
||||
ColumnMetaData col20 = new ColumnMetaData();
|
||||
col20.setColIndex(20);
|
||||
col20.setColName("SCOPE_SCHEMA");
|
||||
col20.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col20);
|
||||
//SCOPE_TABLE
|
||||
ColumnMetaData col21 = new ColumnMetaData();
|
||||
col21.setColIndex(21);
|
||||
col21.setColName("SCOPE_TABLE");
|
||||
col21.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col21);
|
||||
//SOURCE_DATA_TYPE
|
||||
ColumnMetaData col22 = new ColumnMetaData();
|
||||
col22.setColIndex(22);
|
||||
col22.setColName("SOURCE_DATA_TYPE");
|
||||
col22.setColType(TSDBConstants.TSDB_DATA_TYPE_SMALLINT);
|
||||
columnMetaDataList.add(col22);
|
||||
//IS_AUTOINCREMENT
|
||||
ColumnMetaData col23 = new ColumnMetaData();
|
||||
col23.setColIndex(23);
|
||||
col23.setColName("IS_AUTOINCREMENT");
|
||||
col23.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col23);
|
||||
//IS_GENERATEDCOLUMN
|
||||
ColumnMetaData col24 = new ColumnMetaData();
|
||||
col24.setColIndex(24);
|
||||
col24.setColName("IS_GENERATEDCOLUMN");
|
||||
col24.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col24);
|
||||
|
||||
resultSet.setColumnMetaDataList(columnMetaDataList);
|
||||
// set up rowDataList
|
||||
ResultSet rs = stmt.executeQuery("describe " + dbname + "." + tableNamePattern);
|
||||
List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
|
||||
int index = 0;
|
||||
while (rs.next()) {
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData(24);
|
||||
// set TABLE_CAT
|
||||
rowData.setString(0, dbname);
|
||||
// set TABLE_NAME
|
||||
rowData.setString(2, tableNamePattern);
|
||||
// set COLUMN_NAME
|
||||
rowData.setString(3, rs.getString("Field"));
|
||||
// set DATA_TYPE
|
||||
String typeName = rs.getString("Type");
|
||||
rowData.setInt(4, getDataType(typeName));
|
||||
// set TYPE_NAME
|
||||
rowData.setString(5, typeName);
|
||||
// set COLUMN_SIZE
|
||||
int length = rs.getInt("Length");
|
||||
rowData.setInt(6, getColumnSize(typeName, length));
|
||||
// set DECIMAL_DIGITS
|
||||
rowData.setInt(8, getDecimalDigits(typeName));
|
||||
// set NUM_PREC_RADIX
|
||||
rowData.setInt(9, 10);
|
||||
// set NULLABLE
|
||||
rowData.setInt(10, getNullable(index, typeName));
|
||||
// set REMARKS
|
||||
rowData.setString(11, rs.getString("Note"));
|
||||
rowDataList.add(rowData);
|
||||
index++;
|
||||
}
|
||||
resultSet.setRowDataList(rowDataList);
|
||||
return resultSet;
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected int getNullable(int index, String typeName) {
|
||||
if (index == 0 && "TIMESTAMP".equals(typeName))
|
||||
return DatabaseMetaData.columnNoNulls;
|
||||
|
@ -552,7 +842,6 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
switch (typeName) {
|
||||
case "TIMESTAMP":
|
||||
return 23;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -615,9 +904,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
return getEmptyResultSet();
|
||||
}
|
||||
|
||||
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
|
||||
return getEmptyResultSet();
|
||||
}
|
||||
public abstract ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException;
|
||||
|
||||
public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException {
|
||||
return getEmptyResultSet();
|
||||
|
@ -718,9 +1005,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
return getEmptyResultSet();
|
||||
}
|
||||
|
||||
public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
|
||||
return getEmptyResultSet();
|
||||
}
|
||||
public abstract ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException;
|
||||
|
||||
public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern,
|
||||
String attributeNamePattern) throws SQLException {
|
||||
|
@ -728,15 +1013,17 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
}
|
||||
|
||||
public boolean supportsResultSetHoldability(int holdability) throws SQLException {
|
||||
if (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getResultSetHoldability() throws SQLException {
|
||||
return 0;
|
||||
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
|
||||
}
|
||||
|
||||
public int getDatabaseMajorVersion() throws SQLException {
|
||||
return 0;
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int getDatabaseMinorVersion() throws SQLException {
|
||||
|
@ -744,7 +1031,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
}
|
||||
|
||||
public int getJDBCMajorVersion() throws SQLException {
|
||||
return 0;
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int getJDBCMinorVersion() throws SQLException {
|
||||
|
@ -768,7 +1055,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
}
|
||||
|
||||
public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
|
||||
return null;
|
||||
return getEmptyResultSet();
|
||||
}
|
||||
|
||||
public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
|
||||
|
@ -805,4 +1092,180 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData {
|
|||
private ResultSet getEmptyResultSet() {
|
||||
return new EmptyResultSet();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
protected ResultSet getCatalogs(Connection conn) throws SQLException {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
|
||||
// set up ColumnMetaDataList
|
||||
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
||||
// TABLE_CAT
|
||||
ColumnMetaData col1 = new ColumnMetaData();
|
||||
col1.setColIndex(1);
|
||||
col1.setColName("TABLE_CAT");
|
||||
col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col1);
|
||||
|
||||
resultSet.setColumnMetaDataList(columnMetaDataList);
|
||||
|
||||
List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
|
||||
ResultSet rs = stmt.executeQuery("show databases");
|
||||
while (rs.next()) {
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData(1);
|
||||
rowData.setString(0, rs.getString("name"));
|
||||
rowDataList.add(rowData);
|
||||
}
|
||||
resultSet.setRowDataList(rowDataList);
|
||||
return resultSet;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected ResultSet getPrimaryKeys(String catalog, String schema, String table, Connection conn) throws SQLException {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
if (catalog == null || catalog.isEmpty())
|
||||
return null;
|
||||
|
||||
ResultSet databases = stmt.executeQuery("show databases");
|
||||
String dbname = null;
|
||||
while (databases.next()) {
|
||||
dbname = databases.getString("name");
|
||||
if (dbname.equalsIgnoreCase(catalog))
|
||||
break;
|
||||
}
|
||||
databases.close();
|
||||
if (dbname == null)
|
||||
return null;
|
||||
|
||||
stmt.execute("use " + dbname);
|
||||
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
|
||||
// set up ColumnMetaDataList
|
||||
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
||||
// TABLE_CAT
|
||||
ColumnMetaData col1 = new ColumnMetaData();
|
||||
col1.setColIndex(0);
|
||||
col1.setColName("TABLE_CAT");
|
||||
col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col1);
|
||||
// TABLE_SCHEM
|
||||
ColumnMetaData col2 = new ColumnMetaData();
|
||||
col2.setColIndex(1);
|
||||
col2.setColName("TABLE_SCHEM");
|
||||
col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col2);
|
||||
// TABLE_NAME
|
||||
ColumnMetaData col3 = new ColumnMetaData();
|
||||
col3.setColIndex(2);
|
||||
col3.setColName("TABLE_NAME");
|
||||
col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col3);
|
||||
// COLUMN_NAME
|
||||
ColumnMetaData col4 = new ColumnMetaData();
|
||||
col4.setColIndex(3);
|
||||
col4.setColName("COLUMN_NAME");
|
||||
col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col4);
|
||||
// KEY_SEQ
|
||||
ColumnMetaData col5 = new ColumnMetaData();
|
||||
col5.setColIndex(4);
|
||||
col5.setColName("KEY_SEQ");
|
||||
col5.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(col5);
|
||||
// PK_NAME
|
||||
ColumnMetaData col6 = new ColumnMetaData();
|
||||
col6.setColIndex(5);
|
||||
col6.setColName("PK_NAME");
|
||||
col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col6);
|
||||
resultSet.setColumnMetaDataList(columnMetaDataList);
|
||||
|
||||
// set rowData
|
||||
List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
|
||||
ResultSet rs = stmt.executeQuery("describe " + dbname + "." + table);
|
||||
rs.next();
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData(6);
|
||||
rowData.setString(0, null);
|
||||
rowData.setString(1, null);
|
||||
rowData.setString(2, table);
|
||||
String pkName = rs.getString(1);
|
||||
rowData.setString(3, pkName);
|
||||
rowData.setInt(4, 1);
|
||||
rowData.setString(5, pkName);
|
||||
rowDataList.add(rowData);
|
||||
resultSet.setRowDataList(rowDataList);
|
||||
return resultSet;
|
||||
}
|
||||
}
|
||||
|
||||
protected ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern, Connection conn) throws SQLException {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
if (catalog == null || catalog.isEmpty())
|
||||
return null;
|
||||
|
||||
ResultSet databases = stmt.executeQuery("show databases");
|
||||
String dbname = null;
|
||||
while (databases.next()) {
|
||||
dbname = databases.getString("name");
|
||||
if (dbname.equalsIgnoreCase(catalog))
|
||||
break;
|
||||
}
|
||||
databases.close();
|
||||
if (dbname == null)
|
||||
return null;
|
||||
|
||||
stmt.execute("use " + dbname);
|
||||
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
|
||||
// set up ColumnMetaDataList
|
||||
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
|
||||
// TABLE_CAT
|
||||
ColumnMetaData col1 = new ColumnMetaData();
|
||||
col1.setColIndex(0);
|
||||
col1.setColName("TABLE_CAT");
|
||||
col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col1);
|
||||
// TABLE_SCHEM
|
||||
ColumnMetaData col2 = new ColumnMetaData();
|
||||
col2.setColIndex(1);
|
||||
col2.setColName("TABLE_SCHEM");
|
||||
col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col2);
|
||||
// TABLE_NAME
|
||||
ColumnMetaData col3 = new ColumnMetaData();
|
||||
col3.setColIndex(2);
|
||||
col3.setColName("TABLE_NAME");
|
||||
col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col3);
|
||||
// SUPERTABLE_NAME
|
||||
ColumnMetaData col4 = new ColumnMetaData();
|
||||
col4.setColIndex(3);
|
||||
col4.setColName("SUPERTABLE_NAME");
|
||||
col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR);
|
||||
columnMetaDataList.add(col4);
|
||||
resultSet.setColumnMetaDataList(columnMetaDataList);
|
||||
|
||||
ResultSet rs = stmt.executeQuery("show tables like '" + tableNamePattern + "'");
|
||||
List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData(4);
|
||||
rowData.setString(2, rs.getString(1));
|
||||
rowData.setString(3, rs.getString(4));
|
||||
rowDataList.add(rowData);
|
||||
}
|
||||
resultSet.setRowDataList(rowDataList);
|
||||
return resultSet;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/***************************************************************************
|
||||
* 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/>.
|
||||
*****************************************************************************/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/*
|
||||
* TDengine only supports a subset of the standard SQL, thus this implemetation of the
|
||||
* standard JDBC API contains more or less some adjustments customized for certain
|
||||
* compatibility needs.
|
||||
*/
|
||||
public class CatalogResultSet extends TSDBResultSetWrapper {
|
||||
|
||||
public CatalogResultSet(ResultSet resultSet) {
|
||||
super.setOriginalResultSet(resultSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int columnIndex) throws SQLException {
|
||||
if (columnIndex <= 1) {
|
||||
return super.getString(columnIndex);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(int columnIndex) throws SQLException {
|
||||
if (columnIndex <= 1) {
|
||||
return super.getBoolean(columnIndex);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes(int columnIndex) throws SQLException {
|
||||
if (columnIndex <= 1) {
|
||||
return super.getBytes(columnIndex);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject(int columnIndex) throws SQLException {
|
||||
if (columnIndex <= 1) {
|
||||
return super.getObject(columnIndex);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/***************************************************************************
|
||||
* 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/>.
|
||||
*****************************************************************************/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/*
|
||||
* TDengine only supports a subset of the standard SQL, thus this implemetation of the
|
||||
* standard JDBC API contains more or less some adjustments customized for certain
|
||||
* compatibility needs.
|
||||
*/
|
||||
public class GetTablesResultSet extends TSDBResultSetWrapper {
|
||||
|
||||
private String catalog;
|
||||
private String schemaPattern;
|
||||
private String tableNamePattern;
|
||||
private String[] types;
|
||||
|
||||
public GetTablesResultSet(ResultSet resultSet, String catalog, String schemaPattern, String tableNamePattern, String[] types) {
|
||||
super.setOriginalResultSet(resultSet);
|
||||
this.catalog = catalog;
|
||||
this.schemaPattern = schemaPattern;
|
||||
this.tableNamePattern = tableNamePattern;
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int columnIndex) throws SQLException {
|
||||
String ret = null;
|
||||
switch (columnIndex) {
|
||||
case 3:
|
||||
return super.getString(1);
|
||||
case 4:
|
||||
return "table";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -19,9 +19,12 @@ import java.util.Map;
|
|||
|
||||
public abstract class TSDBConstants {
|
||||
|
||||
public static final String STATEMENT_CLOSED = "Statement already closed.";
|
||||
public static final String DEFAULT_PORT = "6200";
|
||||
public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!";
|
||||
public static final String INVALID_VARIABLES = "invalid variables";
|
||||
public static final String RESULT_SET_IS_CLOSED = "resultSet is closed.";
|
||||
|
||||
public static Map<Integer, String> DATATYPE_MAP = null;
|
||||
|
||||
public static final long JNI_NULL_POINTER = 0L;
|
||||
|
@ -74,7 +77,7 @@ public abstract class TSDBConstants {
|
|||
}
|
||||
|
||||
static {
|
||||
DATATYPE_MAP = new HashMap<Integer, String>();
|
||||
DATATYPE_MAP = new HashMap<>();
|
||||
DATATYPE_MAP.put(1, "BOOL");
|
||||
DATATYPE_MAP.put(2, "TINYINT");
|
||||
DATATYPE_MAP.put(3, "SMALLINT");
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -100,7 +100,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
|||
* order to process those supported SQLs.
|
||||
*/
|
||||
private void preprocessSql() {
|
||||
|
||||
/***** For processing some of Spark SQLs*****/
|
||||
// should replace it first
|
||||
this.rawSql = this.rawSql.replaceAll("or (.*) is null", "");
|
||||
|
@ -149,7 +148,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
|||
rawSql = rawSql.replace(matcher.group(1), tableFullName);
|
||||
}
|
||||
/***** for inner queries *****/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,7 +194,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
|||
|
||||
@Override
|
||||
public void setNull(int parameterIndex, int sqlType) throws SQLException {
|
||||
setObject(parameterIndex, new String("NULL"));
|
||||
setObject(parameterIndex, "NULL");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -123,11 +123,21 @@ public class TSDBResultSet implements ResultSet {
|
|||
}
|
||||
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
try {
|
||||
return iface.cast(this);
|
||||
} catch (ClassCastException cce) {
|
||||
throw new SQLException("Unable to unwrap to " + iface.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
return iface.isInstance(this);
|
||||
}
|
||||
|
||||
public boolean next() throws SQLException {
|
||||
|
|
|
@ -52,12 +52,18 @@ public class TSDBStatement implements Statement {
|
|||
this.isClosed = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
try {
|
||||
return iface.cast(this);
|
||||
} catch (ClassCastException cce) {
|
||||
throw new SQLException("Unable to unwrap to " + iface.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
return iface.isInstance(this);
|
||||
}
|
||||
|
||||
public ResultSet executeQuery(String sql) throws SQLException {
|
||||
|
@ -130,10 +136,15 @@ public class TSDBStatement implements Statement {
|
|||
}
|
||||
|
||||
public void setMaxFieldSize(int max) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
||||
public int getMaxRows() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
// always set maxRows to zero, meaning unlimitted rows in a resultSet
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -29,177 +29,53 @@ public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getSchemaTerm() throws SQLException {
|
||||
return null;
|
||||
public String getDriverName() throws SQLException {
|
||||
return RestfulDriver.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProcedureTerm() throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCatalogTerm() throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCatalogAtStart() throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
|
||||
Statement stmt = null;
|
||||
if (null != connection && !connection.isClosed()) {
|
||||
stmt = connection.createStatement();
|
||||
if (catalog == null || catalog.length() < 1) {
|
||||
catalog = connection.getCatalog();
|
||||
}
|
||||
stmt.executeUpdate("use " + catalog);
|
||||
ResultSet resultSet0 = stmt.executeQuery("show tables");
|
||||
GetTablesResultSet getTablesResultSet = new GetTablesResultSet(resultSet0, catalog, schemaPattern, tableNamePattern, types);
|
||||
return getTablesResultSet;
|
||||
} else {
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
}
|
||||
return super.getTables(catalog, schemaPattern, tableNamePattern, types, connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getCatalogs() throws SQLException {
|
||||
if (connection != null && !connection.isClosed()) {
|
||||
Statement stmt = connection.createStatement();
|
||||
ResultSet resultSet0 = stmt.executeQuery("show databases");
|
||||
CatalogResultSet resultSet = new CatalogResultSet(resultSet0);
|
||||
return resultSet;
|
||||
} else {
|
||||
return new EmptyResultSet();
|
||||
if (connection == null || connection.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
return super.getCatalogs(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getTableTypes() throws SQLException {
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
}
|
||||
return super.getTableTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
|
||||
Statement stmt = null;
|
||||
if (null != connection && !connection.isClosed()) {
|
||||
stmt = connection.createStatement();
|
||||
if (catalog == null || catalog.length() < 1) {
|
||||
catalog = connection.getCatalog();
|
||||
}
|
||||
stmt.execute("use " + catalog);
|
||||
|
||||
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
|
||||
// set up ColumnMetaDataList
|
||||
List<ColumnMetaData> columnMetaDataList = new ArrayList<>(24);
|
||||
columnMetaDataList.add(null);
|
||||
columnMetaDataList.add(null);
|
||||
// add TABLE_NAME
|
||||
ColumnMetaData colMetaData = new ColumnMetaData();
|
||||
colMetaData.setColIndex(3);
|
||||
colMetaData.setColName("TABLE_NAME");
|
||||
colMetaData.setColSize(193);
|
||||
colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY);
|
||||
columnMetaDataList.add(colMetaData);
|
||||
// add COLUMN_NAME
|
||||
colMetaData = new ColumnMetaData();
|
||||
colMetaData.setColIndex(4);
|
||||
colMetaData.setColName("COLUMN_NAME");
|
||||
colMetaData.setColSize(65);
|
||||
colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY);
|
||||
columnMetaDataList.add(colMetaData);
|
||||
// add DATA_TYPE
|
||||
colMetaData = new ColumnMetaData();
|
||||
colMetaData.setColIndex(5);
|
||||
colMetaData.setColName("DATA_TYPE");
|
||||
colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(colMetaData);
|
||||
// add TYPE_NAME
|
||||
colMetaData = new ColumnMetaData();
|
||||
colMetaData.setColIndex(6);
|
||||
colMetaData.setColName("TYPE_NAME");
|
||||
colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY);
|
||||
columnMetaDataList.add(colMetaData);
|
||||
// add COLUMN_SIZE
|
||||
colMetaData = new ColumnMetaData();
|
||||
colMetaData.setColIndex(7);
|
||||
colMetaData.setColName("COLUMN_SIZE");
|
||||
colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(colMetaData);
|
||||
// add BUFFER_LENGTH ,not used
|
||||
columnMetaDataList.add(null);
|
||||
// add DECIMAL_DIGITS
|
||||
colMetaData = new ColumnMetaData();
|
||||
colMetaData.setColIndex(9);
|
||||
colMetaData.setColName("DECIMAL_DIGITS");
|
||||
colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(colMetaData);
|
||||
// add NUM_PREC_RADIX
|
||||
colMetaData = new ColumnMetaData();
|
||||
colMetaData.setColIndex(10);
|
||||
colMetaData.setColName("NUM_PREC_RADIX");
|
||||
colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(colMetaData);
|
||||
// add NULLABLE
|
||||
colMetaData = new ColumnMetaData();
|
||||
colMetaData.setColIndex(11);
|
||||
colMetaData.setColName("NULLABLE");
|
||||
colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT);
|
||||
columnMetaDataList.add(colMetaData);
|
||||
|
||||
resultSet.setColumnMetaDataList(columnMetaDataList);
|
||||
|
||||
// set up rowDataList
|
||||
ResultSet resultSet0 = stmt.executeQuery("describe " + tableNamePattern);
|
||||
List<TSDBResultSetRowData> rowDataList = new ArrayList<>();
|
||||
int index = 0;
|
||||
while (resultSet0.next()) {
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData(24);
|
||||
// set TABLE_NAME
|
||||
rowData.setString(2, tableNamePattern);
|
||||
// set COLUMN_NAME
|
||||
rowData.setString(3, resultSet0.getString(1));
|
||||
// set DATA_TYPE
|
||||
String typeName = resultSet0.getString(2);
|
||||
rowData.setInt(4, getDataType(typeName));
|
||||
// set TYPE_NAME
|
||||
rowData.setString(5, typeName);
|
||||
// set COLUMN_SIZE
|
||||
int length = resultSet0.getInt(3);
|
||||
rowData.setInt(6, getColumnSize(typeName, length));
|
||||
// set DECIMAL_DIGITS
|
||||
rowData.setInt(8, getDecimalDigits(typeName));
|
||||
// set NUM_PREC_RADIX
|
||||
rowData.setInt(9, 10);
|
||||
// set NULLABLE
|
||||
rowData.setInt(10, getNullable(index, typeName));
|
||||
rowDataList.add(rowData);
|
||||
index++;
|
||||
}
|
||||
resultSet.setRowDataList(rowDataList);
|
||||
|
||||
return resultSet;
|
||||
} else {
|
||||
if (connection == null || connection.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
}
|
||||
return super.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern, connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxLogicalLobSize() throws SQLException {
|
||||
return 0;
|
||||
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
|
||||
if (connection == null || connection.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
return super.getPrimaryKeys(catalog, schema, table, connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRefCursors() throws SQLException {
|
||||
return false;
|
||||
public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
|
||||
if (connection == null || connection.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
return super.getSuperTables(catalog, schemaPattern, tableNamePattern, connection);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,28 +15,28 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
public class RestfulResultSet implements ResultSet {
|
||||
private static final String RESULT_SET_IS_CLOSED = "resultSet is closed.";
|
||||
private volatile boolean isClosed;
|
||||
private int pos = -1;
|
||||
|
||||
private final String database;
|
||||
private final Statement statement;
|
||||
// data
|
||||
private ArrayList<ArrayList<Object>> resultSet;
|
||||
private ArrayList<ArrayList<Object>> resultSet = new ArrayList<>();
|
||||
// meta
|
||||
private ArrayList<String> columnNames;
|
||||
private ArrayList<Field> columns;
|
||||
private ArrayList<String> columnNames = new ArrayList<>();
|
||||
private ArrayList<Field> columns = new ArrayList<>();
|
||||
private RestfulResultSetMetaData metaData;
|
||||
|
||||
/**
|
||||
* 由一个result的Json构造结果集,对应执行show databases, show tables等这些语句,返回结果集,但无法获取结果集对应的meta,统一当成String处理
|
||||
*
|
||||
* @param resultJson: 包含data信息的结果集,有sql返回的结果集
|
||||
***/
|
||||
public RestfulResultSet(String database, Statement statement, JSONObject resultJson) {
|
||||
this.database = database;
|
||||
this.statement = statement;
|
||||
// row data
|
||||
JSONArray data = resultJson.getJSONArray("data");
|
||||
resultSet = new ArrayList<>();
|
||||
int columnIndex = 0;
|
||||
for (; columnIndex < data.size(); columnIndex++) {
|
||||
ArrayList oneRow = new ArrayList<>();
|
||||
|
@ -48,15 +48,13 @@ public class RestfulResultSet implements ResultSet {
|
|||
}
|
||||
|
||||
// column only names
|
||||
columnNames = new ArrayList<>();
|
||||
columns = new ArrayList<>();
|
||||
JSONArray head = resultJson.getJSONArray("head");
|
||||
for (int i = 0; i < head.size(); i++) {
|
||||
String name = head.getString(i);
|
||||
columnNames.add(name);
|
||||
columns.add(new Field(name, "", 0, ""));
|
||||
}
|
||||
this.metaData = new RestfulResultSetMetaData(this.database, columns);
|
||||
this.metaData = new RestfulResultSetMetaData(this.database, columns, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,7 +76,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
}
|
||||
}
|
||||
this.columns = newColumns;
|
||||
this.metaData = new RestfulResultSetMetaData(this.database, this.columns);
|
||||
this.metaData = new RestfulResultSetMetaData(this.database, this.columns, this);
|
||||
}
|
||||
|
||||
public Field findField(String columnName, List<JSONObject> fieldJsonList) {
|
||||
|
@ -91,7 +89,6 @@ public class RestfulResultSet implements ResultSet {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -112,10 +109,9 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public boolean next() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
if (pos < resultSet.size() - 1) {
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
pos++;
|
||||
if (pos <= resultSet.size() - 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -131,37 +127,38 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public boolean wasNull() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
return resultSet.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
if (columnIndex > resultSet.get(pos).size()) {
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size()));
|
||||
}
|
||||
return resultSet.get(pos).get(columnIndex - 1).toString();
|
||||
|
||||
columnIndex = getTrueColumnIndex(columnIndex);
|
||||
return resultSet.get(pos).get(columnIndex).toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
String result = getString(columnIndex);
|
||||
if (!(result.equals("true") || result.equals("false"))) {
|
||||
throw new SQLException("not boolean value");
|
||||
}
|
||||
return result.equals("true");
|
||||
columnIndex = getTrueColumnIndex(columnIndex);
|
||||
int result = getInt(columnIndex);
|
||||
return result == 0 ? false : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getByte(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -169,40 +166,55 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public short getShort(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
return Short.parseShort(getString(columnIndex));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
columnIndex = getTrueColumnIndex(columnIndex);
|
||||
return Short.parseShort(resultSet.get(pos).get(columnIndex).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
return Integer.parseInt(getString(columnIndex));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
columnIndex = getTrueColumnIndex(columnIndex);
|
||||
return Integer.parseInt(resultSet.get(pos).get(columnIndex).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
return Long.parseLong(getString(columnIndex));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
columnIndex = getTrueColumnIndex(columnIndex);
|
||||
return Long.parseLong(resultSet.get(pos).get(columnIndex).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFloat(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
return Float.parseFloat(getString(columnIndex));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
columnIndex = getTrueColumnIndex(columnIndex);
|
||||
return Float.parseFloat(resultSet.get(pos).get(columnIndex).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
return Double.parseDouble(getString(columnIndex));
|
||||
columnIndex = getTrueColumnIndex(columnIndex);
|
||||
return Double.parseDouble(resultSet.get(pos).get(columnIndex).toString());
|
||||
}
|
||||
|
||||
private int getTrueColumnIndex(int columnIndex) throws SQLException {
|
||||
if (columnIndex < 1) {
|
||||
throw new SQLException("Column Index out of range, " + columnIndex + " < 1");
|
||||
}
|
||||
|
||||
int numOfCols = resultSet.get(pos).size();
|
||||
if (columnIndex > numOfCols) {
|
||||
throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols);
|
||||
}
|
||||
|
||||
return columnIndex - 1;
|
||||
}
|
||||
|
||||
/*******************************************************************************************************************/
|
||||
|
@ -210,7 +222,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -218,7 +230,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public byte[] getBytes(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -226,7 +238,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public Date getDate(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -234,7 +246,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public Time getTime(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -242,17 +254,18 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public Timestamp getTimestamp(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
String strDate = getString(columnIndex);
|
||||
strDate = strDate.substring(1, strDate.length() - 1);
|
||||
columnIndex = getTrueColumnIndex(columnIndex);
|
||||
String strDate = resultSet.get(pos).get(columnIndex).toString();
|
||||
// strDate = strDate.substring(1, strDate.length() - 1);
|
||||
return Timestamp.valueOf(strDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getAsciiStream(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -260,7 +273,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public InputStream getUnicodeStream(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -268,17 +281,16 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public InputStream getBinaryStream(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
||||
/*************************************************************************************************************/
|
||||
|
||||
@Override
|
||||
public String getString(String columnLabel) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
return getString(findColumn(columnLabel) + 1);
|
||||
return getString(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -338,53 +350,44 @@ public class RestfulResultSet implements ResultSet {
|
|||
|
||||
@Override
|
||||
public Timestamp getTimestamp(String columnLabel) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
return Timestamp.valueOf(getString(findColumn(columnLabel)));
|
||||
return getTimestamp(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getAsciiStream(String columnLabel) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
return getAsciiStream(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getUnicodeStream(String columnLabel) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
return getUnicodeStream(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getBinaryStream(String columnLabel) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
return getBinaryStream(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
/*************************************************************************************************************/
|
||||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCursorName() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -392,7 +395,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public ResultSetMetaData getMetaData() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
return this.metaData;
|
||||
}
|
||||
|
@ -400,7 +403,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public Object getObject(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -413,15 +416,18 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public int findColumn(String columnLabel) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
return columnNames.indexOf(columnLabel);
|
||||
int columnIndex = columnNames.indexOf(columnLabel);
|
||||
if (columnIndex == -1)
|
||||
throw new SQLException("cannot find Column in resultSet");
|
||||
return columnIndex + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getCharacterStream(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -429,7 +435,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public Reader getCharacterStream(String columnLabel) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -437,7 +443,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -445,7 +451,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -453,78 +459,132 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public boolean isBeforeFirst() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
return this.pos == -1 && this.resultSet.size() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAfterLast() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
return this.pos >= resultSet.size() && this.resultSet.size() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFirst() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
return this.pos == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLast() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
if (this.resultSet.size() == 0)
|
||||
return false;
|
||||
return this.pos == (this.resultSet.size() - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeFirst() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
synchronized (this) {
|
||||
if (this.resultSet.size() > 0) {
|
||||
this.pos = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterLast() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
synchronized (this) {
|
||||
if (this.resultSet.size() > 0) {
|
||||
this.pos = this.resultSet.size();
|
||||
}
|
||||
}
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean first() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
if (this.resultSet.size() == 0)
|
||||
return false;
|
||||
|
||||
synchronized (this) {
|
||||
this.pos = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean last() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
if (this.resultSet.size() == 0)
|
||||
return false;
|
||||
synchronized (this) {
|
||||
this.pos = this.resultSet.size() - 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRow() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
int row;
|
||||
synchronized (this) {
|
||||
if (this.pos < 0 || this.pos >= this.resultSet.size())
|
||||
return 0;
|
||||
row = this.pos + 1;
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean absolute(int row) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
// if (this.resultSet.size() == 0)
|
||||
// return false;
|
||||
//
|
||||
// if (row == 0) {
|
||||
// beforeFirst();
|
||||
// return false;
|
||||
// } else if (row == 1) {
|
||||
// return first();
|
||||
// } else if (row == -1) {
|
||||
// return last();
|
||||
// } else if (row > this.resultSet.size()) {
|
||||
// afterLast();
|
||||
// return false;
|
||||
// } else {
|
||||
// if (row < 0) {
|
||||
// // adjust to reflect after end of result set
|
||||
// int newRowPosition = this.resultSet.size() + row + 1;
|
||||
// if (newRowPosition <= 0) {
|
||||
// beforeFirst();
|
||||
// return false;
|
||||
// } else {
|
||||
// return absolute(newRowPosition);
|
||||
// }
|
||||
// } else {
|
||||
// row--; // adjust for index difference
|
||||
// this.pos = row;
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -532,7 +592,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public boolean relative(int rows) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -540,7 +600,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public boolean previous() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
@ -548,17 +608,18 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public void setFetchDirection(int direction) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
if (direction != ResultSet.FETCH_REVERSE || direction != ResultSet.FETCH_REVERSE || direction != ResultSet.FETCH_UNKNOWN)
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
if ((direction != ResultSet.FETCH_FORWARD) && (direction != ResultSet.FETCH_REVERSE) && (direction != ResultSet.FETCH_UNKNOWN))
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
if (!(getType() == ResultSet.TYPE_FORWARD_ONLY && direction == ResultSet.FETCH_FORWARD))
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFetchDirection() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
return ResultSet.FETCH_FORWARD;
|
||||
}
|
||||
|
@ -566,17 +627,17 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public void setFetchSize(int rows) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
if (rows < 0)
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFetchSize() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
return this.resultSet.size();
|
||||
}
|
||||
|
@ -834,7 +895,7 @@ public class RestfulResultSet implements ResultSet {
|
|||
@Override
|
||||
public Statement getStatement() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED));
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
return this.statement;
|
||||
}
|
||||
|
@ -992,14 +1053,15 @@ public class RestfulResultSet implements ResultSet {
|
|||
|
||||
@Override
|
||||
public int getHoldability() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() throws SQLException {
|
||||
return false;
|
||||
//TODO: SQLFeature Not Supported
|
||||
// throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
return isClosed;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1224,11 +1286,21 @@ public class RestfulResultSet implements ResultSet {
|
|||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
try {
|
||||
return iface.cast(this);
|
||||
} catch (ClassCastException cce) {
|
||||
throw new SQLException("Unable to unwrap to " + iface.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg(TSDBConstants.RESULT_SET_IS_CLOSED));
|
||||
|
||||
return iface.isInstance(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import com.taosdata.jdbc.TSDBConstants;
|
||||
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||
|
||||
private final String database;
|
||||
private ArrayList<RestfulResultSet.Field> fields;
|
||||
private final RestfulResultSet resultSet;
|
||||
|
||||
public RestfulResultSetMetaData(String database, ArrayList<RestfulResultSet.Field> fields) {
|
||||
public RestfulResultSetMetaData(String database, ArrayList<RestfulResultSet.Field> fields, RestfulResultSet resultSet) {
|
||||
this.database = database;
|
||||
this.fields = fields;
|
||||
this.resultSet = resultSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,13 +31,12 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
|||
|
||||
@Override
|
||||
public boolean isCaseSensitive(int column) throws SQLException {
|
||||
//TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSearchable(int column) throws SQLException {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,17 +46,30 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
|||
|
||||
@Override
|
||||
public int isNullable(int column) throws SQLException {
|
||||
if (column == 1)
|
||||
return ResultSetMetaData.columnNoNulls;
|
||||
return ResultSetMetaData.columnNullable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSigned(int column) throws SQLException {
|
||||
String type = this.fields.get(column - 1).type.toUpperCase();
|
||||
switch (type) {
|
||||
case "TINYINT":
|
||||
case "SMALLINT":
|
||||
case "INT":
|
||||
case "BIGINT":
|
||||
case "FLOAT":
|
||||
case "DOUBLE":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnDisplaySize(int column) throws SQLException {
|
||||
return 0;
|
||||
return this.fields.get(column - 1).length;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,27 +79,46 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
|||
|
||||
@Override
|
||||
public String getColumnName(int column) throws SQLException {
|
||||
return null;
|
||||
return fields.get(column - 1).name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchemaName(int column) throws SQLException {
|
||||
return this.database;
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPrecision(int column) throws SQLException {
|
||||
String type = this.fields.get(column - 1).type.toUpperCase();
|
||||
switch (type) {
|
||||
case "FLOAT":
|
||||
return 5;
|
||||
case "DOUBLE":
|
||||
return 9;
|
||||
case "BINARY":
|
||||
case "NCHAR":
|
||||
return this.fields.get(column - 1).length;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScale(int column) throws SQLException {
|
||||
String type = this.fields.get(column - 1).type.toUpperCase();
|
||||
switch (type) {
|
||||
case "FLOAT":
|
||||
return 5;
|
||||
case "DOUBLE":
|
||||
return 9;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableName(int column) throws SQLException {
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,17 +128,41 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
|||
|
||||
@Override
|
||||
public int getColumnType(int column) throws SQLException {
|
||||
return 0;
|
||||
String type = this.fields.get(column - 1).type.toUpperCase();
|
||||
switch (type) {
|
||||
case "BOOL":
|
||||
return java.sql.Types.BOOLEAN;
|
||||
case "TINYINT":
|
||||
return java.sql.Types.TINYINT;
|
||||
case "SMALLINT":
|
||||
return java.sql.Types.SMALLINT;
|
||||
case "INT":
|
||||
return java.sql.Types.INTEGER;
|
||||
case "BIGINT":
|
||||
return java.sql.Types.BIGINT;
|
||||
case "FLOAT":
|
||||
return java.sql.Types.FLOAT;
|
||||
case "DOUBLE":
|
||||
return java.sql.Types.DOUBLE;
|
||||
case "BINARY":
|
||||
return java.sql.Types.BINARY;
|
||||
case "TIMESTAMP":
|
||||
return java.sql.Types.TIMESTAMP;
|
||||
case "NCHAR":
|
||||
return java.sql.Types.NCHAR;
|
||||
}
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnTypeName(int column) throws SQLException {
|
||||
return null;
|
||||
String type = fields.get(column - 1).type;
|
||||
return type.toUpperCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly(int column) throws SQLException {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -117,16 +177,43 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
|||
|
||||
@Override
|
||||
public String getColumnClassName(int column) throws SQLException {
|
||||
return null;
|
||||
String type = this.fields.get(column - 1).type;
|
||||
String columnClassName = "";
|
||||
switch (type) {
|
||||
case "BOOL":
|
||||
return Boolean.class.getName();
|
||||
case "TINYINT":
|
||||
case "SMALLINT":
|
||||
return Short.class.getName();
|
||||
case "INT":
|
||||
return Integer.class.getName();
|
||||
case "BIGINT":
|
||||
return Long.class.getName();
|
||||
case "FLOAT":
|
||||
return Float.class.getName();
|
||||
case "DOUBLE":
|
||||
return Double.class.getName();
|
||||
case "TIMESTAMP":
|
||||
return Timestamp.class.getName();
|
||||
case "BINARY":
|
||||
case "NCHAR":
|
||||
return String.class.getName();
|
||||
}
|
||||
return columnClassName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
return null;
|
||||
try {
|
||||
return iface.cast(this);
|
||||
} catch (ClassCastException cce) {
|
||||
throw new SQLException("Unable to unwrap to " + iface.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return false;
|
||||
return iface.isInstance(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class RestfulStatement implements Statement {
|
||||
|
||||
private static final String STATEMENT_CLOSED = "Statement already closed.";
|
||||
private boolean closed;
|
||||
private String database;
|
||||
private final RestfulConnection conn;
|
||||
|
@ -65,17 +64,163 @@ public class RestfulStatement implements Statement {
|
|||
public ResultSet executeQuery(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException("statement already closed");
|
||||
if (!SqlSyntaxValidator.isSelectSql(sql))
|
||||
throw new SQLException("not a select sql for executeQuery: " + sql);
|
||||
if (!SqlSyntaxValidator.isValidForExecuteQuery(sql))
|
||||
throw new SQLException("not a valid sql for executeQuery: " + sql);
|
||||
|
||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||
if (SqlSyntaxValidator.isDatabaseUnspecifiedQuery(sql)) {
|
||||
return executeOneQuery(url, sql);
|
||||
}
|
||||
|
||||
if (this.database == null || this.database.isEmpty())
|
||||
throw new SQLException("Database not specified or available");
|
||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||
return executeOneQuery(url, sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeUpdate(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException("statement already closed");
|
||||
if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql))
|
||||
throw new SQLException("not a valid sql for executeUpdate: " + sql);
|
||||
|
||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||
if (SqlSyntaxValidator.isDatabaseUnspecifiedUpdate(sql)) {
|
||||
return executeOneUpdate(url, sql);
|
||||
}
|
||||
|
||||
if (this.database == null || this.database.isEmpty())
|
||||
throw new SQLException("Database not specified or available");
|
||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||
return executeOneUpdate(url, sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
synchronized (RestfulStatement.class) {
|
||||
if (!isClosed())
|
||||
this.closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxFieldSize() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return TSDBConstants.maxFieldSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxFieldSize(int max) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
if (max < 0)
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxRows() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxRows(int max) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
if (max < 0)
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEscapeProcessing(boolean enable) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getQueryTimeout() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQueryTimeout(int seconds) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
if (seconds < 0)
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() throws SQLException {
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
// nothing to do
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCursorName(String name) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException("Invalid method call on a closed statement.");
|
||||
if (!SqlSyntaxValidator.isValidForExecute(sql))
|
||||
throw new SQLException("not a valid sql for execute: " + sql);
|
||||
|
||||
//如果执行了use操作应该将当前Statement的catalog设置为新的database
|
||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||
if (SqlSyntaxValidator.isUseSql(sql)) {
|
||||
HttpClientPoolUtil.execute(url, sql);
|
||||
this.database = sql.trim().replace("use", "").trim();
|
||||
this.conn.setCatalog(this.database);
|
||||
} else if (SqlSyntaxValidator.isDatabaseUnspecifiedQuery(sql)) {
|
||||
executeOneQuery(url, sql);
|
||||
} else if (SqlSyntaxValidator.isDatabaseUnspecifiedUpdate(sql)) {
|
||||
executeOneUpdate(url, sql);
|
||||
} else {
|
||||
if (SqlSyntaxValidator.isValidForExecuteQuery(sql)) {
|
||||
executeQuery(sql);
|
||||
} else {
|
||||
executeUpdate(sql);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private ResultSet executeOneQuery(String url, String sql) throws SQLException {
|
||||
if (!SqlSyntaxValidator.isValidForExecuteQuery(sql))
|
||||
throw new SQLException("not a select sql for executeQuery: " + sql);
|
||||
|
||||
// row data
|
||||
String result = HttpClientPoolUtil.execute(url, sql);
|
||||
JSONObject resultJson = JSON.parseObject(result);
|
||||
if (resultJson.getString("status").equals("error")) {
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code")));
|
||||
}
|
||||
|
||||
// parse table name from sql
|
||||
String[] tableIdentifiers = parseTableIdentifier(sql);
|
||||
if (tableIdentifiers != null) {
|
||||
|
@ -93,23 +238,14 @@ public class RestfulStatement implements Statement {
|
|||
} else {
|
||||
this.resultSet = new RestfulResultSet(database, this, resultJson);
|
||||
}
|
||||
|
||||
this.affectedRows = 0;
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeUpdate(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException("statement already closed");
|
||||
private int executeOneUpdate(String url, String sql) throws SQLException {
|
||||
if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql))
|
||||
throw new SQLException("not a valid sql for executeUpdate: " + sql);
|
||||
|
||||
if (this.database == null)
|
||||
throw new SQLException("Database not specified or available");
|
||||
|
||||
final String url = "http://" + conn.getHost().trim() + ":" + conn.getPort() + "/rest/sql";
|
||||
// HttpClientPoolUtil.execute(url, "use " + conn.getDatabase());
|
||||
String result = HttpClientPoolUtil.execute(url, sql);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
if (jsonObject.getString("status").equals("error")) {
|
||||
|
@ -120,130 +256,10 @@ public class RestfulStatement implements Statement {
|
|||
return this.affectedRows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
synchronized (RestfulStatement.class) {
|
||||
if (!isClosed())
|
||||
this.closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxFieldSize() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
return TSDBConstants.maxFieldSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxFieldSize(int max) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
if (max < 0)
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxRows() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxRows(int max) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
if (max < 0)
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEscapeProcessing(boolean enable) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(RestfulStatement.STATEMENT_CLOSED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getQueryTimeout() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQueryTimeout(int seconds) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
if (seconds < 0)
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() throws SQLException {
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
// nothing to do
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCursorName(String name) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(RestfulStatement.STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(String sql) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw new SQLException("Invalid method call on a closed statement.");
|
||||
}
|
||||
//如果执行了use操作应该将当前Statement的catalog设置为新的database
|
||||
if (SqlSyntaxValidator.isUseSql(sql)) {
|
||||
this.database = sql.trim().replace("use", "").trim();
|
||||
this.conn.setCatalog(this.database);
|
||||
}
|
||||
if (this.database == null)
|
||||
throw new SQLException("Database not specified or available");
|
||||
|
||||
if (SqlSyntaxValidator.isSelectSql(sql)) {
|
||||
executeQuery(sql);
|
||||
} else if (SqlSyntaxValidator.isShowSql(sql) || SqlSyntaxValidator.isDescribeSql(sql)) {
|
||||
final String url = "http://" + conn.getHost().trim() + ":" + conn.getPort() + "/rest/sql";
|
||||
if (!SqlSyntaxValidator.isShowDatabaseSql(sql)) {
|
||||
HttpClientPoolUtil.execute(url, "use " + conn.getDatabase());
|
||||
}
|
||||
String result = HttpClientPoolUtil.execute(url, sql);
|
||||
JSONObject resultJson = JSON.parseObject(result);
|
||||
if (resultJson.getString("status").equals("error")) {
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code")));
|
||||
}
|
||||
this.resultSet = new RestfulResultSet(database, this, resultJson);
|
||||
} else {
|
||||
executeUpdate(sql);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getResultSet() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
|
@ -275,7 +291,7 @@ public class RestfulStatement implements Statement {
|
|||
@Override
|
||||
public void setFetchSize(int rows) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
if (rows < 0)
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
//nothing to do
|
||||
|
@ -284,28 +300,28 @@ public class RestfulStatement implements Statement {
|
|||
@Override
|
||||
public int getFetchSize() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResultSetConcurrency() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return this.resultSet.getConcurrency();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResultSetType() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return this.resultSet.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBatch(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
//TODO:
|
||||
}
|
||||
|
||||
|
@ -323,14 +339,14 @@ public class RestfulStatement implements Statement {
|
|||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return this.conn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMoreResults(int current) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
if (resultSet == null)
|
||||
return false;
|
||||
|
||||
|
@ -388,7 +404,7 @@ public class RestfulStatement implements Statement {
|
|||
@Override
|
||||
public int getResultSetHoldability() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return this.resultSet.getHoldability();
|
||||
}
|
||||
|
||||
|
@ -400,28 +416,28 @@ public class RestfulStatement implements Statement {
|
|||
@Override
|
||||
public void setPoolable(boolean poolable) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPoolable() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeOnCompletion() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
this.closeOnCompletion = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCloseOnCompletion() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(STATEMENT_CLOSED);
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
return this.closeOnCompletion;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,11 @@ import java.sql.Connection;
|
|||
|
||||
public class SqlSyntaxValidator {
|
||||
|
||||
private static final String[] updateSQL = {"insert", "update", "delete", "create", "alter", "drop", "show", "describe", "use", "import"};
|
||||
private static final String[] querySQL = {"select"};
|
||||
private static final String[] SQL = {"select", "insert", "import", "create", "use", "alter", "drop", "set", "show", "describe"};
|
||||
private static final String[] updateSQL = {"insert", "import", "create", "use", "alter", "drop", "set"};
|
||||
private static final String[] querySQL = {"select", "show", "describe"};
|
||||
|
||||
private static final String[] databaseUnspecifiedShow = {"databases", "dnodes", "mnodes", "variables"};
|
||||
|
||||
private TSDBConnection tsdbConnection;
|
||||
|
||||
|
@ -37,8 +40,38 @@ public class SqlSyntaxValidator {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean isValidForExecuteQuery(String sql) {
|
||||
for (String prefix : querySQL) {
|
||||
if (sql.trim().toLowerCase().startsWith(prefix))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isValidForExecute(String sql) {
|
||||
for (String prefix : SQL) {
|
||||
if (sql.trim().toLowerCase().startsWith(prefix))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isDatabaseUnspecifiedQuery(String sql) {
|
||||
for (String databaseObj : databaseUnspecifiedShow) {
|
||||
if (sql.trim().toLowerCase().matches("show\\s+" + databaseObj + ".*"))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isDatabaseUnspecifiedUpdate(String sql) {
|
||||
sql = sql.trim().toLowerCase();
|
||||
return sql.matches("create\\s+database.*") || sql.startsWith("set") || sql.matches("drop\\s+database.*");
|
||||
}
|
||||
|
||||
public static boolean isUseSql(String sql) {
|
||||
return sql.trim().toLowerCase().startsWith("use") || sql.trim().toLowerCase().matches("create\\s*database.*") || sql.toLowerCase().toLowerCase().matches("drop\\s*database.*");
|
||||
return sql.trim().toLowerCase().startsWith("use");
|
||||
// || sql.trim().toLowerCase().matches("create\\s*database.*") || sql.toLowerCase().toLowerCase().matches("drop\\s*database.*");
|
||||
}
|
||||
|
||||
public static boolean isShowSql(String sql) {
|
||||
|
@ -58,8 +91,9 @@ public class SqlSyntaxValidator {
|
|||
return sql.trim().toLowerCase().startsWith("select");
|
||||
}
|
||||
|
||||
|
||||
public static boolean isShowDatabaseSql(String sql) {
|
||||
return sql.trim().toLowerCase().matches("show\\s*databases");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import com.taosdata.jdbc.TSDBPreparedStatement;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TestPreparedStatement {
|
||||
|
||||
public static void main(String[] args) throws SQLException {
|
||||
Connection connection = null;
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, "localhost");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://localhost:0/", properties);
|
||||
String rawSql = "select * from test.log0601";
|
||||
// String[] params = new String[]{"ts", "c1"};
|
||||
PreparedStatement pstmt = (TSDBPreparedStatement) connection.prepareStatement(rawSql);
|
||||
ResultSet resSet = pstmt.executeQuery();
|
||||
while(resSet.next()) {
|
||||
for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
|
||||
System.out.printf("%d: %s \n", i, resSet.getString(i));
|
||||
}
|
||||
}
|
||||
resSet.close();
|
||||
pstmt.close();
|
||||
connection.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (null != connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import com.taosdata.jdbc.utils.TDNodes;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public abstract class BaseTest {
|
||||
|
||||
private static boolean testCluster = false;
|
||||
private static TDNodes nodes = new TDNodes();
|
||||
|
||||
@BeforeClass
|
||||
public static void setupEnv() {
|
||||
try {
|
||||
if (nodes.getTDNode(1).getTaosdPid() != null) {
|
||||
System.out.println("Kill taosd before running JDBC test");
|
||||
nodes.getTDNode(1).setRunning(1);
|
||||
nodes.stop(1);
|
||||
}
|
||||
nodes.setTestCluster(testCluster);
|
||||
nodes.deploy(1);
|
||||
nodes.start(1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUpEnv() {
|
||||
nodes.stop(1);
|
||||
}
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BatchInsertTest extends BaseTest {
|
||||
|
||||
static Connection connection = null;
|
||||
static Statement statement = null;
|
||||
static String dbName = "test";
|
||||
static String stbName = "meters";
|
||||
static String host = "localhost";
|
||||
static int numOfTables = 30;
|
||||
final static int numOfRecordsPerTable = 1000;
|
||||
static long ts = 1496732686000l;
|
||||
final static String tablePrefix = "t";
|
||||
|
||||
@Before
|
||||
public void createDatabase() throws SQLException {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
|
||||
statement = connection.createStatement();
|
||||
statement.executeUpdate("drop database if exists " + dbName);
|
||||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
statement.executeUpdate("use " + dbName);
|
||||
|
||||
String createTableSql = "create table " + stbName + "(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))";
|
||||
statement.executeUpdate(createTableSql);
|
||||
|
||||
for(int i = 0; i < numOfTables; i++) {
|
||||
String loc = i % 2 == 0 ? "beijing" : "shanghai";
|
||||
String createSubTalbesSql = "create table " + tablePrefix + i + " using " + stbName + " tags(" + i + ", '" + loc + "')";
|
||||
statement.executeUpdate(createSubTalbesSql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchInsert() throws SQLException{
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(numOfTables);
|
||||
|
||||
for (int i = 0; i < numOfTables; i++) {
|
||||
final int index = i;
|
||||
executorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Statement statement = connection.createStatement(); // get statement
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("INSERT INTO " + tablePrefix + index + " VALUES");
|
||||
Random rand = new Random();
|
||||
for (int j = 1; j <= numOfRecordsPerTable; j++) {
|
||||
sb.append("(" + (ts + j) + ", ");
|
||||
sb.append(rand.nextInt(100) + ", ");
|
||||
sb.append(rand.nextInt(100) + ", ");
|
||||
sb.append(rand.nextInt(100) + ")");
|
||||
}
|
||||
statement.addBatch(sb.toString());
|
||||
statement.executeBatch();
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("Thread " + index + " takes " + (endTime - startTime) + " microseconds");
|
||||
connection.commit();
|
||||
statement.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
executorService.shutdown();
|
||||
|
||||
try {
|
||||
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet rs = statement.executeQuery("select * from meters");
|
||||
int num = 0;
|
||||
while (rs.next()) {
|
||||
num++;
|
||||
}
|
||||
assertEquals(num, numOfTables * numOfRecordsPerTable);
|
||||
rs.close();
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void close() throws Exception {
|
||||
statement.close();
|
||||
connection.close();
|
||||
Thread.sleep(10);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
@ -8,53 +9,31 @@ import java.sql.SQLException;
|
|||
import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConnectionTest extends BaseTest {
|
||||
static Connection connection = null;
|
||||
static Statement statement = null;
|
||||
static String dbName = "test";
|
||||
static String stbName = "st";
|
||||
static String host = "localhost";
|
||||
public class ConnectionTest {
|
||||
private Connection connection;
|
||||
private Statement statement;
|
||||
private static String host = "127.0.0.1";
|
||||
|
||||
@Test
|
||||
public void testConnection() throws SQLException {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
public void testConnection() {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
|
||||
assertTrue(null != connection);
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
Assert.assertTrue(null != connection);
|
||||
statement = connection.createStatement();
|
||||
assertTrue(null != statement);
|
||||
|
||||
// try reconnect
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
|
||||
try {
|
||||
statement.execute("create database if not exists " + dbName);
|
||||
} catch (SQLException e) {
|
||||
assert false : "create database error: " + e.getMessage();
|
||||
}
|
||||
|
||||
try {
|
||||
if (!connection.isClosed()) {
|
||||
if (!statement.isClosed()) {
|
||||
statement.executeUpdate("drop database " + dbName);
|
||||
Assert.assertTrue(null != statement);
|
||||
statement.close();
|
||||
}
|
||||
connection.close();
|
||||
Thread.sleep(10);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
assert false : "close connection error: " + e.getMessage();
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,92 +1,112 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.*;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ImportTest extends BaseTest {
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
String dbName = "test";
|
||||
String tName = "t0";
|
||||
String host = "localhost";
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class ImportTest {
|
||||
private static Connection connection;
|
||||
static String dbName = "test";
|
||||
static String tName = "t0";
|
||||
static String host = "127.0.0.1";
|
||||
private static long ts;
|
||||
|
||||
@Before
|
||||
public void createDatabase() throws SQLException {
|
||||
@BeforeClass
|
||||
public static void before() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
|
||||
statement = connection.createStatement();
|
||||
statement.executeUpdate("drop database if exists " + dbName);
|
||||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.execute("create database if not exists " + dbName);
|
||||
stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
|
||||
stmt.close();
|
||||
|
||||
ts = System.currentTimeMillis();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertData() throws Exception {
|
||||
long ts = 1496732686000l;
|
||||
|
||||
public void case001_insertData() throws Exception {
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
ts++;
|
||||
int row = statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")");
|
||||
System.out.println("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")\t" + row);
|
||||
int row = stmt.executeUpdate("import into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")");
|
||||
System.out.println("import into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")\t" + row);
|
||||
assertEquals(1, row);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectData() throws Exception {
|
||||
insertData();
|
||||
String sql = "select * from test.t0";
|
||||
ResultSet resSet = statement.executeQuery(sql);
|
||||
|
||||
while (resSet.next()) {
|
||||
for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
|
||||
System.out.printf(i + ": " + resSet.getString(i) + "\t");
|
||||
}
|
||||
}
|
||||
resSet.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importData() throws Exception {
|
||||
public void case002_checkSum() {
|
||||
Assert.assertEquals(50, select());
|
||||
}
|
||||
|
||||
private int select() {
|
||||
int count = 0;
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
|
||||
String sql = "select * from " + dbName + "." + tName;
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
while (rs.next()) {
|
||||
count++;
|
||||
}
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case003_importData() {
|
||||
// 避免时间重复
|
||||
long ts = 1496732686000l;
|
||||
|
||||
StringBuilder sqlBuilder = new StringBuilder("insert into ").append(dbName).append(".").append(tName).append(" values ");
|
||||
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
StringBuilder sqlBuilder = new StringBuilder("import into ").append(dbName).append(".").append(tName).append(" values ");
|
||||
for (int i = 0; i < 50; i++) {
|
||||
int a = i / 5;
|
||||
long t = ts + a;
|
||||
long t = (++ts) + a;
|
||||
sqlBuilder.append("(").append(t).append(",").append((100 + i)).append(",").append(i).append(") ");
|
||||
}
|
||||
System.out.println(sqlBuilder.toString());
|
||||
int rows = statement.executeUpdate(sqlBuilder.toString());
|
||||
System.out.println(rows);
|
||||
assertEquals(10, rows);
|
||||
int rows = stmt.executeUpdate(sqlBuilder.toString());
|
||||
assertEquals(50, rows);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() throws Exception {
|
||||
@Test
|
||||
public void case004_checkSum() {
|
||||
Assert.assertEquals(100, select());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void close() {
|
||||
try {
|
||||
if (connection != null) {
|
||||
Statement statement = connection.createStatement();
|
||||
statement.executeUpdate("drop database " + dbName);
|
||||
statement.close();
|
||||
connection.close();
|
||||
Thread.sleep(10);
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.*;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import java.sql.*;
|
||||
|
@ -12,14 +9,13 @@ import java.util.Properties;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@FixMethodOrder(MethodSorters.DEFAULT)
|
||||
public class PreparedStatementTest extends BaseTest {
|
||||
static Connection connection = null;
|
||||
static PreparedStatement statement = null;
|
||||
@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
|
||||
public class PreparedStatementTest {
|
||||
static Connection connection;
|
||||
static TSDBPreparedStatement statement;
|
||||
static String dbName = "test";
|
||||
static String tName = "t0";
|
||||
static String host = "localhost";
|
||||
static ResultSet resSet = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void createConnection() throws SQLException {
|
||||
|
@ -29,19 +25,16 @@ public class PreparedStatementTest extends BaseTest {
|
|||
return;
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
|
||||
String sql = "drop database if exists " + dbName;
|
||||
statement = (TSDBPreparedStatement) connection.prepareStatement(sql);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTableAndQuery() throws SQLException {
|
||||
public void case001_createTableAndQuery() throws SQLException {
|
||||
long ts = System.currentTimeMillis();
|
||||
|
||||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
|
@ -49,141 +42,132 @@ public class PreparedStatementTest extends BaseTest {
|
|||
statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
|
||||
|
||||
PreparedStatement selectStatement = connection.prepareStatement("select * from " + dbName + "." + tName);
|
||||
|
||||
ResultSet resultSet = selectStatement.executeQuery();
|
||||
assertTrue(null != resultSet);
|
||||
|
||||
boolean isClosed = statement.isClosed();
|
||||
assertEquals(false, isClosed);
|
||||
selectStatement.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreparedStatement() throws SQLException {
|
||||
public void case002_testPreparedStatement() throws SQLException {
|
||||
long ts = System.currentTimeMillis() + 20000;
|
||||
PreparedStatement saveStatement = connection
|
||||
.prepareStatement("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
|
||||
|
||||
PreparedStatement saveStatement = connection.prepareStatement("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
|
||||
int affectedRows = saveStatement.executeUpdate();
|
||||
assertTrue(1 == affectedRows);
|
||||
saveStatement.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavedPreparedStatement() throws SQLException {
|
||||
public void case003_testSavedPreparedStatement() throws SQLException {
|
||||
long ts = System.currentTimeMillis();
|
||||
|
||||
TSDBPreparedStatement saveStatement = (TSDBPreparedStatement) connection
|
||||
.prepareStatement("insert into " + dbName + "." + tName + " values (?, ?)");
|
||||
|
||||
TSDBPreparedStatement saveStatement = (TSDBPreparedStatement) connection.prepareStatement("insert into " + dbName + "." + tName + " values (?, ?)");
|
||||
saveStatement.setObject(1, ts + 10000);
|
||||
saveStatement.setObject(2, 3);
|
||||
int rows = saveStatement.executeUpdate();
|
||||
assertEquals(1, rows);
|
||||
saveStatement.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupport() {
|
||||
// if(null == resSet) {
|
||||
// return;
|
||||
// }
|
||||
TSDBPreparedStatement tsdbStatement = (TSDBPreparedStatement) statement;
|
||||
public void case004_testUnsupport() throws SQLException {
|
||||
|
||||
Assert.assertNotNull(statement.unwrap(TSDBPreparedStatement.class));
|
||||
Assert.assertTrue(statement.isWrapperFor(TSDBPreparedStatement.class));
|
||||
|
||||
try {
|
||||
tsdbStatement.unwrap(null);
|
||||
statement.getMaxFieldSize();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.isWrapperFor(null);
|
||||
statement.setMaxFieldSize(0);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getMaxFieldSize();
|
||||
statement.setEscapeProcessing(true);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.setMaxFieldSize(0);
|
||||
statement.cancel();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.setEscapeProcessing(true);
|
||||
statement.getWarnings();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.cancel();
|
||||
statement.clearWarnings();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getWarnings();
|
||||
statement.setCursorName(null);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.clearWarnings();
|
||||
statement.getMoreResults();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.setCursorName(null);
|
||||
statement.setFetchDirection(0);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getMoreResults();
|
||||
statement.getFetchDirection();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.setFetchDirection(0);
|
||||
statement.getResultSetConcurrency();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getFetchDirection();
|
||||
statement.getResultSetType();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getResultSetConcurrency();
|
||||
statement.getConnection();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getResultSetType();
|
||||
statement.getMoreResults();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getConnection();
|
||||
statement.getGeneratedKeys();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getMoreResults();
|
||||
statement.executeUpdate(null, 0);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getGeneratedKeys();
|
||||
statement.executeUpdate(null, new int[]{0});
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.executeUpdate(null, 0);
|
||||
statement.executeUpdate(null, new String[]{"str1", "str2"});
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.executeUpdate(null, new int[]{0});
|
||||
statement.getResultSetHoldability();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.executeUpdate(null, new String[]{"str1", "str2"});
|
||||
statement.setPoolable(true);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getResultSetHoldability();
|
||||
statement.isPoolable();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.setPoolable(true);
|
||||
statement.closeOnCompletion();
|
||||
} catch (SQLException e) {
|
||||
|
||||
}
|
||||
try {
|
||||
tsdbStatement.isPoolable();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.closeOnCompletion();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.isCloseOnCompletion();
|
||||
statement.isCloseOnCompletion();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,37 +6,22 @@ import org.junit.Test;
|
|||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
public class QueryDataTest {
|
||||
|
||||
public class QueryDataTest extends BaseTest {
|
||||
|
||||
static Connection connection = null;
|
||||
static Statement statement = null;
|
||||
static Connection connection;
|
||||
static Statement statement;
|
||||
static String dbName = "test";
|
||||
static String stbName = "meters";
|
||||
static String host = "localhost";
|
||||
static int numOfTables = 30;
|
||||
final static int numOfRecordsPerTable = 1000;
|
||||
static long ts = 1496732686000l;
|
||||
final static String tablePrefix = "t";
|
||||
static String host = "127.0.0.1";
|
||||
|
||||
@Before
|
||||
public void createDatabase() throws SQLException {
|
||||
public void createDatabase() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
|
@ -47,35 +32,41 @@ public class QueryDataTest extends BaseTest {
|
|||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
statement.executeUpdate("use " + dbName);
|
||||
|
||||
String createTableSql = "create table " + stbName + "(ts timestamp, name binary(6))";
|
||||
String createTableSql = "create table " + stbName + "(ts timestamp, name binary(64))";
|
||||
statement.executeUpdate(createTableSql);
|
||||
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryBinaryData() throws SQLException {
|
||||
|
||||
String insertSql = "insert into " + stbName + " values(now, 'taosda')";
|
||||
String insertSql = "insert into " + stbName + " values(now, 'taosdata')";
|
||||
System.out.println(insertSql);
|
||||
|
||||
statement.executeUpdate(insertSql);
|
||||
|
||||
String querySql = "select * from " + stbName;
|
||||
ResultSet rs = statement.executeQuery(querySql);
|
||||
|
||||
while (rs.next()) {
|
||||
String name = rs.getString(2) + "001";
|
||||
String name = rs.getString(2);
|
||||
System.out.println("name = " + name);
|
||||
assertEquals(name, "taosda001");
|
||||
assertEquals("taosdata", name);
|
||||
}
|
||||
rs.close();
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void close() throws Exception {
|
||||
public void close() {
|
||||
try {
|
||||
if (statement != null)
|
||||
statement.close();
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
Thread.sleep(10);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -13,42 +14,37 @@ import java.util.Properties;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ResultSetTest extends BaseTest {
|
||||
static Connection connection = null;
|
||||
static Statement statement = null;
|
||||
public class ResultSetTest {
|
||||
static Connection connection;
|
||||
static Statement statement;
|
||||
static String dbName = "test";
|
||||
static String tName = "t0";
|
||||
static String host = "localhost";
|
||||
static ResultSet resSet = null;
|
||||
static ResultSet resSet;
|
||||
|
||||
@BeforeClass
|
||||
public static void createDatabaseAndTable() throws SQLException {
|
||||
public static void createDatabaseAndTable() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
|
||||
statement = connection.createStatement();
|
||||
statement.executeUpdate("drop database if exists " + dbName);
|
||||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
statement.executeUpdate("create table if not exists " + dbName + "." + tName +
|
||||
" (ts timestamp, k1 int, k2 bigint, k3 float, k4 double, k5 binary(30), k6 smallint, k7 bool, k8 nchar(20))");
|
||||
statement.execute("use " + dbName);
|
||||
statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k1 int, k2 bigint, k3 float, k4 double, k5 binary(30), k6 smallint, k7 bool, k8 nchar(20))");
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
statement.executeQuery("use " + dbName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultSet() {
|
||||
String sql = null;
|
||||
String sql;
|
||||
long ts = 1496732686000l;
|
||||
int v1 = 2147483600;
|
||||
long v2 = ts + 1000;
|
||||
|
@ -119,16 +115,8 @@ public class ResultSetTest extends BaseTest {
|
|||
public void testUnsupport() throws SQLException {
|
||||
statement.executeQuery("show databases");
|
||||
resSet = statement.getResultSet();
|
||||
try {
|
||||
resSet.unwrap(null);
|
||||
} catch (SQLException e) {
|
||||
assertTrue(e.getMessage().contains("this operation is NOT supported currently!"));
|
||||
}
|
||||
try {
|
||||
resSet.isWrapperFor(null);
|
||||
} catch (SQLException e) {
|
||||
assertTrue(e.getMessage().contains("this operation is NOT supported currently!"));
|
||||
}
|
||||
Assert.assertNotNull(resSet.unwrap(TSDBResultSet.class));
|
||||
Assert.assertTrue(resSet.isWrapperFor(TSDBResultSet.class));
|
||||
try {
|
||||
resSet.getAsciiStream(0);
|
||||
} catch (SQLException e) {
|
||||
|
@ -815,13 +803,18 @@ public class ResultSetTest extends BaseTest {
|
|||
assertEquals(res.length, 2);
|
||||
statement.clearBatch();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void close() throws Exception {
|
||||
public static void close() {
|
||||
try {
|
||||
statement.executeUpdate("drop database " + dbName);
|
||||
if (statement != null)
|
||||
statement.close();
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
Thread.sleep(10);
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,61 +9,73 @@ import java.util.Properties;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SelectTest extends BaseTest {
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
public class SelectTest {
|
||||
Connection connection;
|
||||
String dbName = "test";
|
||||
String tName = "t0";
|
||||
String host = "localhost";
|
||||
String host = "127.0.0.1";
|
||||
|
||||
@Before
|
||||
public void createDatabaseAndTable() throws SQLException {
|
||||
public void createDatabaseAndTable() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
|
||||
statement = connection.createStatement();
|
||||
statement.executeUpdate("drop database if exists " + dbName);
|
||||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.execute("drop database if exists " + dbName);
|
||||
stmt.execute("create database if not exists " + dbName);
|
||||
stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
|
||||
stmt.close();
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectData() throws SQLException {
|
||||
public void selectData() {
|
||||
long ts = 1496732686000l;
|
||||
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
ts++;
|
||||
int row = statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")");
|
||||
int row = stmt.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")");
|
||||
System.out.println("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")\t" + row);
|
||||
assertEquals(1, row);
|
||||
}
|
||||
|
||||
String sql = "select * from " + dbName + "." + tName;
|
||||
ResultSet resSet = statement.executeQuery(sql);
|
||||
ResultSet resSet = stmt.executeQuery(sql);
|
||||
|
||||
int num = 0;
|
||||
while (resSet.next()) {
|
||||
num++;
|
||||
}
|
||||
resSet.close();
|
||||
|
||||
assertEquals(num, 50);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() throws Exception {
|
||||
statement.executeUpdate("drop database " + dbName);
|
||||
statement.close();
|
||||
public void close() {
|
||||
try {
|
||||
if (connection != null) {
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.executeUpdate("drop database " + dbName);
|
||||
stmt.close();
|
||||
connection.close();
|
||||
Thread.sleep(10);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,69 +12,67 @@ import java.util.Properties;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class StableTest extends BaseTest {
|
||||
static Connection connection = null;
|
||||
static Statement statement = null;
|
||||
static String dbName = "test";
|
||||
static String stbName = "st";
|
||||
static String host = "localhost";
|
||||
public class StableTest {
|
||||
|
||||
private static Connection connection;
|
||||
private static String dbName = "test";
|
||||
private static String stbName = "st";
|
||||
private static String host = "127.0.0.1";
|
||||
|
||||
@BeforeClass
|
||||
public static void createDatabase() throws SQLException {
|
||||
public static void createDatabase() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
|
||||
statement = connection.createStatement();
|
||||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
statement.executeQuery("use " + dbName);
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute("drop database if exists " + dbName);
|
||||
statement.execute("create database if not exists " + dbName);
|
||||
statement.execute("use " + dbName);
|
||||
statement.close();
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void createStable() {
|
||||
String sql = "create table " + stbName + " (ts timestamp, v1 int, v2 int) tags (tg nchar(20)) ";
|
||||
|
||||
try {
|
||||
statement.executeUpdate(sql);
|
||||
@Test
|
||||
public void case001_createSuperTable() {
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
final String sql = "create table " + stbName + " (ts timestamp, v1 int, v2 int) tags (tg nchar(20)) ";
|
||||
stmt.execute(sql);
|
||||
} catch (SQLException e) {
|
||||
assert false : "error create stable" + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void createTable() {
|
||||
String sql = "create table t1 using " + stbName + " tags (\"beijing\")";
|
||||
|
||||
try {
|
||||
statement.executeUpdate(sql);
|
||||
@Test
|
||||
public void case002_createTable() {
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
final String sql = "create table t1 using " + stbName + " tags (\"beijing\")";
|
||||
stmt.execute(sql);
|
||||
} catch (SQLException e) {
|
||||
assert false : "error create table" + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void describeSTable() {
|
||||
createStable();
|
||||
String sql = "describe " + stbName;
|
||||
public void case003_describeSTable() {
|
||||
int num = 0;
|
||||
System.out.println("describe stable");
|
||||
try {
|
||||
ResultSet res = statement.executeQuery(sql);
|
||||
while (res.next()) {
|
||||
for (int i = 1; i <= res.getMetaData().getColumnCount(); i++) {
|
||||
System.out.printf("%d: %s\n", i, res.getString(i));
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
String sql = "describe " + stbName;
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
while (rs.next()) {
|
||||
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
|
||||
System.out.println(i + ":" + rs.getString(i));
|
||||
}
|
||||
num++;
|
||||
}
|
||||
res.close();
|
||||
rs.close();
|
||||
assertEquals(4, num);
|
||||
} catch (SQLException e) {
|
||||
assert false : "error describe stable" + e.getMessage();
|
||||
|
@ -82,41 +80,31 @@ public class StableTest extends BaseTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void describeTable() {
|
||||
createTable();
|
||||
String sql = "describe t1";
|
||||
public void case004_describeTable() {
|
||||
int num = 0;
|
||||
System.out.println("describe table");
|
||||
try {
|
||||
ResultSet res = statement.executeQuery(sql);
|
||||
while (res.next()) {
|
||||
for (int i = 1; i <= res.getMetaData().getColumnCount(); i++) {
|
||||
System.out.printf("%d: %s\n", i, res.getString(i));
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
ResultSet rs = stmt.executeQuery("describe t1");
|
||||
while (rs.next()) {
|
||||
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
|
||||
System.out.printf("%d: %s\n", i, rs.getString(i));
|
||||
}
|
||||
num++;
|
||||
}
|
||||
res.close();
|
||||
rs.close();
|
||||
assertEquals(4, num);
|
||||
} catch (SQLException e) {
|
||||
assert false : "error describe stable" + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void validCreateSql() {
|
||||
String sql = "create table t2 using " + stbName + " tags (\"beijing\")";
|
||||
boolean valid = ((TSDBConnection) connection).getConnection().validateCreateTableSql(sql);
|
||||
assertEquals(true, valid);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void close() throws Exception {
|
||||
if (!statement.isClosed()) {
|
||||
statement.executeUpdate("drop database " + dbName);
|
||||
statement.close();
|
||||
public static void close() {
|
||||
try {
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
Thread.sleep(10);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -16,23 +17,22 @@ public class StatementTest {
|
|||
static String dbName = "test";
|
||||
static String tName = "t0";
|
||||
static String host = "localhost";
|
||||
static ResultSet resSet = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void createConnection() throws SQLException {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", properties);
|
||||
|
||||
statement = connection.createStatement();
|
||||
statement.executeUpdate("drop database if exists " + dbName);
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -49,7 +49,6 @@ public class StatementTest {
|
|||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -67,118 +66,46 @@ public class StatementTest {
|
|||
assertEquals(false, isClosed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupport() {
|
||||
TSDBStatement tsdbStatement = (TSDBStatement) statement;
|
||||
try {
|
||||
tsdbStatement.unwrap(null);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.isWrapperFor(null);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getMaxFieldSize();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.setMaxFieldSize(0);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.setEscapeProcessing(true);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.cancel();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getWarnings();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.clearWarnings();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.setCursorName(null);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getMoreResults();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.setFetchDirection(0);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getFetchDirection();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getResultSetConcurrency();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getResultSetType();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getConnection();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getMoreResults();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getGeneratedKeys();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.executeUpdate(null, 0);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.executeUpdate(null, new int[]{0});
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.executeUpdate(null, new String[]{"str1", "str2"});
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.getResultSetHoldability();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.setPoolable(true);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.isPoolable();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.closeOnCompletion();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
try {
|
||||
tsdbStatement.isCloseOnCompletion();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
@Test(expected = SQLException.class)
|
||||
public void testUnsupport() throws SQLException {
|
||||
Assert.assertNotNull(statement.unwrap(TSDBStatement.class));
|
||||
Assert.assertTrue(statement.isWrapperFor(TSDBStatement.class));
|
||||
|
||||
statement.getMaxFieldSize();
|
||||
statement.setMaxFieldSize(0);
|
||||
statement.setEscapeProcessing(true);
|
||||
statement.cancel();
|
||||
statement.getWarnings();
|
||||
statement.clearWarnings();
|
||||
statement.setCursorName(null);
|
||||
statement.getMoreResults();
|
||||
statement.setFetchDirection(0);
|
||||
statement.getFetchDirection();
|
||||
statement.getResultSetConcurrency();
|
||||
statement.getResultSetType();
|
||||
statement.getConnection();
|
||||
statement.getMoreResults();
|
||||
statement.getGeneratedKeys();
|
||||
statement.executeUpdate(null, 0);
|
||||
statement.executeUpdate(null, new int[]{0});
|
||||
statement.executeUpdate(null, new String[]{"str1", "str2"});
|
||||
statement.getResultSetHoldability();
|
||||
statement.setPoolable(true);
|
||||
statement.isPoolable();
|
||||
statement.closeOnCompletion();
|
||||
statement.isCloseOnCompletion();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void close() throws Exception {
|
||||
if (!statement.isClosed()) {
|
||||
statement.executeUpdate("drop database if exists " + dbName);
|
||||
public static void close() {
|
||||
try {
|
||||
statement.execute("drop database if exists " + dbName);
|
||||
if (statement != null)
|
||||
statement.close();
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
Thread.sleep(10);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,21 +10,18 @@ import java.sql.SQLException;
|
|||
import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
|
||||
public class SubscribeTest extends BaseTest {
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
public class SubscribeTest {
|
||||
Connection connection;
|
||||
Statement statement;
|
||||
String dbName = "test";
|
||||
String tName = "t0";
|
||||
String host = "localhost";
|
||||
String topic = "test";
|
||||
|
||||
@Before
|
||||
public void createDatabase() throws SQLException {
|
||||
public void createDatabase() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
|
@ -41,6 +38,10 @@ public class SubscribeTest extends BaseTest {
|
|||
String sql = "insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")";
|
||||
statement.executeUpdate(sql);
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -79,10 +80,16 @@ public class SubscribeTest extends BaseTest {
|
|||
}
|
||||
|
||||
@After
|
||||
public void close() throws Exception {
|
||||
public void close() {
|
||||
try {
|
||||
statement.executeQuery("drop database " + dbName);
|
||||
if (statement != null)
|
||||
statement.close();
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
Thread.sleep(10);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,26 +1,14 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.*;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TSDBDatabaseMetaDataTest {
|
||||
private TSDBDatabaseMetaData metaData;
|
||||
private static final String host = "localhost";
|
||||
|
||||
@Before
|
||||
public void before() throws ClassNotFoundException, SQLException {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
metaData = (TSDBDatabaseMetaData) DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties).getMetaData();
|
||||
}
|
||||
private static final String host = "127.0.0.1";
|
||||
private static Connection connection;
|
||||
private static TSDBDatabaseMetaData metaData;
|
||||
|
||||
@Test
|
||||
public void unwrap() throws SQLException {
|
||||
|
@ -45,7 +33,7 @@ public class TSDBDatabaseMetaDataTest {
|
|||
|
||||
@Test
|
||||
public void getURL() throws SQLException {
|
||||
Assert.assertEquals("jdbc:TAOS://localhost:6030/?user=root&password=taosdata", metaData.getURL());
|
||||
Assert.assertEquals("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", metaData.getURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -639,6 +627,7 @@ public class TSDBDatabaseMetaDataTest {
|
|||
|
||||
@Test
|
||||
public void getTables() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
ResultSet tables = metaData.getTables("log", "", null, null);
|
||||
ResultSetMetaData metaData = tables.getMetaData();
|
||||
while (tables.next()) {
|
||||
|
@ -658,6 +647,8 @@ public class TSDBDatabaseMetaDataTest {
|
|||
|
||||
@Test
|
||||
public void getCatalogs() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
|
||||
ResultSet catalogs = metaData.getCatalogs();
|
||||
ResultSetMetaData meta = catalogs.getMetaData();
|
||||
while (catalogs.next()) {
|
||||
|
@ -670,6 +661,8 @@ public class TSDBDatabaseMetaDataTest {
|
|||
|
||||
@Test
|
||||
public void getTableTypes() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
|
||||
ResultSet tableTypes = metaData.getTableTypes();
|
||||
while (tableTypes.next()) {
|
||||
System.out.println(tableTypes.getString("TABLE_TYPE"));
|
||||
|
@ -679,6 +672,8 @@ public class TSDBDatabaseMetaDataTest {
|
|||
|
||||
@Test
|
||||
public void getColumns() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
|
||||
ResultSet columns = metaData.getColumns("log", "", "dn", "");
|
||||
ResultSetMetaData meta = columns.getMetaData();
|
||||
while (columns.next()) {
|
||||
|
@ -717,6 +712,8 @@ public class TSDBDatabaseMetaDataTest {
|
|||
|
||||
@Test
|
||||
public void getPrimaryKeys() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
|
||||
ResultSet rs = metaData.getPrimaryKeys("log", "", "dn1");
|
||||
while (rs.next()) {
|
||||
System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME"));
|
||||
|
@ -850,6 +847,8 @@ public class TSDBDatabaseMetaDataTest {
|
|||
|
||||
@Test
|
||||
public void getSuperTables() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
|
||||
ResultSet rs = metaData.getSuperTables("log", "", "dn1");
|
||||
while (rs.next()) {
|
||||
System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME"));
|
||||
|
@ -914,11 +913,6 @@ public class TSDBDatabaseMetaDataTest {
|
|||
Assert.assertNull(metaData.getRowIdLifetime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSchemas() throws SQLException {
|
||||
Assert.assertNull(metaData.getSchemas());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsStoredFunctionsUsingCallSyntax() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsStoredFunctionsUsingCallSyntax());
|
||||
|
@ -953,4 +947,32 @@ public class TSDBDatabaseMetaDataTest {
|
|||
public void generatedKeyAlwaysReturned() throws SQLException {
|
||||
Assert.assertFalse(metaData.generatedKeyAlwaysReturned());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties);
|
||||
metaData = connection.getMetaData().unwrap(TSDBDatabaseMetaData.class);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
try {
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,9 +3,6 @@ package com.taosdata.jdbc;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -27,54 +24,15 @@ public class TSDBDriverTest {
|
|||
"jdbc:TAOS://:/test",
|
||||
"jdbc:TAOS://localhost:0/?user=root&password=taosdata"
|
||||
};
|
||||
private static boolean islibLoaded = false;
|
||||
private static boolean isTaosdActived;
|
||||
|
||||
private Connection conn;
|
||||
|
||||
@BeforeClass
|
||||
public static void before() {
|
||||
String osName = System.getProperty("os.name").toLowerCase();
|
||||
if (!osName.equals("linux"))
|
||||
return;
|
||||
// try to load taos lib
|
||||
try {
|
||||
System.loadLibrary("taos");
|
||||
islibLoaded = true;
|
||||
} catch (UnsatisfiedLinkError error) {
|
||||
System.out.println("load tdengine lib failed.");
|
||||
error.printStackTrace();
|
||||
}
|
||||
// check taosd is activated
|
||||
try {
|
||||
String[] cmd = {"/bin/bash", "-c", "ps -ef | grep taosd | grep -v \"grep\""};
|
||||
Process exec = Runtime.getRuntime().exec(cmd);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
|
||||
int lineCnt = 0;
|
||||
while (reader.readLine() != null) {
|
||||
lineCnt++;
|
||||
}
|
||||
if (lineCnt > 0)
|
||||
isTaosdActived = true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectWithJdbcURL() {
|
||||
final String url = "jdbc:TAOS://localhost:6030/log?user=root&password=taosdata";
|
||||
try {
|
||||
if (islibLoaded && isTaosdActived) {
|
||||
conn = DriverManager.getConnection(url);
|
||||
assertNotNull("failure - connection should not be null", conn);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
fail("failure - should not throw Exception");
|
||||
|
@ -89,10 +47,8 @@ public class TSDBDriverTest {
|
|||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
try {
|
||||
if (islibLoaded && isTaosdActived) {
|
||||
conn = DriverManager.getConnection(jdbcUrl, connProps);
|
||||
assertNotNull("failure - connection should not be null", conn);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
fail("failure - should not throw Exception");
|
||||
|
@ -107,10 +63,8 @@ public class TSDBDriverTest {
|
|||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
try {
|
||||
if (islibLoaded && isTaosdActived) {
|
||||
conn = DriverManager.getConnection(jdbcUrl, connProps);
|
||||
assertNotNull("failure - connection should not be null", conn);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
fail("failure - should not throw Exception");
|
||||
|
@ -207,4 +161,14 @@ public class TSDBDriverTest {
|
|||
assertNull("failure - getParentLogger should be be null", new TSDBDriver().getParentLogger());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void before() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,186 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class TSDBPreparedStatementTest {
|
||||
private static final String host = "127.0.0.1";
|
||||
private static Connection conn;
|
||||
|
||||
@Test
|
||||
public void executeQuery() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executeUpdate() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNull() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBoolean() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setByte() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setShort() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setInt() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLong() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setFloat() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDouble() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBigDecimal() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setString() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBytes() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDate() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTime() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTimestamp() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsciiStream() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setUnicodeStream() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBinaryStream() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearParameters() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setObject() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void execute() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addBatch() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCharacterStream() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setRef() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBlob() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setClob() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setArray() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetaData() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setURL() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParameterMetaData() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setRowId() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNString() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNCharacterStream() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNClob() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSQLXML() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
try {
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,12 @@
|
|||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import com.taosdata.jdbc.lib.TSDBCommon;
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -18,23 +16,40 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
public class BatchInsertTest {
|
||||
|
||||
static String host = "localhost";
|
||||
static String host = "127.0.0.1";
|
||||
static String dbName = "test";
|
||||
static String stbName = "meters";
|
||||
static int numOfTables = 30;
|
||||
final static int numOfRecordsPerTable = 1000;
|
||||
static long ts = 1496732686000l;
|
||||
final static String tablePrefix = "t";
|
||||
|
||||
private Connection connection;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
try {
|
||||
connection = TSDBCommon.getConn(host);
|
||||
TSDBCommon.createDatabase(connection, dbName);
|
||||
TSDBCommon.createStable(connection, stbName);
|
||||
TSDBCommon.createTables(connection, numOfTables, stbName, tablePrefix);
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
|
||||
Statement statement = connection.createStatement();
|
||||
statement.executeUpdate("drop database if exists " + dbName);
|
||||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
statement.executeUpdate("use " + dbName);
|
||||
// create stable
|
||||
String createTableSql = "create table " + stbName + "(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))";
|
||||
statement.executeUpdate(createTableSql);
|
||||
// create tables
|
||||
for(int i = 0; i < numOfTables; i++) {
|
||||
String loc = i % 2 == 0 ? "beijing" : "shanghai";
|
||||
String createSubTalbesSql = "create table " + tablePrefix + i + " using " + stbName + " tags(" + i + ", '" + loc + "')";
|
||||
statement.executeUpdate(createSubTalbesSql);
|
||||
}
|
||||
statement.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -45,9 +60,7 @@ public class BatchInsertTest {
|
|||
ExecutorService executorService = Executors.newFixedThreadPool(numOfTables);
|
||||
for (int i = 0; i < numOfTables; i++) {
|
||||
final int index = i;
|
||||
executorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
executorService.execute(() -> {
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Statement statement = connection.createStatement(); // get statement
|
||||
|
@ -69,7 +82,6 @@ public class BatchInsertTest {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -102,7 +114,6 @@ public class BatchInsertTest {
|
|||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
package com.taosdata.jdbc.lib;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TSDBCommon {
|
||||
|
||||
public static Connection getConn(String host) throws SQLException, ClassNotFoundException {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
return DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
}
|
||||
|
||||
public static void createDatabase(Connection connection, String dbName) throws SQLException {
|
||||
Statement statement = connection.createStatement();
|
||||
statement.executeUpdate("drop database if exists " + dbName);
|
||||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
statement.executeUpdate("use " + dbName);
|
||||
statement.close();
|
||||
}
|
||||
|
||||
public static void createStable(Connection connection, String stbName) throws SQLException {
|
||||
Statement statement = connection.createStatement();
|
||||
String createTableSql = "create table " + stbName + "(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))";
|
||||
statement.executeUpdate(createTableSql);
|
||||
statement.close();
|
||||
}
|
||||
|
||||
public static void createTables(Connection connection, int numOfTables, String stbName,String tablePrefix) throws SQLException {
|
||||
Statement statement = connection.createStatement();
|
||||
for(int i = 0; i < numOfTables; i++) {
|
||||
String loc = i % 2 == 0 ? "beijing" : "shanghai";
|
||||
String createSubTalbesSql = "create table " + tablePrefix + i + " using " + stbName + " tags(" + i + ", '" + loc + "')";
|
||||
statement.executeUpdate(createSubTalbesSql);
|
||||
}
|
||||
statement.close();
|
||||
}
|
||||
}
|
|
@ -7,8 +7,8 @@ import java.sql.*;
|
|||
|
||||
public class AuthenticationTest {
|
||||
|
||||
// private static final String host = "127.0.0.1";
|
||||
private static final String host = "master";
|
||||
private static final String host = "127.0.0.1";
|
||||
// private static final String host = "master";
|
||||
private static final String user = "root";
|
||||
private static final String password = "123456";
|
||||
private Connection conn;
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.junit.Test;
|
|||
import java.sql.*;
|
||||
|
||||
public class RestfulDriverTest {
|
||||
private static final String host = "master";
|
||||
private static final String host = "127.0.0.1";
|
||||
|
||||
@Test
|
||||
public void connect() {
|
||||
|
|
|
@ -9,24 +9,13 @@ import java.util.Random;
|
|||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class RestfulJDBCTest {
|
||||
|
||||
private static final String host = "master";
|
||||
private Connection connection;
|
||||
|
||||
@Before
|
||||
public void before() throws ClassNotFoundException, SQLException {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata");
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws SQLException {
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
}
|
||||
|
||||
private static final String host = "127.0.0.1";
|
||||
// private static final String host = "master";
|
||||
private static Connection connection;
|
||||
private Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
/**
|
||||
* 查询所有log.log
|
||||
* select * from log.log
|
||||
**/
|
||||
@Test
|
||||
public void testCase001() {
|
||||
|
@ -85,7 +74,6 @@ public class RestfulJDBCTest {
|
|||
}
|
||||
}
|
||||
|
||||
private Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
@Test
|
||||
public void testCase005() {
|
||||
|
@ -105,5 +93,50 @@ public class RestfulJDBCTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase006() {
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
ResultSet rs = stmt.executeQuery("select * from weather");
|
||||
while (rs.next()) {
|
||||
System.out.print("ts: " + rs.getTimestamp("ts"));
|
||||
System.out.print(", temperature: " + rs.getString("temperature"));
|
||||
System.out.print(", humidity: " + rs.getString("humidity"));
|
||||
System.out.println(", location: " + rs.getString("location"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase007() {
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
ResultSet rs = stmt.executeQuery("select * from weather");
|
||||
ResultSetMetaData meta = rs.getMetaData();
|
||||
while (rs.next()) {
|
||||
int columnCount = meta.getColumnCount();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
String columnLabel = meta.getColumnLabel(i);
|
||||
String value = rs.getString(i);
|
||||
System.out.print(columnLabel + ": " + value + "\t");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void before() throws ClassNotFoundException, SQLException {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void after() throws SQLException {
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,221 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class RestfulResultSetMetaDataTest {
|
||||
|
||||
private static final String host = "127.0.0.1";
|
||||
// private static final String host = "master";
|
||||
|
||||
private static Connection conn;
|
||||
private static Statement stmt;
|
||||
private static ResultSet rs;
|
||||
private static ResultSetMetaData meta;
|
||||
|
||||
@Test
|
||||
public void getColumnCount() throws SQLException {
|
||||
Assert.assertEquals(10, meta.getColumnCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAutoIncrement() throws SQLException {
|
||||
Assert.assertFalse(meta.isAutoIncrement(1));
|
||||
Assert.assertFalse(meta.isAutoIncrement(2));
|
||||
Assert.assertFalse(meta.isAutoIncrement(3));
|
||||
Assert.assertFalse(meta.isAutoIncrement(4));
|
||||
Assert.assertFalse(meta.isAutoIncrement(5));
|
||||
Assert.assertFalse(meta.isAutoIncrement(6));
|
||||
Assert.assertFalse(meta.isAutoIncrement(7));
|
||||
Assert.assertFalse(meta.isAutoIncrement(8));
|
||||
Assert.assertFalse(meta.isAutoIncrement(9));
|
||||
Assert.assertFalse(meta.isAutoIncrement(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCaseSensitive() throws SQLException {
|
||||
Assert.assertFalse(meta.isCaseSensitive(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSearchable() throws SQLException {
|
||||
Assert.assertTrue(meta.isSearchable(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCurrency() throws SQLException {
|
||||
Assert.assertFalse(meta.isCurrency(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isNullable() throws SQLException {
|
||||
Assert.assertEquals(ResultSetMetaData.columnNoNulls, meta.isNullable(1));
|
||||
Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(2));
|
||||
Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(3));
|
||||
Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(4));
|
||||
Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(5));
|
||||
Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(6));
|
||||
Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(7));
|
||||
Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(8));
|
||||
Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(9));
|
||||
Assert.assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSigned() throws SQLException {
|
||||
Assert.assertFalse(meta.isSigned(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getColumnDisplaySize() throws SQLException {
|
||||
Assert.assertEquals(64, meta.getColumnDisplaySize(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getColumnLabel() throws SQLException {
|
||||
Assert.assertEquals("f1", meta.getColumnLabel(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getColumnName() throws SQLException {
|
||||
Assert.assertEquals("f1", meta.getColumnName(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemaName() throws SQLException {
|
||||
Assert.assertEquals("", meta.getSchemaName(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPrecision() throws SQLException {
|
||||
Assert.assertEquals(0, meta.getPrecision(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getScale() throws SQLException {
|
||||
Assert.assertEquals(0, meta.getScale(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTableName() throws SQLException {
|
||||
Assert.assertEquals("", meta.getTableName(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCatalogName() throws SQLException {
|
||||
Assert.assertEquals("restful_test", meta.getCatalogName(1));
|
||||
Assert.assertEquals("restful_test", meta.getCatalogName(2));
|
||||
Assert.assertEquals("restful_test", meta.getCatalogName(3));
|
||||
Assert.assertEquals("restful_test", meta.getCatalogName(4));
|
||||
Assert.assertEquals("restful_test", meta.getCatalogName(5));
|
||||
Assert.assertEquals("restful_test", meta.getCatalogName(6));
|
||||
Assert.assertEquals("restful_test", meta.getCatalogName(7));
|
||||
Assert.assertEquals("restful_test", meta.getCatalogName(8));
|
||||
Assert.assertEquals("restful_test", meta.getCatalogName(9));
|
||||
Assert.assertEquals("restful_test", meta.getCatalogName(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getColumnType() throws SQLException {
|
||||
Assert.assertEquals(Types.TIMESTAMP, meta.getColumnType(1));
|
||||
Assert.assertEquals(Types.INTEGER, meta.getColumnType(2));
|
||||
Assert.assertEquals(Types.BIGINT, meta.getColumnType(3));
|
||||
Assert.assertEquals(Types.FLOAT, meta.getColumnType(4));
|
||||
Assert.assertEquals(Types.DOUBLE, meta.getColumnType(5));
|
||||
Assert.assertEquals(Types.BINARY, meta.getColumnType(6));
|
||||
Assert.assertEquals(Types.SMALLINT, meta.getColumnType(7));
|
||||
Assert.assertEquals(Types.TINYINT, meta.getColumnType(8));
|
||||
Assert.assertEquals(Types.BOOLEAN, meta.getColumnType(9));
|
||||
Assert.assertEquals(Types.NCHAR, meta.getColumnType(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getColumnTypeName() throws SQLException {
|
||||
Assert.assertEquals("TIMESTAMP", meta.getColumnTypeName(1));
|
||||
Assert.assertEquals("INT", meta.getColumnTypeName(2));
|
||||
Assert.assertEquals("BIGINT", meta.getColumnTypeName(3));
|
||||
Assert.assertEquals("FLOAT", meta.getColumnTypeName(4));
|
||||
Assert.assertEquals("DOUBLE", meta.getColumnTypeName(5));
|
||||
Assert.assertEquals("BINARY", meta.getColumnTypeName(6));
|
||||
Assert.assertEquals("SMALLINT", meta.getColumnTypeName(7));
|
||||
Assert.assertEquals("TINYINT", meta.getColumnTypeName(8));
|
||||
Assert.assertEquals("BOOL", meta.getColumnTypeName(9));
|
||||
Assert.assertEquals("NCHAR", meta.getColumnTypeName(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReadOnly() throws SQLException {
|
||||
Assert.assertTrue(meta.isReadOnly(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isWritable() throws SQLException {
|
||||
Assert.assertFalse(meta.isWritable(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDefinitelyWritable() throws SQLException {
|
||||
Assert.assertFalse(meta.isDefinitelyWritable(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getColumnClassName() throws SQLException {
|
||||
Assert.assertEquals(Timestamp.class.getName(), meta.getColumnClassName(1));
|
||||
Assert.assertEquals(Integer.class.getName(), meta.getColumnClassName(2));
|
||||
Assert.assertEquals(Long.class.getName(), meta.getColumnClassName(3));
|
||||
Assert.assertEquals(Float.class.getName(), meta.getColumnClassName(4));
|
||||
Assert.assertEquals(Double.class.getName(), meta.getColumnClassName(5));
|
||||
Assert.assertEquals(String.class.getName(), meta.getColumnClassName(6));
|
||||
Assert.assertEquals(Short.class.getName(), meta.getColumnClassName(7));
|
||||
Assert.assertEquals(Short.class.getName(), meta.getColumnClassName(8));
|
||||
Assert.assertEquals(Boolean.class.getName(), meta.getColumnClassName(9));
|
||||
Assert.assertEquals(String.class.getName(), meta.getColumnClassName(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unwrap() throws SQLException {
|
||||
Assert.assertNotNull(meta.unwrap(RestfulResultSetMetaData.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isWrapperFor() throws SQLException {
|
||||
Assert.assertTrue(meta.isWrapperFor(RestfulResultSetMetaData.class));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata");
|
||||
stmt = conn.createStatement();
|
||||
stmt.execute("create database if not exists restful_test");
|
||||
stmt.execute("use restful_test");
|
||||
stmt.execute("drop table if exists weather");
|
||||
stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))");
|
||||
stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')");
|
||||
rs = stmt.executeQuery("select * from restful_test.weather");
|
||||
rs.next();
|
||||
meta = rs.getMetaData();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
if (stmt != null)
|
||||
stmt.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,588 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.*;
|
||||
|
||||
public class RestfulResultSetTest {
|
||||
|
||||
private static final String host = "127.0.0.1";
|
||||
// private static final String host = "master";
|
||||
|
||||
private static Connection conn;
|
||||
private static Statement stmt;
|
||||
private static ResultSet rs;
|
||||
|
||||
@Test
|
||||
public void wasNull() throws SQLException {
|
||||
Assert.assertFalse(rs.wasNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getString() throws SQLException {
|
||||
String f10 = rs.getString("f10");
|
||||
Assert.assertEquals("涛思数据", f10);
|
||||
f10 = rs.getString(10);
|
||||
Assert.assertEquals("涛思数据", f10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBoolean() throws SQLException {
|
||||
Boolean f9 = rs.getBoolean("f9");
|
||||
Assert.assertEquals(true, f9);
|
||||
f9 = rs.getBoolean(9);
|
||||
Assert.assertEquals(true, f9);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getByte() throws SQLException {
|
||||
rs.getByte(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getShort() throws SQLException {
|
||||
short f7 = rs.getShort("f7");
|
||||
Assert.assertEquals(10, f7);
|
||||
f7 = rs.getShort(7);
|
||||
Assert.assertEquals(10, f7);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInt() throws SQLException {
|
||||
int f2 = rs.getInt("f2");
|
||||
Assert.assertEquals(1, f2);
|
||||
f2 = rs.getInt(2);
|
||||
Assert.assertEquals(1, f2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLong() throws SQLException {
|
||||
long f3 = rs.getLong("f3");
|
||||
Assert.assertEquals(100, f3);
|
||||
f3 = rs.getLong(3);
|
||||
Assert.assertEquals(100, f3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFloat() throws SQLException {
|
||||
float f4 = rs.getFloat("f4");
|
||||
Assert.assertEquals(3.1415f, f4, 0f);
|
||||
f4 = rs.getFloat(4);
|
||||
Assert.assertEquals(3.1415f, f4, 0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDouble() throws SQLException {
|
||||
double f5 = rs.getDouble("f5");
|
||||
Assert.assertEquals(3.1415926, f5, 0.0);
|
||||
f5 = rs.getDouble(5);
|
||||
Assert.assertEquals(3.1415926, f5, 0.0);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getBigDecimal() throws SQLException {
|
||||
rs.getBigDecimal("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getBytes() throws SQLException {
|
||||
rs.getBytes("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getDate() throws SQLException {
|
||||
rs.getDate("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getTime() throws SQLException {
|
||||
rs.getTime("f1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTimestamp() throws SQLException {
|
||||
Timestamp f1 = rs.getTimestamp("f1");
|
||||
Assert.assertEquals("2021-01-01 00:00:00.0", f1.toString());
|
||||
f1 = rs.getTimestamp(1);
|
||||
Assert.assertEquals("2021-01-01 00:00:00.0", f1.toString());
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getAsciiStream() throws SQLException {
|
||||
rs.getAsciiStream("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getUnicodeStream() throws SQLException {
|
||||
rs.getUnicodeStream("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getBinaryStream() throws SQLException {
|
||||
rs.getBinaryStream("f1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWarnings() throws SQLException {
|
||||
Assert.assertNull(rs.getWarnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearWarnings() throws SQLException {
|
||||
rs.clearWarnings();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getCursorName() throws SQLException {
|
||||
rs.getCursorName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetaData() throws SQLException {
|
||||
ResultSetMetaData meta = rs.getMetaData();
|
||||
Assert.assertNotNull(meta);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getObject() throws SQLException {
|
||||
rs.getObject("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLException.class)
|
||||
public void findColumn() throws SQLException {
|
||||
int columnIndex = rs.findColumn("f1");
|
||||
Assert.assertEquals(1, columnIndex);
|
||||
columnIndex = rs.findColumn("f2");
|
||||
Assert.assertEquals(2, columnIndex);
|
||||
columnIndex = rs.findColumn("f3");
|
||||
Assert.assertEquals(3, columnIndex);
|
||||
columnIndex = rs.findColumn("f4");
|
||||
Assert.assertEquals(4, columnIndex);
|
||||
columnIndex = rs.findColumn("f5");
|
||||
Assert.assertEquals(5, columnIndex);
|
||||
columnIndex = rs.findColumn("f6");
|
||||
Assert.assertEquals(6, columnIndex);
|
||||
columnIndex = rs.findColumn("f7");
|
||||
Assert.assertEquals(7, columnIndex);
|
||||
columnIndex = rs.findColumn("f8");
|
||||
Assert.assertEquals(8, columnIndex);
|
||||
columnIndex = rs.findColumn("f9");
|
||||
Assert.assertEquals(9, columnIndex);
|
||||
columnIndex = rs.findColumn("f10");
|
||||
Assert.assertEquals(10, columnIndex);
|
||||
|
||||
rs.findColumn("f11");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getCharacterStream() throws SQLException {
|
||||
rs.getCharacterStream(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isBeforeFirst() throws SQLException {
|
||||
Assert.assertFalse(rs.isBeforeFirst());
|
||||
rs.beforeFirst();
|
||||
Assert.assertTrue(rs.isBeforeFirst());
|
||||
rs.next();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAfterLast() throws SQLException {
|
||||
Assert.assertFalse(rs.isAfterLast());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFirst() throws SQLException {
|
||||
Assert.assertTrue(rs.isFirst());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isLast() throws SQLException {
|
||||
Assert.assertTrue(rs.isLast());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeFirst() throws SQLException {
|
||||
rs.beforeFirst();
|
||||
Assert.assertTrue(rs.isBeforeFirst());
|
||||
rs.next();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterLast() throws SQLException {
|
||||
rs.afterLast();
|
||||
Assert.assertTrue(rs.isAfterLast());
|
||||
rs.first();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void first() throws SQLException {
|
||||
rs.first();
|
||||
Assert.assertEquals("2021-01-01 00:00:00.0", rs.getTimestamp("f1").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void last() throws SQLException {
|
||||
rs.last();
|
||||
Assert.assertEquals("2021-01-01 00:00:00.0", rs.getTimestamp("f1").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRow() throws SQLException {
|
||||
int row = rs.getRow();
|
||||
Assert.assertEquals(1, row);
|
||||
rs.beforeFirst();
|
||||
row = rs.getRow();
|
||||
Assert.assertEquals(0, row);
|
||||
rs.first();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void absolute() throws SQLException {
|
||||
rs.absolute(-1);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void relative() throws SQLException {
|
||||
rs.relative(-1);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void previous() throws SQLException {
|
||||
rs.previous();
|
||||
}
|
||||
|
||||
@Test(expected = SQLException.class)
|
||||
public void setFetchDirection() throws SQLException {
|
||||
rs.setFetchDirection(ResultSet.FETCH_FORWARD);
|
||||
rs.setFetchDirection(ResultSet.FETCH_UNKNOWN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFetchDirection() throws SQLException {
|
||||
Assert.assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection());
|
||||
}
|
||||
|
||||
@Test(expected = SQLException.class)
|
||||
public void setFetchSize() throws SQLException {
|
||||
rs.setFetchSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFetchSize() throws SQLException {
|
||||
Assert.assertEquals(1, rs.getFetchSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getType() throws SQLException {
|
||||
Assert.assertEquals(ResultSet.TYPE_FORWARD_ONLY, rs.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getConcurrency() throws SQLException {
|
||||
Assert.assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void rowUpdated() throws SQLException {
|
||||
rs.rowUpdated();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void rowInserted() throws SQLException {
|
||||
rs.rowInserted();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void rowDeleted() throws SQLException {
|
||||
rs.rowDeleted();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateNull() throws SQLException {
|
||||
rs.updateNull("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateBoolean() throws SQLException {
|
||||
rs.updateBoolean(1, false);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateByte() throws SQLException {
|
||||
rs.updateByte(1, new Byte("0"));
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateShort() throws SQLException {
|
||||
rs.updateShort(1, new Short("0"));
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateInt() throws SQLException {
|
||||
rs.updateInt(1, 1);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateLong() throws SQLException {
|
||||
rs.updateLong(1, 1l);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateFloat() throws SQLException {
|
||||
rs.updateFloat(1, 1f);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateDouble() throws SQLException {
|
||||
rs.updateDouble(1, 1.0);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateBigDecimal() throws SQLException {
|
||||
rs.updateBigDecimal(1, new BigDecimal(1));
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateString() throws SQLException {
|
||||
rs.updateString(1, "abc");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateBytes() throws SQLException {
|
||||
rs.updateBytes(1, new byte[]{});
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateDate() throws SQLException {
|
||||
rs.updateDate(1, new Date(System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateTime() throws SQLException {
|
||||
rs.updateTime(1, new Time(System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateTimestamp() throws SQLException {
|
||||
rs.updateTimestamp(1, new Timestamp(System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateAsciiStream() throws SQLException {
|
||||
rs.updateAsciiStream(1, null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateBinaryStream() throws SQLException {
|
||||
rs.updateBinaryStream(1, null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateCharacterStream() throws SQLException {
|
||||
rs.updateCharacterStream(1, null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateObject() throws SQLException {
|
||||
rs.updateObject(1, null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void insertRow() throws SQLException {
|
||||
rs.insertRow();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateRow() throws SQLException {
|
||||
rs.updateRow();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void deleteRow() throws SQLException {
|
||||
rs.deleteRow();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void refreshRow() throws SQLException {
|
||||
rs.refreshRow();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void cancelRowUpdates() throws SQLException {
|
||||
rs.cancelRowUpdates();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void moveToInsertRow() throws SQLException {
|
||||
rs.moveToInsertRow();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStatement() throws SQLException {
|
||||
Statement stmt = rs.getStatement();
|
||||
Assert.assertNotNull(stmt);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void moveToCurrentRow() throws SQLException {
|
||||
rs.moveToCurrentRow();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getRef() throws SQLException {
|
||||
rs.getRef(1);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getBlob() throws SQLException {
|
||||
rs.getBlob("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getClob() throws SQLException {
|
||||
rs.getClob("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getArray() throws SQLException {
|
||||
rs.getArray("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getURL() throws SQLException {
|
||||
rs.getURL("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateRef() throws SQLException {
|
||||
rs.updateRef("f1", null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateBlob() throws SQLException {
|
||||
rs.updateBlob(1, (InputStream) null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateClob() throws SQLException {
|
||||
rs.updateClob(1, (Reader) null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateArray() throws SQLException {
|
||||
rs.updateArray(1, null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getRowId() throws SQLException {
|
||||
rs.getRowId("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateRowId() throws SQLException {
|
||||
rs.updateRowId(1, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHoldability() throws SQLException {
|
||||
Assert.assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, rs.getHoldability());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isClosed() throws SQLException {
|
||||
Assert.assertFalse(rs.isClosed());
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateNString() throws SQLException {
|
||||
rs.updateNString(1, null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateNClob() throws SQLException {
|
||||
rs.updateNClob(1, (Reader) null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getNClob() throws SQLException {
|
||||
rs.getNClob("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getSQLXML() throws SQLException {
|
||||
rs.getSQLXML("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateSQLXML() throws SQLException {
|
||||
rs.updateSQLXML(1, null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getNString() throws SQLException {
|
||||
rs.getNString("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getNCharacterStream() throws SQLException {
|
||||
rs.getNCharacterStream("f1");
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void updateNCharacterStream() throws SQLException {
|
||||
rs.updateNCharacterStream(1, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unwrap() throws SQLException {
|
||||
RestfulResultSet unwrap = rs.unwrap(RestfulResultSet.class);
|
||||
Assert.assertNotNull(unwrap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isWrapperFor() throws SQLException {
|
||||
Assert.assertTrue(rs.isWrapperFor(RestfulResultSet.class));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata");
|
||||
stmt = conn.createStatement();
|
||||
stmt.execute("create database if not exists restful_test");
|
||||
stmt.execute("use restful_test");
|
||||
stmt.execute("drop table if exists weather");
|
||||
stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))");
|
||||
stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')");
|
||||
rs = stmt.executeQuery("select * from restful_test.weather");
|
||||
rs.next();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
if (stmt != null)
|
||||
stmt.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import com.taosdata.jdbc.utils.SQLExecutor;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
||||
|
@ -10,379 +11,316 @@ import java.sql.*;
|
|||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class SQLTest {
|
||||
private static final String host = "master";
|
||||
|
||||
private static final String host = "127.0.0.1";
|
||||
// private static final String host = "master";
|
||||
private static Connection connection;
|
||||
|
||||
@Test
|
||||
public void testCase001() {
|
||||
String sql = "create database if not exists restful_test";
|
||||
execute(sql);
|
||||
SQLExecutor.execute(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase002() {
|
||||
String sql = "use restful_test";
|
||||
execute(sql);
|
||||
SQLExecutor.execute(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase003() {
|
||||
String sql = "show databases";
|
||||
executeWithResult(sql);
|
||||
SQLExecutor.executeWithResult(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase004() {
|
||||
String sql = "show tables";
|
||||
executeWithResult(sql);
|
||||
SQLExecutor.executeWithResult(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase005() {
|
||||
String sql = "show stables";
|
||||
executeWithResult(sql);
|
||||
SQLExecutor.executeWithResult(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase006() {
|
||||
String sql = "show dnodes";
|
||||
executeWithResult(sql);
|
||||
SQLExecutor.executeWithResult(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase007() {
|
||||
String sql = "show vgroups";
|
||||
executeWithResult(sql);
|
||||
SQLExecutor.executeWithResult(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase008() {
|
||||
String sql = "drop table if exists restful_test.weather";
|
||||
execute(sql);
|
||||
SQLExecutor.execute(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase009() {
|
||||
String sql = "create table if not exists restful_test.weather(ts timestamp, temperature float) tags(location nchar(64))";
|
||||
execute(sql);
|
||||
SQLExecutor.execute(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase010() {
|
||||
String sql = "create table t1 using restful_test.weather tags('北京')";
|
||||
execute(sql);
|
||||
SQLExecutor.execute(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase011() {
|
||||
String sql = "insert into restful_test.t1 values(now, 22.22)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase012() {
|
||||
String sql = "insert into restful_test.t1 values('2020-01-01 00:00:00.000', 22.22)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase013() {
|
||||
String sql = "insert into restful_test.t1 values('2020-01-01 00:01:00.000', 22.22),('2020-01-01 00:02:00.000', 22.22)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase014() {
|
||||
String sql = "insert into restful_test.t2 using weather tags('上海') values('2020-01-01 00:03:00.000', 22.22)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase015() {
|
||||
String sql = "insert into restful_test.t2 using weather tags('上海') values('2020-01-01 00:01:00.000', 22.22),('2020-01-01 00:02:00.000', 22.22)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase016() {
|
||||
String sql = "insert into t1 values('2020-01-01 01:0:00.000', 22.22),('2020-01-01 02:00:00.000', 22.22) t2 values('2020-01-01 01:0:00.000', 33.33),('2020-01-01 02:00:00.000', 33.33)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase017() {
|
||||
String sql = "Insert into t3 using weather tags('广东') values('2020-01-01 01:0:00.000', 22.22),('2020-01-01 02:00:00.000', 22.22) t4 using weather tags('天津') values('2020-01-01 01:0:00.000', 33.33),('2020-01-01 02:00:00.000', 33.33)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase018() {
|
||||
String sql = "select * from restful_test.t1";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase019() {
|
||||
String sql = "select * from restful_test.weather";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase020() {
|
||||
String sql = "select ts, temperature from restful_test.t1";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase021() {
|
||||
String sql = "select ts, temperature from restful_test.weather";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase022() {
|
||||
String sql = "select temperature, ts from restful_test.t1";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase023() {
|
||||
String sql = "select temperature, ts from restful_test.weather";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase024() {
|
||||
String sql = "import into restful_test.t5 using weather tags('石家庄') values('2020-01-01 00:01:00.000', 22.22)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase025() {
|
||||
String sql = "import into restful_test.t6 using weather tags('沈阳') values('2020-01-01 00:01:00.000', 22.22),('2020-01-01 00:02:00.000', 22.22)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase026() {
|
||||
String sql = "import into restful_test.t7 using weather tags('长沙') values('2020-01-01 00:01:00.000', 22.22) restful_test.t8 using weather tags('吉林') values('2020-01-01 00:01:00.000', 22.22)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase027() {
|
||||
String sql = "import into restful_test.t9 using weather tags('武汉') values('2020-01-01 00:01:00.000', 22.22) ,('2020-01-02 00:01:00.000', 22.22) restful_test.t10 using weather tags('哈尔滨') values('2020-01-01 00:01:00.000', 22.22),('2020-01-02 00:01:00.000', 22.22)";
|
||||
executeUpdate(sql);
|
||||
SQLExecutor.executeUpdate(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase028() {
|
||||
String sql = "select location, temperature, ts from restful_test.weather where temperature > 1";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase029() {
|
||||
String sql = "select location, temperature, ts from restful_test.weather where temperature < 1";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase030() {
|
||||
String sql = "select location, temperature, ts from restful_test.weather where ts > now";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase031() {
|
||||
String sql = "select location, temperature, ts from restful_test.weather where ts < now";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase032() {
|
||||
String sql = "select count(*) from restful_test.weather";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase033() {
|
||||
String sql = "select first(*) from restful_test.weather";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase034() {
|
||||
String sql = "select last(*) from restful_test.weather";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase035() {
|
||||
String sql = "select last_row(*) from restful_test.weather";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase036() {
|
||||
String sql = "select ts, ts as primary_key from restful_test.weather";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCase037() {
|
||||
String sql = "select database()";
|
||||
execute("use restful_test");
|
||||
executeQuery(sql);
|
||||
SQLExecutor.execute(connection, "use restful_test");
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase038() {
|
||||
String sql = "select client_version()";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase039() {
|
||||
String sql = "select server_status()";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase040() {
|
||||
String sql = "select server_status() as status";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase041() {
|
||||
String sql = "select tbname, location from restful_test.weather";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase042() {
|
||||
String sql = "select count(tbname) from restful_test.weather";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase043() {
|
||||
String sql = "select * from restful_test.weather where ts < now - 1h";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase044() {
|
||||
String sql = "select * from restful_test.weather where ts < now - 1h and location like '%'";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase045() {
|
||||
String sql = "select * from restful_test.weather where ts < now - 1h order by ts";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase046() {
|
||||
String sql = "select last(*) from restful_test.weather where ts < now - 1h group by tbname order by tbname";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase047() {
|
||||
String sql = "select * from restful_test.weather limit 2";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase048() {
|
||||
String sql = "select * from restful_test.weather limit 2 offset 5";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase049() {
|
||||
String sql = "select * from restful_test.t1, restful_test.t3 where t1.ts = t3.ts ";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase050() {
|
||||
String sql = "select * from restful_test.t1, restful_test.t3 where t1.ts = t3.ts and t1.location = t3.location";
|
||||
executeQuery(sql);
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase051() {
|
||||
String sql = "select * from restful_test.t1 tt, restful_test.t3 yy where tt.ts = yy.ts";
|
||||
executeQuery(sql);
|
||||
}
|
||||
|
||||
private void executeUpdate(String sql) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
long start = System.currentTimeMillis();
|
||||
int affectedRows = statement.executeUpdate(sql);
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("[ affected rows : " + affectedRows + " ] time cost: " + (end - start) + " ms, execute statement ====> " + sql);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void executeWithResult(String sql) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute(sql);
|
||||
ResultSet resultSet = statement.getResultSet();
|
||||
printResult(resultSet);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void execute(String sql) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
long start = System.currentTimeMillis();
|
||||
boolean execute = statement.execute(sql);
|
||||
long end = System.currentTimeMillis();
|
||||
printSql(sql, execute, (end - start));
|
||||
} catch (SQLException e) {
|
||||
System.out.println("ERROR execute SQL ===> " + sql);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void printSql(String sql, boolean succeed, long cost) {
|
||||
System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql);
|
||||
}
|
||||
|
||||
private void executeQuery(String sql) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
long start = System.currentTimeMillis();
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
long end = System.currentTimeMillis();
|
||||
printSql(sql, true, (end - start));
|
||||
printResult(resultSet);
|
||||
} catch (SQLException e) {
|
||||
System.out.println("ERROR execute SQL ===> " + sql);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void printResult(ResultSet resultSet) throws SQLException {
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
while (resultSet.next()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
||||
String columnLabel = metaData.getColumnLabel(i);
|
||||
String value = resultSet.getString(i);
|
||||
sb.append(columnLabel + ": " + value + "\t");
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
SQLExecutor.executeQuery(connection, sql);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
package com.taosdata.jdbc.utils;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class SQLExecutor {
|
||||
|
||||
// insert, import
|
||||
public static void executeUpdate(Connection connection, String sql) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
long start = System.currentTimeMillis();
|
||||
int affectedRows = statement.executeUpdate(sql);
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("[ affected rows : " + affectedRows + " ] time cost: " + (end - start) + " ms, execute statement ====> " + sql);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// show databases, show tables, show stables
|
||||
public static void executeWithResult(Connection connection, String sql) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute(sql);
|
||||
ResultSet resultSet = statement.getResultSet();
|
||||
printResult(resultSet);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// use database, create database, create table, drop table...
|
||||
public static void execute(Connection connection, String sql) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
long start = System.currentTimeMillis();
|
||||
boolean execute = statement.execute(sql);
|
||||
long end = System.currentTimeMillis();
|
||||
printSql(sql, execute, (end - start));
|
||||
} catch (SQLException e) {
|
||||
System.out.println("ERROR execute SQL ===> " + sql);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// select
|
||||
public static void executeQuery(Connection connection, String sql) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
long start = System.currentTimeMillis();
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
long end = System.currentTimeMillis();
|
||||
printSql(sql, true, (end - start));
|
||||
printResult(resultSet);
|
||||
} catch (SQLException e) {
|
||||
System.out.println("ERROR execute SQL ===> " + sql);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void printSql(String sql, boolean succeed, long cost) {
|
||||
System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql);
|
||||
}
|
||||
|
||||
private static void printResult(ResultSet resultSet) throws SQLException {
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
while (resultSet.next()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
||||
String columnLabel = metaData.getColumnLabel(i);
|
||||
String value = resultSet.getString(i);
|
||||
sb.append(columnLabel + ": " + value + "\t");
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -16,10 +16,6 @@ public class SqlSyntaxValidatorTest {
|
|||
@Test
|
||||
public void isUseSQL() {
|
||||
Assert.assertTrue(SqlSyntaxValidator.isUseSql("use database test"));
|
||||
Assert.assertTrue(SqlSyntaxValidator.isUseSql("create database test"));
|
||||
Assert.assertTrue(SqlSyntaxValidator.isUseSql("create database if not exist test"));
|
||||
Assert.assertTrue(SqlSyntaxValidator.isUseSql("drop database test"));
|
||||
Assert.assertTrue(SqlSyntaxValidator.isUseSql("drop database if exist test"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.taosdata.jdbc.utils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class TimeStampUtil {
|
||||
|
||||
private static final String datetimeFormat = "yyyy-MM-dd HH:mm:ss.SSS";
|
||||
|
||||
public static long datetimeToLong(String dateTime) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat);
|
||||
try {
|
||||
return sdf.parse(dateTime).getTime();
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalArgumentException("invalid datetime string >>> " + dateTime);
|
||||
}
|
||||
}
|
||||
|
||||
public static String longToDatetime(long time) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat);
|
||||
return sdf.format(new Date(time));
|
||||
}
|
||||
|
||||
public static class TimeTuple {
|
||||
public Long start;
|
||||
public Long end;
|
||||
public Long timeGap;
|
||||
|
||||
TimeTuple(long start, long end, long timeGap) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.timeGap = timeGap;
|
||||
}
|
||||
}
|
||||
|
||||
public static TimeTuple range(long start, long timeGap, long size) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (timeGap < 1)
|
||||
timeGap = 1;
|
||||
if (start == 0)
|
||||
start = now - size * timeGap;
|
||||
|
||||
// 如果size小于1异常
|
||||
if (size < 1)
|
||||
throw new IllegalArgumentException("size less than 1.");
|
||||
// 如果timeGap为1,已经超长,需要前移start
|
||||
if (start + size > now) {
|
||||
start = now - size;
|
||||
return new TimeTuple(start, now, 1);
|
||||
}
|
||||
long end = start + (long) (timeGap * size);
|
||||
if (end > now) {
|
||||
//压缩timeGap
|
||||
end = now;
|
||||
double gap = (end - start) / (size * 1.0f);
|
||||
if (gap < 1.0f) {
|
||||
timeGap = 1;
|
||||
start = end - size;
|
||||
} else {
|
||||
timeGap = (long) gap;
|
||||
end = start + (long) (timeGap * size);
|
||||
}
|
||||
}
|
||||
return new TimeTuple(start, end, timeGap);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
|||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRC)
|
||||
|
||||
IF (TD_LINUX)
|
||||
ADD_LIBRARY(tcq ${SRC})
|
||||
IF (TD_SOMODE_STATIC)
|
||||
TARGET_LINK_LIBRARIES(tcq tutil common taos_static)
|
||||
|
@ -14,4 +13,3 @@ IF (TD_LINUX)
|
|||
TARGET_LINK_LIBRARIES(tcq tutil common taos)
|
||||
ENDIF ()
|
||||
ADD_SUBDIRECTORY(test)
|
||||
ENDIF ()
|
||||
|
|
|
@ -343,7 +343,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
|
|||
char buf[TSDB_MAX_NCHAR_LEN];
|
||||
int32_t len = taos_fetch_lengths(tres)[i];
|
||||
taosMbsToUcs4(val, len, buf, sizeof(buf), &len);
|
||||
memcpy(val + sizeof(VarDataLenT), buf, len);
|
||||
memcpy((char *)val + sizeof(VarDataLenT), buf, len);
|
||||
varDataLen(val) = len;
|
||||
}
|
||||
tdAppendColVal(trow, val, c->type, c->bytes, c->offset);
|
||||
|
|
|
@ -3,4 +3,4 @@ PROJECT(TDengine)
|
|||
|
||||
LIST(APPEND CQTEST_SRC ./cqtest.c)
|
||||
ADD_EXECUTABLE(cqtest ${CQTEST_SRC})
|
||||
TARGET_LINK_LIBRARIES(cqtest tcq)
|
||||
TARGET_LINK_LIBRARIES(cqtest tcq taos_static)
|
||||
|
|
|
@ -10,7 +10,6 @@ INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc)
|
|||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
|
||||
IF (TD_LINUX)
|
||||
ADD_EXECUTABLE(taosd ${SRC})
|
||||
TARGET_LINK_LIBRARIES(taosd mnode monitor http tsdb twal vnode cJson lz4 balance sync)
|
||||
|
||||
|
@ -28,7 +27,7 @@ IF (TD_LINUX)
|
|||
TARGET_LINK_LIBRARIES(taosd grant)
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_MQTT)
|
||||
IF ((TD_LINUX OR TD_WINDOWS) AND TD_MQTT)
|
||||
TARGET_LINK_LIBRARIES(taosd mqtt)
|
||||
ENDIF ()
|
||||
|
||||
|
@ -46,4 +45,3 @@ IF (TD_LINUX)
|
|||
COMMAND ${CMAKE_COMMAND} -E echo charset UTF-8 >> ${TD_TESTS_OUTPUT_DIR}/cfg/taos.cfg
|
||||
COMMENT "prepare taosd environment")
|
||||
ADD_CUSTOM_TARGET(${PREPARE_ENV_TARGET} ALL WORKING_DIRECTORY ${TD_EXECUTABLE_OUTPUT_PATH} DEPENDS ${PREPARE_ENV_CMD})
|
||||
ENDIF ()
|
||||
|
|
|
@ -97,7 +97,7 @@ static int32_t dnodeReadCfg() {
|
|||
goto PARSE_CFG_OVER;
|
||||
}
|
||||
|
||||
len = fread(content, 1, maxLen, fp);
|
||||
len = (int32_t)fread(content, 1, maxLen, fp);
|
||||
if (len <= 0) {
|
||||
dError("failed to read %s, content is null", file);
|
||||
goto PARSE_CFG_OVER;
|
||||
|
@ -115,7 +115,7 @@ static int32_t dnodeReadCfg() {
|
|||
dError("failed to read %s, dnodeId not found", file);
|
||||
goto PARSE_CFG_OVER;
|
||||
}
|
||||
cfg.dnodeId = dnodeId->valueint;
|
||||
cfg.dnodeId = (int32_t)dnodeId->valueint;
|
||||
|
||||
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||
if (!clusterId || clusterId->type != cJSON_String) {
|
||||
|
|
|
@ -29,8 +29,8 @@ typedef struct {
|
|||
static SCheckItem tsCheckItem[TSDB_CHECK_ITEM_MAX] = {{0}};
|
||||
int64_t tsMinFreeMemSizeForStart = 0;
|
||||
|
||||
static int bindTcpPort(int port) {
|
||||
int serverSocket;
|
||||
static int32_t bindTcpPort(int16_t port) {
|
||||
SOCKET serverSocket;
|
||||
struct sockaddr_in server_addr;
|
||||
|
||||
if ((serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
|
||||
|
@ -45,22 +45,22 @@ static int bindTcpPort(int port) {
|
|||
|
||||
if (bind(serverSocket, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
|
||||
dError("port:%d tcp bind() fail: %s", port, strerror(errno));
|
||||
close(serverSocket);
|
||||
taosCloseSocket(serverSocket);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (listen(serverSocket, 5) < 0) {
|
||||
dError("port:%d listen() fail: %s", port, strerror(errno));
|
||||
close(serverSocket);
|
||||
taosCloseSocket(serverSocket);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(serverSocket);
|
||||
taosCloseSocket(serverSocket);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bindUdpPort(int port) {
|
||||
int serverSocket;
|
||||
static int32_t bindUdpPort(int16_t port) {
|
||||
SOCKET serverSocket;
|
||||
struct sockaddr_in server_addr;
|
||||
|
||||
if ((serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
|
@ -75,19 +75,19 @@ static int bindUdpPort(int port) {
|
|||
|
||||
if (bind(serverSocket, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
|
||||
dError("port:%d udp bind() fail: %s", port, strerror(errno));
|
||||
close(serverSocket);
|
||||
taosCloseSocket(serverSocket);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(serverSocket);
|
||||
taosCloseSocket(serverSocket);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dnodeCheckNetwork() {
|
||||
int ret;
|
||||
int startPort = tsServerPort;
|
||||
static int32_t dnodeCheckNetwork() {
|
||||
int32_t ret;
|
||||
int16_t startPort = tsServerPort;
|
||||
|
||||
for (int port = startPort; port < startPort + 12; port++) {
|
||||
for (int16_t port = startPort; port < startPort + 12; port++) {
|
||||
ret = bindTcpPort(port);
|
||||
if (0 != ret) {
|
||||
dError("failed to tcp bind port %d, quit", port);
|
||||
|
@ -103,7 +103,7 @@ static int dnodeCheckNetwork() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int dnodeCheckMem() {
|
||||
static int32_t dnodeCheckMem() {
|
||||
float memoryUsedMB;
|
||||
float memoryAvailMB;
|
||||
if (true != taosGetSysMemory(&memoryUsedMB)) {
|
||||
|
@ -121,12 +121,12 @@ static int dnodeCheckMem() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int dnodeCheckCpu() {
|
||||
static int32_t dnodeCheckCpu() {
|
||||
// TODO:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dnodeCheckDisk() {
|
||||
static int32_t dnodeCheckDisk() {
|
||||
taosGetDisk();
|
||||
|
||||
if (tsAvailDataDirGB < tsMinimalDataDirGB) {
|
||||
|
@ -147,24 +147,24 @@ static int dnodeCheckDisk() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int dnodeCheckOs() {
|
||||
static int32_t dnodeCheckOs() {
|
||||
// TODO:
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int dnodeCheckAccess() {
|
||||
static int32_t dnodeCheckAccess() {
|
||||
// TODO:
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dnodeCheckVersion() {
|
||||
static int32_t dnodeCheckVersion() {
|
||||
// TODO:
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dnodeCheckDatafile() {
|
||||
static int32_t dnodeCheckDatafile() {
|
||||
// TODO:
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -152,7 +152,7 @@ static int32_t dnodeReadEps() {
|
|||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
|
||||
len = fread(content, 1, maxLen, fp);
|
||||
len = (int32_t)fread(content, 1, maxLen, fp);
|
||||
if (len <= 0) {
|
||||
dError("failed to read %s, content is null", file);
|
||||
goto PRASE_EPS_OVER;
|
||||
|
@ -199,7 +199,7 @@ static int32_t dnodeReadEps() {
|
|||
dError("failed to read %s, dnodeId not found", file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
ep->dnodeId = dnodeId->valueint;
|
||||
ep->dnodeId = (int32_t)dnodeId->valueint;
|
||||
|
||||
cJSON *dnodeFqdn = cJSON_GetObjectItem(dnodeInfo, "dnodeFqdn");
|
||||
if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) {
|
||||
|
|
|
@ -80,7 +80,7 @@ void dnodeUpdateEpSetForPeer(SRpcEpSet *ep) {
|
|||
|
||||
pthread_mutex_lock(&tsMInfosMutex);
|
||||
dInfo("minfos is changed, numOfEps:%d inUse:%d", ep->numOfEps, ep->inUse);
|
||||
for (int i = 0; i < ep->numOfEps; ++i) {
|
||||
for (int32_t i = 0; i < ep->numOfEps; ++i) {
|
||||
ep->port[i] -= TSDB_PORT_DNODEDNODE;
|
||||
dInfo("minfo:%d %s:%u", i, ep->fqdn[i], ep->port[i]);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ void dnodeGetMInfos(SMInfos *pMinfos) {
|
|||
void dnodeGetEpSetForPeer(SRpcEpSet *epSet) {
|
||||
pthread_mutex_lock(&tsMInfosMutex);
|
||||
*epSet = tsMEpSet;
|
||||
for (int i = 0; i < epSet->numOfEps; ++i) {
|
||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||
epSet->port[i] += TSDB_PORT_DNODEDNODE;
|
||||
}
|
||||
pthread_mutex_unlock(&tsMInfosMutex);
|
||||
|
@ -171,7 +171,7 @@ static int32_t dnodeReadMInfos() {
|
|||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
|
||||
len = fread(content, 1, maxLen, fp);
|
||||
len = (int32_t)fread(content, 1, maxLen, fp);
|
||||
if (len <= 0) {
|
||||
dError("failed to read %s, content is null", file);
|
||||
goto PARSE_MINFOS_OVER;
|
||||
|
@ -189,14 +189,14 @@ static int32_t dnodeReadMInfos() {
|
|||
dError("failed to read mnodeEpSet.json, inUse not found");
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
tsMInfos.inUse = inUse->valueint;
|
||||
tsMInfos.inUse = (int8_t)inUse->valueint;
|
||||
|
||||
cJSON *nodeNum = cJSON_GetObjectItem(root, "nodeNum");
|
||||
if (!nodeNum || nodeNum->type != cJSON_Number) {
|
||||
dError("failed to read mnodeEpSet.json, nodeNum not found");
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
minfos.mnodeNum = nodeNum->valueint;
|
||||
minfos.mnodeNum = (int8_t)nodeNum->valueint;
|
||||
|
||||
cJSON *nodeInfos = cJSON_GetObjectItem(root, "nodeInfos");
|
||||
if (!nodeInfos || nodeInfos->type != cJSON_Array) {
|
||||
|
@ -204,13 +204,13 @@ static int32_t dnodeReadMInfos() {
|
|||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
|
||||
int size = cJSON_GetArraySize(nodeInfos);
|
||||
int32_t size = cJSON_GetArraySize(nodeInfos);
|
||||
if (size != minfos.mnodeNum) {
|
||||
dError("failed to read mnodeEpSet.json, nodeInfos size not matched");
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
cJSON *nodeInfo = cJSON_GetArrayItem(nodeInfos, i);
|
||||
if (nodeInfo == NULL) continue;
|
||||
|
||||
|
@ -227,7 +227,7 @@ static int32_t dnodeReadMInfos() {
|
|||
}
|
||||
|
||||
SMInfo *pMinfo = &minfos.mnodeInfos[i];
|
||||
pMinfo->mnodeId = nodeId->valueint;
|
||||
pMinfo->mnodeId = (int32_t)nodeId->valueint;
|
||||
tstrncpy(pMinfo->mnodeEp, nodeEp->valuestring, TSDB_EP_LEN);
|
||||
|
||||
bool changed = dnodeCheckEpChanged(pMinfo->mnodeId, pMinfo->mnodeEp);
|
||||
|
|
|
@ -60,7 +60,7 @@ int32_t dnodeInitMPeer() {
|
|||
void dnodeCleanupMPeer() {
|
||||
for (int32_t i = 0; i < tsMPeerWP.maxNum; ++i) {
|
||||
SMPeerWorker *pWorker = tsMPeerWP.worker + i;
|
||||
if (pWorker->thread) {
|
||||
if (taosCheckPthreadValid(pWorker->thread)) {
|
||||
taosQsetThreadResume(tsMPeerQset);
|
||||
}
|
||||
dDebug("dnode mpeer worker:%d is closed", i);
|
||||
|
@ -69,7 +69,7 @@ void dnodeCleanupMPeer() {
|
|||
for (int32_t i = 0; i < tsMPeerWP.maxNum; ++i) {
|
||||
SMPeerWorker *pWorker = tsMPeerWP.worker + i;
|
||||
dDebug("dnode mpeer worker:%d start to join", i);
|
||||
if (pWorker->thread) {
|
||||
if (taosCheckPthreadValid(pWorker->thread)) {
|
||||
pthread_join(pWorker->thread, NULL);
|
||||
}
|
||||
dDebug("dnode mpeer worker:%d join success", i);
|
||||
|
|
|
@ -40,7 +40,7 @@ static void *dnodeProcessMReadQueue(void *param);
|
|||
int32_t dnodeInitMRead() {
|
||||
tsMReadQset = taosOpenQset();
|
||||
|
||||
tsMReadWP.maxNum = tsNumOfCores * tsNumOfThreadsPerCore / 2;
|
||||
tsMReadWP.maxNum = (int32_t)(tsNumOfCores * tsNumOfThreadsPerCore / 2);
|
||||
tsMReadWP.maxNum = MAX(2, tsMReadWP.maxNum);
|
||||
tsMReadWP.maxNum = MIN(4, tsMReadWP.maxNum);
|
||||
tsMReadWP.curNum = 0;
|
||||
|
@ -60,7 +60,7 @@ int32_t dnodeInitMRead() {
|
|||
void dnodeCleanupMRead() {
|
||||
for (int32_t i = 0; i < tsMReadWP.maxNum; ++i) {
|
||||
SMReadWorker *pWorker = tsMReadWP.worker + i;
|
||||
if (pWorker->thread) {
|
||||
if (taosCheckPthreadValid(pWorker->thread)) {
|
||||
taosQsetThreadResume(tsMReadQset);
|
||||
}
|
||||
dDebug("dnode mread worker:%d is closed", i);
|
||||
|
@ -69,7 +69,7 @@ void dnodeCleanupMRead() {
|
|||
for (int32_t i = 0; i < tsMReadWP.maxNum; ++i) {
|
||||
SMReadWorker *pWorker = tsMReadWP.worker + i;
|
||||
dDebug("dnode mread worker:%d start to join", i);
|
||||
if (pWorker->thread) {
|
||||
if (taosCheckPthreadValid(pWorker->thread)) {
|
||||
pthread_join(pWorker->thread, NULL);
|
||||
}
|
||||
dDebug("dnode mread worker:%d start to join", i);
|
||||
|
|
|
@ -60,7 +60,7 @@ int32_t dnodeInitMWrite() {
|
|||
void dnodeCleanupMWrite() {
|
||||
for (int32_t i = 0; i < tsMWriteWP.maxNum; ++i) {
|
||||
SMWriteWorker *pWorker = tsMWriteWP.worker + i;
|
||||
if (pWorker->thread) {
|
||||
if (taosCheckPthreadValid(pWorker->thread)) {
|
||||
taosQsetThreadResume(tsMWriteQset);
|
||||
}
|
||||
dDebug("dnode mwrite worker:%d is closed", i);
|
||||
|
@ -69,7 +69,7 @@ void dnodeCleanupMWrite() {
|
|||
for (int32_t i = 0; i < tsMWriteWP.maxNum; ++i) {
|
||||
SMWriteWorker *pWorker = tsMWriteWP.worker + i;
|
||||
dDebug("dnode mwrite worker:%d start to join", i);
|
||||
if (pWorker->thread) {
|
||||
if (taosCheckPthreadValid(pWorker->thread)) {
|
||||
pthread_join(pWorker->thread, NULL);
|
||||
}
|
||||
dDebug("dnode mwrite worker:%d join success", i);
|
||||
|
|
|
@ -90,7 +90,10 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
|||
};
|
||||
|
||||
if (pMsg->pCont == NULL) return;
|
||||
if (pMsg->msgType == TSDB_MSG_TYPE_NETWORK_TEST) return dnodeSendStartupStep(pMsg);
|
||||
if (pMsg->msgType == TSDB_MSG_TYPE_NETWORK_TEST) {
|
||||
dnodeSendStartupStep(pMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dnodeGetRunStatus() != TSDB_RUN_STATUS_RUNING) {
|
||||
rspMsg.code = TSDB_CODE_APP_NOT_READY;
|
||||
|
|
|
@ -70,7 +70,7 @@ int32_t dnodeInitShell() {
|
|||
|
||||
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeSendStartupStep;
|
||||
|
||||
int32_t numOfThreads = (tsNumOfCores * tsNumOfThreadsPerCore) / 2.0;
|
||||
int32_t numOfThreads = (int32_t)((tsNumOfCores * tsNumOfThreadsPerCore) / 2.0);
|
||||
if (numOfThreads < 1) {
|
||||
numOfThreads = 1;
|
||||
}
|
||||
|
|
|
@ -70,5 +70,5 @@ int32_t dnodeStepInit(SStep *pSteps, int32_t stepSize) {
|
|||
}
|
||||
|
||||
void dnodeStepCleanup(SStep *pSteps, int32_t stepSize) {
|
||||
return taosStepCleanupImp(pSteps, stepSize - 1);
|
||||
taosStepCleanupImp(pSteps, stepSize - 1);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue