Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6f6a02f8
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6f6a02f8
编写于
6月 09, 2021
作者:
haoranc
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:taosdata/TDengine into test/chr
上级
4949dd46
2bee6af7
变更
44
展开全部
显示空白变更内容
内联
并排
Showing
44 changed file
with
2893 addition
and
2054 deletion
+2893
-2054
cmake/define.inc
cmake/define.inc
+18
-6
cmake/input.inc
cmake/input.inc
+5
-0
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+1
-0
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+5
-1
src/client/src/tscProfile.c
src/client/src/tscProfile.c
+20
-9
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+30
-6
src/client/src/tscStream.c
src/client/src/tscStream.c
+13
-4
src/common/src/tglobal.c
src/common/src/tglobal.c
+20
-0
src/common/src/tvariant.c
src/common/src/tvariant.c
+1
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
...main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
+476
-448
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java
...ain/java/com/taosdata/jdbc/AbstractParameterMetaData.java
+23
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java
...bc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java
+13
-4
src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
...ain/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
+53
-879
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
.../jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
+9
-5
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
+53
-12
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+83
-23
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
...rc/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
+527
-27
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
+55
-54
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java
...c/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java
+5
-55
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java
...rc/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java
+1
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java
...src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java
+188
-75
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
+39
-36
src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/NullType.java
.../jdbc/src/main/java/com/taosdata/jdbc/utils/NullType.java
+91
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java
...tor/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java
+2
-10
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java
...c/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java
+22
-8
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
...test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
+186
-57
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
...src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
+3
-3
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java
...est/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java
+25
-19
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
...est/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
+607
-195
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java
...bc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java
+8
-9
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java
...bc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java
+0
-3
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java
...om/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java
+1
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java
...ava/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java
+183
-52
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java
...va/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java
+14
-13
src/connector/python/taos/cinterface.py
src/connector/python/taos/cinterface.py
+1
-1
src/cq/src/cqMain.c
src/cq/src/cqMain.c
+3
-17
src/inc/tcq.h
src/inc/tcq.h
+17
-0
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+4
-0
src/os/src/detail/osTime.c
src/os/src/detail/osTime.c
+2
-2
src/util/inc/tutil.h
src/util/inc/tutil.h
+1
-0
src/util/src/tutil.c
src/util/src/tutil.c
+30
-0
tests/mas/Jenkinsfile
tests/mas/Jenkinsfile
+1
-1
tests/pytest/cluster/clusterSetup.py
tests/pytest/cluster/clusterSetup.py
+52
-17
tests/pytest/functions/showOfflineThresholdIs864000.py
tests/pytest/functions/showOfflineThresholdIs864000.py
+2
-2
未找到文件。
cmake/define.inc
浏览文件 @
6f6a02f8
...
...
@@ -118,7 +118,11 @@ IF (TD_LINUX)
MESSAGE
(
STATUS
"set ningsi macro to true"
)
ENDIF
()
IF
(
TD_MEMORY_SANITIZER
)
SET
(
DEBUG_FLAGS
"-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -O0 -g3 -DDEBUG"
)
ELSE
()
SET
(
DEBUG_FLAGS
"-O0 -g3 -DDEBUG"
)
ENDIF
()
SET
(
RELEASE_FLAGS
"-O3 -Wno-error"
)
IF
(
$
{
COVER
}
MATCHES
"true"
)
...
...
@@ -139,7 +143,11 @@ IF (TD_DARWIN_64)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
MESSAGE
(
STATUS
"darwin64 is defined"
)
SET
(
COMMON_FLAGS
"-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
IF
(
TD_MEMORY_SANITIZER
)
SET
(
DEBUG_FLAGS
"-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -O0 -g3 -DDEBUG"
)
ELSE
()
SET
(
DEBUG_FLAGS
"-O0 -g3 -DDEBUG"
)
ENDIF
()
SET
(
RELEASE_FLAGS
"-Og"
)
INCLUDE_DIRECTORIES
(
$
{
TD_COMMUNITY_DIR
}
/
deps
/
cJson
/
inc
)
INCLUDE_DIRECTORIES
(
$
{
TD_COMMUNITY_DIR
}
/
deps
/
lz4
/
inc
)
...
...
@@ -157,7 +165,11 @@ IF (TD_WINDOWS)
IF
(
MSVC
AND
(
MSVC_VERSION
GREATER_EQUAL
1900
))
SET
(
COMMON_FLAGS
"${COMMON_FLAGS} /Wv:18"
)
ENDIF
()
IF
(
TD_MEMORY_SANITIZER
)
SET
(
DEBUG_FLAGS
"/fsanitize=address /Zi /W3 /GL"
)
ELSE
()
SET
(
DEBUG_FLAGS
"/Zi /W3 /GL"
)
ENDIF
()
SET
(
RELEASE_FLAGS
"/W0 /O3 /GL"
)
ENDIF
()
...
...
cmake/input.inc
浏览文件 @
6f6a02f8
...
...
@@ -78,3 +78,8 @@ SET(TD_BUILD_JDBC TRUE)
IF
(
$
{
BUILD_JDBC
}
MATCHES
"false"
)
SET
(
TD_BUILD_JDBC
FALSE
)
ENDIF
()
SET
(
TD_MEMORY_SANITIZER
FALSE
)
IF
(
$
{
MEMORY_SANITIZER
}
MATCHES
"true"
)
SET
(
TD_MEMORY_SANITIZER
TRUE
)
ENDIF
()
src/client/inc/tsclient.h
浏览文件 @
6f6a02f8
...
...
@@ -405,6 +405,7 @@ typedef struct SSqlObj {
typedef
struct
SSqlStream
{
SSqlObj
*
pSql
;
void
*
cqhandle
;
// stream belong to SCQContext handle
const
char
*
dstTable
;
uint32_t
streamId
;
char
listed
;
...
...
src/client/src/tscParseInsert.c
浏览文件 @
6f6a02f8
...
...
@@ -466,6 +466,10 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, SSqlCmd *pCmd, int1
int32_t
cnt
=
0
;
int32_t
j
=
0
;
if
(
sToken
.
n
>=
TSDB_MAX_BYTES_PER_ROW
)
{
return
tscSQLSyntaxErrMsg
(
pCmd
->
payload
,
"too long string"
,
sToken
.
z
);
}
for
(
uint32_t
k
=
1
;
k
<
sToken
.
n
-
1
;
++
k
)
{
if
(
sToken
.
z
[
k
]
==
'\\'
||
(
sToken
.
z
[
k
]
==
delim
&&
sToken
.
z
[
k
+
1
]
==
delim
))
{
tmpTokenBuf
[
j
]
=
sToken
.
z
[
k
+
1
];
...
...
@@ -705,7 +709,7 @@ static int32_t doParseInsertStatement(SSqlCmd* pCmd, char **str, STableDataBlock
}
code
=
TSDB_CODE_TSC_INVALID_SQL
;
char
tmpTokenBuf
[
16
*
1024
]
=
{
0
};
// used for deleting Escape character: \\, \', \"
char
tmpTokenBuf
[
TSDB_MAX_BYTES_PER_ROW
]
=
{
0
};
// used for deleting Escape character: \\, \', \"
int32_t
numOfRows
=
0
;
code
=
tsParseValues
(
str
,
dataBuf
,
maxNumOfRows
,
pCmd
,
&
numOfRows
,
tmpTokenBuf
);
...
...
src/client/src/tscProfile.c
浏览文件 @
6f6a02f8
...
...
@@ -19,6 +19,7 @@
#include "ttimer.h"
#include "tutil.h"
#include "taosmsg.h"
#include "tcq.h"
#include "taos.h"
...
...
@@ -294,24 +295,34 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
return
msgLen
;
}
void
tscKillConnection
(
STscObj
*
pObj
)
{
pthread_mutex_lock
(
&
pObj
->
mutex
);
SSqlObj
*
pSql
=
pObj
->
sqlList
;
while
(
pSql
)
{
pSql
=
pSql
->
next
;
// cqContext->dbconn is killed then call this callback
void
cqConnKilledNotify
(
void
*
handle
,
void
*
conn
)
{
if
(
handle
==
NULL
||
conn
==
NULL
){
return
;
}
SCqContext
*
pContext
=
(
SCqContext
*
)
handle
;
if
(
pContext
->
dbConn
==
conn
){
atomic_store_ptr
(
&
(
pContext
->
dbConn
),
NULL
);
}
}
void
tscKillConnection
(
STscObj
*
pObj
)
{
// get stream header by locked
pthread_mutex_lock
(
&
pObj
->
mutex
);
SSqlStream
*
pStream
=
pObj
->
streamList
;
pthread_mutex_unlock
(
&
pObj
->
mutex
);
while
(
pStream
)
{
SSqlStream
*
tmp
=
pStream
->
next
;
// set associate variant to NULL
cqConnKilledNotify
(
pStream
->
cqhandle
,
pObj
);
// taos_close_stream function call pObj->mutet lock , careful death-lock
taos_close_stream
(
pStream
);
pStream
=
tmp
;
}
pthread_mutex_unlock
(
&
pObj
->
mutex
);
tscDebug
(
"connection:%p is killed"
,
pObj
);
taos_close
(
pObj
);
}
src/client/src/tscSQLParser.c
浏览文件 @
6f6a02f8
...
...
@@ -314,7 +314,9 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
}
else
if
(
pInfo
->
type
==
TSDB_SQL_DROP_DNODE
)
{
if
(
pzName
->
type
==
TK_STRING
)
{
pzName
->
n
=
strdequote
(
pzName
->
z
);
}
strncpy
(
pCmd
->
payload
,
pzName
->
z
,
pzName
->
n
);
}
else
{
// drop user/account
if
(
pzName
->
n
>=
TSDB_USER_LEN
)
{
...
...
@@ -392,7 +394,9 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
SStrToken
*
id
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
id
->
type
==
TK_STRING
)
{
id
->
n
=
strdequote
(
id
->
z
);
}
break
;
}
...
...
@@ -1987,6 +1991,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const
char
*
msg7
=
"normal table can not apply this function"
;
const
char
*
msg8
=
"multi-columns selection does not support alias column name"
;
const
char
*
msg9
=
"diff can no be applied to unsigned numeric type"
;
const
char
*
msg10
=
"parameter is out of range [1, 100]"
;
switch
(
functionId
)
{
case
TSDB_FUNC_COUNT
:
{
...
...
@@ -2374,7 +2379,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
int64_t
nTop
=
GET_INT32_VAL
(
val
);
if
(
nTop
<=
0
||
nTop
>
100
)
{
// todo use macro
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
5
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
10
);
}
// todo REFACTOR
...
...
@@ -6674,6 +6679,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
const
char
*
msg5
=
"sql too long"
;
// todo ADD support
const
char
*
msg6
=
"from missing in subclause"
;
const
char
*
msg7
=
"time interval is required"
;
const
char
*
msg8
=
"the first column should be primary timestamp column"
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
...
...
@@ -6731,9 +6737,27 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
if
(
!
tscIsProjectionQuery
(
pQueryInfo
)
&&
pQueryInfo
->
interval
.
interval
==
0
)
{
// project query primary column must be timestamp type
if
(
tscIsProjectionQuery
(
pQueryInfo
))
{
size_t
size
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
// check zero
if
(
size
==
0
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg8
);
}
// check primary column is timestamp
SSqlExpr
*
pSqlExpr
=
tscSqlExprGet
(
pQueryInfo
,
0
);
if
(
pSqlExpr
==
NULL
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg8
);
}
if
(
pSqlExpr
->
colInfo
.
colId
!=
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg8
);
}
}
else
{
if
(
pQueryInfo
->
interval
.
interval
==
0
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
}
// set the created table[stream] name
code
=
tscSetTableFullName
(
pTableMetaInfo
,
pName
,
pSql
);
...
...
src/client/src/tscStream.c
浏览文件 @
6f6a02f8
...
...
@@ -141,6 +141,10 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
pStream
->
numOfRes
=
0
;
// reset the numOfRes.
SSqlObj
*
pSql
=
pStream
->
pSql
;
// pSql == NULL maybe killStream already called
if
(
pSql
==
NULL
)
{
return
;
}
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
tscDebug
(
"0x%"
PRIx64
" add into timer"
,
pSql
->
self
);
...
...
@@ -336,8 +340,12 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer)
if
(
pStream
->
isProject
)
{
int64_t
now
=
taosGetTimestamp
(
pStream
->
precision
);
int64_t
etime
=
now
>
pStream
->
etime
?
pStream
->
etime
:
now
;
int64_t
maxRetent
=
tsMaxRetentWindow
*
1000
;
if
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
maxRetent
*=
1000
;
}
if
(
pStream
->
etime
<
now
&&
now
-
pStream
->
etime
>
tsMaxRetentWindow
)
{
if
(
pStream
->
etime
<
now
&&
now
-
pStream
->
etime
>
maxRetent
)
{
/*
* current time window will be closed, since it too early to exceed the maxRetentWindow value
*/
...
...
@@ -662,7 +670,7 @@ void cbParseSql(void* param, TAOS_RES* res, int code) {
}
TAOS_STREAM
*
taos_open_stream_withname
(
TAOS
*
taos
,
const
char
*
dstTable
,
const
char
*
sqlstr
,
void
(
*
fp
)(
void
*
param
,
TAOS_RES
*
,
TAOS_ROW
row
),
int64_t
stime
,
void
*
param
,
void
(
*
callback
)(
void
*
))
{
int64_t
stime
,
void
*
param
,
void
(
*
callback
)(
void
*
)
,
void
*
cqhandle
)
{
STscObj
*
pObj
=
(
STscObj
*
)
taos
;
if
(
pObj
==
NULL
||
pObj
->
signature
!=
pObj
)
return
NULL
;
...
...
@@ -695,6 +703,7 @@ TAOS_STREAM *taos_open_stream_withname(TAOS *taos, const char* dstTable, const c
pStream
->
callback
=
callback
;
pStream
->
param
=
param
;
pStream
->
pSql
=
pSql
;
pStream
->
cqhandle
=
cqhandle
;
pSql
->
pStream
=
pStream
;
pSql
->
param
=
pStream
;
pSql
->
maxRetry
=
TSDB_MAX_REPLICA
;
...
...
@@ -735,7 +744,7 @@ TAOS_STREAM *taos_open_stream_withname(TAOS *taos, const char* dstTable, const c
TAOS_STREAM
*
taos_open_stream
(
TAOS
*
taos
,
const
char
*
sqlstr
,
void
(
*
fp
)(
void
*
param
,
TAOS_RES
*
,
TAOS_ROW
row
),
int64_t
stime
,
void
*
param
,
void
(
*
callback
)(
void
*
))
{
return
taos_open_stream_withname
(
taos
,
""
,
sqlstr
,
fp
,
stime
,
param
,
callback
);
return
taos_open_stream_withname
(
taos
,
""
,
sqlstr
,
fp
,
stime
,
param
,
callback
,
NULL
);
}
void
taos_close_stream
(
TAOS_STREAM
*
handle
)
{
...
...
src/common/src/tglobal.c
浏览文件 @
6f6a02f8
...
...
@@ -817,6 +817,16 @@ static void doInitGlobalConfig(void) {
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
taosInitConfigOption
(
cfg
);
cfg
.
option
=
"precision"
;
cfg
.
ptr
=
&
tsTimePrecision
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT8
;
cfg
.
cfgType
=
TSDB_CFG_CTYPE_B_CONFIG
|
TSDB_CFG_CTYPE_B_SHOW
;
cfg
.
minValue
=
TSDB_MIN_PRECISION
;
cfg
.
maxValue
=
TSDB_MAX_PRECISION
;
cfg
.
ptrLength
=
0
;
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
taosInitConfigOption
(
cfg
);
cfg
.
option
=
"comp"
;
cfg
.
ptr
=
&
tsCompression
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT8
;
...
...
@@ -887,6 +897,16 @@ static void doInitGlobalConfig(void) {
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
taosInitConfigOption
(
cfg
);
cfg
.
option
=
"cachelast"
;
cfg
.
ptr
=
&
tsCacheLastRow
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT8
;
cfg
.
cfgType
=
TSDB_CFG_CTYPE_B_CONFIG
|
TSDB_CFG_CTYPE_B_SHOW
;
cfg
.
minValue
=
TSDB_MIN_DB_CACHE_LAST_ROW
;
cfg
.
maxValue
=
TSDB_MAX_DB_CACHE_LAST_ROW
;
cfg
.
ptrLength
=
0
;
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
taosInitConfigOption
(
cfg
);
cfg
.
option
=
"mqttHostName"
;
cfg
.
ptr
=
tsMqttHostName
;
cfg
.
valType
=
TAOS_CFG_VTYPE_STRING
;
...
...
src/common/src/tvariant.c
浏览文件 @
6f6a02f8
...
...
@@ -74,7 +74,7 @@ void tVariantCreate(tVariant *pVar, SStrToken *token) {
case
TSDB_DATA_TYPE_BINARY
:
{
pVar
->
pz
=
strndup
(
token
->
z
,
token
->
n
);
pVar
->
nLen
=
str
dequote
(
pVar
->
pz
);
pVar
->
nLen
=
str
Rmquote
(
pVar
->
pz
,
token
->
n
);
break
;
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java
浏览文件 @
6f6a02f8
package
com.taosdata.jdbc
;
import
com.sun.org.apache.xpath.internal.operations.Bool
;
import
java.sql.ParameterMetaData
;
import
java.sql.SQLException
;
import
java.sql.Timestamp
;
...
...
@@ -49,6 +51,22 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P
if
(
param
<
1
&&
param
>=
parameters
.
length
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_PARAMETER_INDEX_OUT_RANGE
);
if
(
parameters
[
param
-
1
]
instanceof
Boolean
)
return
TSDBConstants
.
BOOLEAN_PRECISION
;
if
(
parameters
[
param
-
1
]
instanceof
Byte
)
return
TSDBConstants
.
TINYINT_PRECISION
;
if
(
parameters
[
param
-
1
]
instanceof
Short
)
return
TSDBConstants
.
SMALLINT_PRECISION
;
if
(
parameters
[
param
-
1
]
instanceof
Integer
)
return
TSDBConstants
.
INT_PRECISION
;
if
(
parameters
[
param
-
1
]
instanceof
Long
)
return
TSDBConstants
.
BIGINT_PRECISION
;
if
(
parameters
[
param
-
1
]
instanceof
Timestamp
)
return
TSDBConstants
.
TIMESTAMP_MS_PRECISION
;
if
(
parameters
[
param
-
1
]
instanceof
Float
)
return
TSDBConstants
.
FLOAT_PRECISION
;
if
(
parameters
[
param
-
1
]
instanceof
Double
)
return
TSDBConstants
.
DOUBLE_PRECISION
;
if
(
parameters
[
param
-
1
]
instanceof
String
)
return
((
String
)
parameters
[
param
-
1
]).
length
();
if
(
parameters
[
param
-
1
]
instanceof
byte
[])
...
...
@@ -60,6 +78,11 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P
public
int
getScale
(
int
param
)
throws
SQLException
{
if
(
param
<
1
&&
param
>=
parameters
.
length
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_PARAMETER_INDEX_OUT_RANGE
);
if
(
parameters
[
param
-
1
]
instanceof
Float
)
return
TSDBConstants
.
FLOAT_SCALE
;
if
(
parameters
[
param
-
1
]
instanceof
Double
)
return
TSDBConstants
.
DOUBLE_SCALE
;
return
0
;
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java
浏览文件 @
6f6a02f8
...
...
@@ -66,10 +66,16 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet
public
abstract
byte
[]
getBytes
(
int
columnIndex
)
throws
SQLException
;
@Override
public
abstract
Date
getDate
(
int
columnIndex
)
throws
SQLException
;
public
Date
getDate
(
int
columnIndex
)
throws
SQLException
{
Timestamp
timestamp
=
getTimestamp
(
columnIndex
);
return
timestamp
==
null
?
null
:
new
Date
(
timestamp
.
getTime
());
}
@Override
public
abstract
Time
getTime
(
int
columnIndex
)
throws
SQLException
;
public
Time
getTime
(
int
columnIndex
)
throws
SQLException
{
Timestamp
timestamp
=
getTimestamp
(
columnIndex
);
return
timestamp
==
null
?
null
:
new
Time
(
timestamp
.
getTime
());
}
@Override
public
abstract
Timestamp
getTimestamp
(
int
columnIndex
)
throws
SQLException
;
...
...
@@ -84,9 +90,11 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet
}
@Override
@Deprecated
public
InputStream
getUnicodeStream
(
int
columnIndex
)
throws
SQLException
{
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_RESULTSET_CLOSED
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
...
...
@@ -171,6 +179,7 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet
}
@Override
@Deprecated
public
InputStream
getUnicodeStream
(
String
columnLabel
)
throws
SQLException
{
return
getUnicodeStream
(
findColumn
(
columnLabel
));
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
浏览文件 @
6f6a02f8
...
...
@@ -49,7 +49,7 @@ public class TSDBConnection extends AbstractConnection {
this
.
databaseMetaData
.
setConnection
(
this
);
}
public
TSDBJNIConnector
getConnect
ion
()
{
public
TSDBJNIConnector
getConnect
or
()
{
return
this
.
connector
;
}
...
...
@@ -58,7 +58,7 @@ public class TSDBConnection extends AbstractConnection {
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
new
TSDBStatement
(
this
,
this
.
connector
);
return
new
TSDBStatement
(
this
);
}
public
TSDBSubscribe
subscribe
(
String
topic
,
String
sql
,
boolean
restart
)
throws
SQLException
{
...
...
@@ -74,14 +74,18 @@ public class TSDBConnection extends AbstractConnection {
}
public
PreparedStatement
prepareStatement
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
new
TSDBPreparedStatement
(
this
,
this
.
connector
,
sql
);
}
return
new
TSDBPreparedStatement
(
this
,
sql
);
}
public
void
close
()
throws
SQLException
{
if
(
isClosed
)
if
(
isClosed
)
{
return
;
}
this
.
connector
.
closeConnection
();
this
.
isClosed
=
true
;
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java
浏览文件 @
6f6a02f8
...
...
@@ -41,14 +41,14 @@ public abstract class TSDBConstants {
public
static
final
int
TSDB_DATA_TYPE_BINARY
=
8
;
public
static
final
int
TSDB_DATA_TYPE_TIMESTAMP
=
9
;
public
static
final
int
TSDB_DATA_TYPE_NCHAR
=
10
;
/*
系统增加新的无符号数据类型,分别是:
unsigned tinyint, 数值范围:0-254, NULL 为255
unsigned smallint,数值范围: 0-65534, NULL 为65535
unsigned int,数值范围:0-4294967294,NULL 为4294967295u
unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u。
example:
create table tb(ts timestamp, a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned);
/*
*
*
系统增加新的无符号数据类型,分别是:
*
unsigned tinyint, 数值范围:0-254, NULL 为255
*
unsigned smallint,数值范围: 0-65534, NULL 为65535
*
unsigned int,数值范围:0-4294967294,NULL 为4294967295u
*
unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u。
*
example:
*
create table tb(ts timestamp, a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned);
*/
public
static
final
int
TSDB_DATA_TYPE_UTINYINT
=
11
;
//unsigned tinyint
public
static
final
int
TSDB_DATA_TYPE_USMALLINT
=
12
;
//unsigned smallint
...
...
@@ -57,6 +57,47 @@ public abstract class TSDBConstants {
// nchar column max length
public
static
final
int
maxFieldSize
=
16
*
1024
;
// precision for data types
public
static
final
int
BOOLEAN_PRECISION
=
1
;
public
static
final
int
TINYINT_PRECISION
=
4
;
public
static
final
int
SMALLINT_PRECISION
=
6
;
public
static
final
int
INT_PRECISION
=
11
;
public
static
final
int
BIGINT_PRECISION
=
20
;
public
static
final
int
FLOAT_PRECISION
=
12
;
public
static
final
int
DOUBLE_PRECISION
=
22
;
public
static
final
int
TIMESTAMP_MS_PRECISION
=
23
;
public
static
final
int
TIMESTAMP_US_PRECISION
=
26
;
// scale for data types
public
static
final
int
FLOAT_SCALE
=
31
;
public
static
final
int
DOUBLE_SCALE
=
31
;
public
static
int
typeName2JdbcType
(
String
type
)
{
switch
(
type
.
toUpperCase
())
{
case
"TIMESTAMP"
:
return
Types
.
TIMESTAMP
;
case
"INT"
:
return
Types
.
INTEGER
;
case
"BIGINT"
:
return
Types
.
BIGINT
;
case
"FLOAT"
:
return
Types
.
FLOAT
;
case
"DOUBLE"
:
return
Types
.
DOUBLE
;
case
"BINARY"
:
return
Types
.
BINARY
;
case
"SMALLINT"
:
return
Types
.
SMALLINT
;
case
"TINYINT"
:
return
Types
.
TINYINT
;
case
"BOOL"
:
return
Types
.
BOOLEAN
;
case
"NCHAR"
:
return
Types
.
NCHAR
;
default
:
return
Types
.
NULL
;
}
}
public
static
int
taosType2JdbcType
(
int
taosType
)
throws
SQLException
{
switch
(
taosType
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_BOOL
:
...
...
@@ -88,7 +129,7 @@ public abstract class TSDBConstants {
}
public
static
String
taosType2JdbcTypeName
(
int
taosType
)
throws
SQLException
{
switch
(
taosType
){
switch
(
taosType
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_BOOL
:
return
"BOOL"
;
case
TSDBConstants
.
TSDB_DATA_TYPE_UTINYINT
:
...
...
@@ -119,7 +160,7 @@ public abstract class TSDBConstants {
}
public
static
int
jdbcType2TaosType
(
int
jdbcType
)
throws
SQLException
{
switch
(
jdbcType
){
switch
(
jdbcType
)
{
case
Types
.
BOOLEAN
:
return
TSDBConstants
.
TSDB_DATA_TYPE_BOOL
;
case
Types
.
TINYINT
:
...
...
@@ -145,7 +186,7 @@ public abstract class TSDBConstants {
}
public
static
String
jdbcType2TaosTypeName
(
int
jdbcType
)
throws
SQLException
{
switch
(
jdbcType
){
switch
(
jdbcType
)
{
case
Types
.
BOOLEAN
:
return
"BOOL"
;
case
Types
.
TINYINT
:
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
浏览文件 @
6f6a02f8
...
...
@@ -18,6 +18,7 @@ package com.taosdata.jdbc;
import
com.taosdata.jdbc.utils.TaosInfo
;
import
java.nio.ByteBuffer
;
import
java.sql.SQLException
;
import
java.sql.SQLWarning
;
import
java.util.List
;
...
...
@@ -29,10 +30,13 @@ public class TSDBJNIConnector {
private
static
volatile
Boolean
isInitialized
=
false
;
private
TaosInfo
taosInfo
=
TaosInfo
.
getInstance
();
// Connection pointer used in C
private
long
taos
=
TSDBConstants
.
JNI_NULL_POINTER
;
// result set status in current connection
private
boolean
isResultsetClosed
;
private
int
affectedRows
=
-
1
;
static
{
...
...
@@ -75,7 +79,6 @@ public class TSDBJNIConnector {
public
boolean
connect
(
String
host
,
int
port
,
String
dbName
,
String
user
,
String
password
)
throws
SQLException
{
if
(
this
.
taos
!=
TSDBConstants
.
JNI_NULL_POINTER
)
{
// this.closeConnectionImp(this.taos);
closeConnection
();
this
.
taos
=
TSDBConstants
.
JNI_NULL_POINTER
;
}
...
...
@@ -97,12 +100,6 @@ public class TSDBJNIConnector {
* @throws SQLException
*/
public
long
executeQuery
(
String
sql
)
throws
SQLException
{
// close previous result set if the user forgets to invoke the
// free method to close previous result set.
// if (!this.isResultsetClosed) {
// freeResultSet(taosResultSetPointer);
// }
Long
pSql
=
0
l
;
try
{
pSql
=
this
.
executeQueryImp
(
sql
.
getBytes
(
TaosGlobalConfig
.
getCharset
()),
this
.
taos
);
...
...
@@ -170,7 +167,7 @@ public class TSDBJNIConnector {
private
native
long
isUpdateQueryImp
(
long
connection
,
long
pSql
);
/**
* Free result
set operation from C to release result
set pointer by JNI
* Free result
set operation from C to release result
set pointer by JNI
*/
public
int
freeResultSet
(
long
pSql
)
{
int
res
=
this
.
freeResultSetImp
(
this
.
taos
,
pSql
);
...
...
@@ -178,19 +175,6 @@ public class TSDBJNIConnector {
return
res
;
}
/**
* Close the open result set which is associated to the current connection. If the result set is already
* closed, return 0 for success.
*/
// public int freeResultSet() {
// int resCode = TSDBConstants.JNI_SUCCESS;
// if (!isResultsetClosed) {
// resCode = this.freeResultSetImp(this.taos, this.taosResultSetPointer);
// taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER;
// isResultsetClosed = true;
// }
// return resCode;
// }
private
native
int
freeResultSetImp
(
long
connection
,
long
result
);
/**
...
...
@@ -210,7 +194,9 @@ public class TSDBJNIConnector {
* Get schema metadata
*/
public
int
getSchemaMetaData
(
long
resultSet
,
List
<
ColumnMetaData
>
columnMetaData
)
{
return
this
.
getSchemaMetaDataImp
(
this
.
taos
,
resultSet
,
columnMetaData
);
int
ret
=
this
.
getSchemaMetaDataImp
(
this
.
taos
,
resultSet
,
columnMetaData
);
columnMetaData
.
stream
().
forEach
(
column
->
column
.
setColIndex
(
column
.
getColIndex
()
+
1
));
return
ret
;
}
private
native
int
getSchemaMetaDataImp
(
long
connection
,
long
resultSet
,
List
<
ColumnMetaData
>
columnMetaData
);
...
...
@@ -237,6 +223,7 @@ public class TSDBJNIConnector {
*/
public
void
closeConnection
()
throws
SQLException
{
int
code
=
this
.
closeConnectionImp
(
this
.
taos
);
if
(
code
<
0
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
else
if
(
code
==
0
)
{
...
...
@@ -244,6 +231,7 @@ public class TSDBJNIConnector {
}
else
{
throw
new
SQLException
(
"Undefined error code returned by TDengine when closing a connection"
);
}
// invoke closeConnectionImpl only here
taosInfo
.
connect_close_increment
();
}
...
...
@@ -280,7 +268,7 @@ public class TSDBJNIConnector {
private
native
void
unsubscribeImp
(
long
subscription
,
boolean
isKeep
);
/**
* Validate if a <I>create table</I>
sql
statement is correct without actually creating that table
* Validate if a <I>create table</I>
SQL
statement is correct without actually creating that table
*/
public
boolean
validateCreateTableSql
(
String
sql
)
{
int
res
=
validateCreateTableSqlImp
(
taos
,
sql
.
getBytes
());
...
...
@@ -288,4 +276,76 @@ public class TSDBJNIConnector {
}
private
native
int
validateCreateTableSqlImp
(
long
connection
,
byte
[]
sqlBytes
);
public
long
prepareStmt
(
String
sql
)
throws
SQLException
{
Long
stmt
;
try
{
stmt
=
prepareStmtImp
(
sql
.
getBytes
(),
this
.
taos
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_ENCODING
);
}
if
(
stmt
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
if
(
stmt
==
TSDBConstants
.
JNI_SQL_NULL
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_SQL_NULL
);
}
if
(
stmt
==
TSDBConstants
.
JNI_OUT_OF_MEMORY
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_OUT_OF_MEMORY
);
}
return
stmt
;
}
private
native
long
prepareStmtImp
(
byte
[]
sql
,
long
con
);
public
void
setBindTableName
(
long
stmt
,
String
tableName
)
throws
SQLException
{
int
code
=
setBindTableNameImp
(
stmt
,
tableName
,
this
.
taos
);
if
(
code
!=
TSDBConstants
.
JNI_SUCCESS
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"failed to set table name"
);
}
}
private
native
int
setBindTableNameImp
(
long
stmt
,
String
name
,
long
conn
);
public
void
setBindTableNameAndTags
(
long
stmt
,
String
tableName
,
int
numOfTags
,
ByteBuffer
tags
,
ByteBuffer
typeList
,
ByteBuffer
lengthList
,
ByteBuffer
nullList
)
throws
SQLException
{
int
code
=
setTableNameTagsImp
(
stmt
,
tableName
,
numOfTags
,
tags
.
array
(),
typeList
.
array
(),
lengthList
.
array
(),
nullList
.
array
(),
this
.
taos
);
if
(
code
!=
TSDBConstants
.
JNI_SUCCESS
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"failed to bind table name and corresponding tags"
);
}
}
private
native
int
setTableNameTagsImp
(
long
stmt
,
String
name
,
int
numOfTags
,
byte
[]
tags
,
byte
[]
typeList
,
byte
[]
lengthList
,
byte
[]
nullList
,
long
conn
);
public
void
bindColumnDataArray
(
long
stmt
,
ByteBuffer
colDataList
,
ByteBuffer
lengthList
,
ByteBuffer
isNullList
,
int
type
,
int
bytes
,
int
numOfRows
,
int
columnIndex
)
throws
SQLException
{
int
code
=
bindColDataImp
(
stmt
,
colDataList
.
array
(),
lengthList
.
array
(),
isNullList
.
array
(),
type
,
bytes
,
numOfRows
,
columnIndex
,
this
.
taos
);
if
(
code
!=
TSDBConstants
.
JNI_SUCCESS
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"failed to bind column data"
);
}
}
private
native
int
bindColDataImp
(
long
stmt
,
byte
[]
colDataList
,
byte
[]
lengthList
,
byte
[]
isNullList
,
int
type
,
int
bytes
,
int
numOfRows
,
int
columnIndex
,
long
conn
);
public
void
executeBatch
(
long
stmt
)
throws
SQLException
{
int
code
=
executeBatchImp
(
stmt
,
this
.
taos
);
if
(
code
!=
TSDBConstants
.
JNI_SUCCESS
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"failed to execute batch bind"
);
}
}
private
native
int
executeBatchImp
(
long
stmt
,
long
con
);
public
void
closeBatch
(
long
stmt
)
throws
SQLException
{
int
code
=
closeStmt
(
stmt
,
this
.
taos
);
if
(
code
!=
TSDBConstants
.
JNI_SUCCESS
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"failed to close batch bind"
);
}
}
private
native
int
closeStmt
(
long
stmt
,
long
con
);
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
浏览文件 @
6f6a02f8
...
...
@@ -133,9 +133,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
this
.
blockData
.
getString
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
if
(!
lastWasNull
)
{
res
=
this
.
rowData
.
getString
(
columnIndex
-
1
,
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
());
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
res
=
this
.
rowData
.
getString
(
columnIndex
,
nativeType
);
}
return
res
;
}
...
...
@@ -147,9 +148,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
this
.
blockData
.
getBoolean
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
if
(!
lastWasNull
)
{
res
=
this
.
rowData
.
getBoolean
(
columnIndex
-
1
,
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
());
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
res
=
this
.
rowData
.
getBoolean
(
columnIndex
,
nativeType
);
}
return
res
;
}
...
...
@@ -161,9 +163,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
(
byte
)
this
.
blockData
.
getInt
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
if
(!
lastWasNull
)
{
res
=
(
byte
)
this
.
rowData
.
getInt
(
columnIndex
-
1
,
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
());
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
res
=
(
byte
)
this
.
rowData
.
getInt
(
columnIndex
,
nativeType
);
}
return
res
;
}
...
...
@@ -175,9 +178,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
(
short
)
this
.
blockData
.
getInt
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
if
(!
lastWasNull
)
{
res
=
(
short
)
this
.
rowData
.
getInt
(
columnIndex
-
1
,
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
());
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
res
=
(
short
)
this
.
rowData
.
getInt
(
columnIndex
,
nativeType
);
}
return
res
;
}
...
...
@@ -189,9 +193,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
this
.
blockData
.
getInt
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
if
(!
lastWasNull
)
{
res
=
this
.
rowData
.
getInt
(
columnIndex
-
1
,
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
());
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
res
=
this
.
rowData
.
getInt
(
columnIndex
,
nativeType
);
}
return
res
;
}
...
...
@@ -203,13 +209,15 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
this
.
blockData
.
getLong
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
if
(!
lastWasNull
)
{
Object
value
=
this
.
rowData
.
get
(
columnIndex
-
1
);
if
(
value
instanceof
Timestamp
)
Object
value
=
this
.
rowData
.
get
Object
(
columnIndex
);
if
(
value
instanceof
Timestamp
)
{
res
=
((
Timestamp
)
value
).
getTime
();
else
res
=
this
.
rowData
.
getLong
(
columnIndex
-
1
,
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
());
}
else
{
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
res
=
this
.
rowData
.
getLong
(
columnIndex
,
nativeType
);
}
}
return
res
;
}
...
...
@@ -221,9 +229,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
(
float
)
this
.
blockData
.
getDouble
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
if
(!
lastWasNull
)
res
=
this
.
rowData
.
getFloat
(
columnIndex
-
1
,
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
());
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
if
(!
lastWasNull
)
{
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
res
=
this
.
rowData
.
getFloat
(
columnIndex
,
nativeType
);
}
return
res
;
}
...
...
@@ -235,9 +245,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
this
.
blockData
.
getDouble
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
if
(!
lastWasNull
)
{
res
=
this
.
rowData
.
getDouble
(
columnIndex
-
1
,
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
());
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
res
=
this
.
rowData
.
getDouble
(
columnIndex
,
nativeType
);
}
return
res
;
}
...
...
@@ -245,34 +256,27 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
public
byte
[]
getBytes
(
int
columnIndex
)
throws
SQLException
{
checkAvailability
(
columnIndex
,
this
.
columnMetaDataList
.
size
());
Object
value
=
this
.
rowData
.
get
(
columnIndex
-
1
);
Object
value
=
this
.
rowData
.
get
Object
(
columnIndex
);
if
(
value
==
null
)
return
null
;
int
col
Type
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
switch
(
col
Type
)
{
int
native
Type
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
switch
(
native
Type
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
:
return
Longs
.
toByteArray
((
L
ong
)
value
);
return
Longs
.
toByteArray
((
l
ong
)
value
);
case
TSDBConstants
.
TSDB_DATA_TYPE_INT
:
return
Ints
.
toByteArray
((
int
)
value
);
case
TSDBConstants
.
TSDB_DATA_TYPE_SMALLINT
:
return
Shorts
.
toByteArray
((
S
hort
)
value
);
return
Shorts
.
toByteArray
((
s
hort
)
value
);
case
TSDBConstants
.
TSDB_DATA_TYPE_TINYINT
:
return
new
byte
[]{(
byte
)
value
};
}
case
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
:
return
(
byte
[])
value
;
case
TSDBConstants
.
TSDB_DATA_TYPE_BOOL
:
case
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
:
default
:
return
value
.
toString
().
getBytes
();
}
@Override
public
Date
getDate
(
int
columnIndex
)
throws
SQLException
{
Timestamp
timestamp
=
getTimestamp
(
columnIndex
);
return
timestamp
==
null
?
null
:
new
Date
(
timestamp
.
getTime
());
}
@Override
public
Time
getTime
(
int
columnIndex
)
throws
SQLException
{
Timestamp
timestamp
=
getTimestamp
(
columnIndex
);
return
timestamp
==
null
?
null
:
new
Time
(
timestamp
.
getTime
());
}
public
Timestamp
getTimestamp
(
int
columnIndex
)
throws
SQLException
{
...
...
@@ -282,9 +286,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
this
.
blockData
.
getTimestamp
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
if
(!
lastWasNull
)
{
res
=
this
.
rowData
.
getTimestamp
(
columnIndex
-
1
);
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
res
=
this
.
rowData
.
getTimestamp
(
columnIndex
,
nativeType
);
}
return
res
;
}
...
...
@@ -304,13 +309,9 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
this
.
blockData
.
get
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
if
(!
lastWasNull
)
{
int
colType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
if
(
colType
==
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
)
res
=
((
String
)
this
.
rowData
.
get
(
columnIndex
-
1
)).
getBytes
();
else
res
=
this
.
rowData
.
get
(
columnIndex
-
1
);
res
=
this
.
rowData
.
getObject
(
columnIndex
);
}
return
res
;
}
...
...
@@ -318,7 +319,7 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
public
int
findColumn
(
String
columnLabel
)
throws
SQLException
{
for
(
ColumnMetaData
colMetaData
:
this
.
columnMetaDataList
)
{
if
(
colMetaData
.
getColName
()
!=
null
&&
colMetaData
.
getColName
().
equalsIgnoreCase
(
columnLabel
))
{
return
colMetaData
.
getColIndex
()
+
1
;
return
colMetaData
.
getColIndex
();
}
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
...
...
@@ -329,25 +330,25 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
if
(
this
.
getBatchFetch
())
return
new
BigDecimal
(
this
.
blockData
.
getLong
(
columnIndex
-
1
));
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
-
1
);
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
BigDecimal
res
=
null
;
if
(!
lastWasNull
)
{
int
col
Type
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
switch
(
col
Type
)
{
int
native
Type
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
switch
(
native
Type
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_TINYINT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_SMALLINT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_INT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
:
res
=
new
BigDecimal
(
Long
.
valueOf
(
this
.
rowData
.
get
(
columnIndex
-
1
).
toString
()));
res
=
new
BigDecimal
(
Long
.
valueOf
(
this
.
rowData
.
get
Object
(
columnIndex
).
toString
()));
break
;
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_DOUBLE
:
res
=
new
BigDecimal
(
Double
.
valueOf
(
this
.
rowData
.
get
(
columnIndex
-
1
).
toString
()));
res
=
new
BigDecimal
(
Double
.
valueOf
(
this
.
rowData
.
get
Object
(
columnIndex
).
toString
()));
break
;
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
return
new
BigDecimal
(((
Timestamp
)
this
.
rowData
.
get
(
columnIndex
-
1
)).
getTime
());
return
new
BigDecimal
(((
Timestamp
)
this
.
rowData
.
get
Object
(
columnIndex
)).
getTime
());
default
:
res
=
new
BigDecimal
(
this
.
rowData
.
get
(
columnIndex
-
1
).
toString
());
res
=
new
BigDecimal
(
this
.
rowData
.
get
Object
(
columnIndex
).
toString
());
}
}
return
res
;
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java
浏览文件 @
6f6a02f8
...
...
@@ -29,6 +29,8 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.List
;
import
com.taosdata.jdbc.utils.NullType
;
public
class
TSDBResultSetBlockData
{
private
int
numOfRows
=
0
;
private
int
rowIndex
=
0
;
...
...
@@ -164,59 +166,7 @@ public class TSDBResultSetBlockData {
}
}
private
static
class
NullType
{
private
static
final
byte
NULL_BOOL_VAL
=
0x2
;
private
static
final
String
NULL_STR
=
"null"
;
public
String
toString
()
{
return
NullType
.
NULL_STR
;
}
public
static
boolean
isBooleanNull
(
byte
val
)
{
return
val
==
NullType
.
NULL_BOOL_VAL
;
}
private
static
boolean
isTinyIntNull
(
byte
val
)
{
return
val
==
Byte
.
MIN_VALUE
;
}
private
static
boolean
isSmallIntNull
(
short
val
)
{
return
val
==
Short
.
MIN_VALUE
;
}
private
static
boolean
isIntNull
(
int
val
)
{
return
val
==
Integer
.
MIN_VALUE
;
}
private
static
boolean
isBigIntNull
(
long
val
)
{
return
val
==
Long
.
MIN_VALUE
;
}
private
static
boolean
isFloatNull
(
float
val
)
{
return
Float
.
isNaN
(
val
);
}
private
static
boolean
isDoubleNull
(
double
val
)
{
return
Double
.
isNaN
(
val
);
}
private
static
boolean
isBinaryNull
(
byte
[]
val
,
int
length
)
{
if
(
length
!=
Byte
.
BYTES
)
{
return
false
;
}
return
val
[
0
]
==
0xFF
;
}
private
static
boolean
isNcharNull
(
byte
[]
val
,
int
length
)
{
if
(
length
!=
Integer
.
BYTES
)
{
return
false
;
}
return
(
val
[
0
]
&
val
[
1
]
&
val
[
2
]
&
val
[
3
])
==
0xFF
;
}
}
/**
* The original type may not be a string type, but will be converted to by
...
...
@@ -488,8 +438,8 @@ public class TSDBResultSetBlockData {
}
try
{
String
ss
=
TaosGlobalConfig
.
getCharset
();
return
new
String
(
dest
,
ss
);
String
charset
=
TaosGlobalConfig
.
getCharset
();
return
new
String
(
dest
,
charset
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java
浏览文件 @
6f6a02f8
...
...
@@ -113,6 +113,7 @@ public class TSDBResultSetMetaData extends WrapperImpl implements ResultSetMetaD
ColumnMetaData
columnMetaData
=
this
.
colMetaDataList
.
get
(
column
-
1
);
switch
(
columnMetaData
.
getColType
())
{
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
return
5
;
case
TSDBConstants
.
TSDB_DATA_TYPE_DOUBLE
:
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java
浏览文件 @
6f6a02f8
...
...
@@ -14,6 +14,8 @@
*****************************************************************************/
package
com.taosdata.jdbc
;
import
com.taosdata.jdbc.utils.NullType
;
import
java.math.BigDecimal
;
import
java.sql.SQLException
;
import
java.sql.Timestamp
;
...
...
@@ -22,11 +24,13 @@ import java.util.ArrayList;
import
java.util.Collections
;
public
class
TSDBResultSetRowData
{
private
ArrayList
<
Object
>
data
;
private
int
colSize
=
0
;
private
int
colSize
;
public
TSDBResultSetRowData
(
int
colSize
)
{
this
.
setColSize
(
colSize
);
this
.
colSize
=
colSize
;
this
.
clear
();
}
public
void
clear
()
{
...
...
@@ -41,67 +45,104 @@ public class TSDBResultSetRowData {
}
public
boolean
wasNull
(
int
col
)
{
return
data
.
get
(
col
)
==
null
;
return
data
.
get
(
col
-
1
)
==
null
;
}
/**
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setBooleanValue
(
int
col
,
boolean
value
)
{
setBoolean
(
col
-
1
,
value
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
*/
public
void
setBoolean
(
int
col
,
boolean
value
)
{
data
.
set
(
col
,
value
);
}
public
boolean
getBoolean
(
int
col
,
int
src
Type
)
throws
SQLException
{
Object
obj
=
data
.
get
(
col
);
public
boolean
getBoolean
(
int
col
,
int
native
Type
)
throws
SQLException
{
Object
obj
=
data
.
get
(
col
-
1
);
switch
(
src
Type
)
{
switch
(
native
Type
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_BOOL
:
return
(
Boolean
)
obj
;
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
return
((
Float
)
obj
)
==
1.0
?
Boolean
.
TRUE
:
Boolean
.
FALSE
;
case
TSDBConstants
.
TSDB_DATA_TYPE_DOUBLE
:
return
((
Double
)
obj
)
==
1.0
?
Boolean
.
TRUE
:
Boolean
.
FALSE
;
case
TSDBConstants
.
TSDB_DATA_TYPE_TINYINT
:
return
((
Byte
)
obj
)
==
1
?
Boolean
.
TRUE
:
Boolean
.
FALSE
;
case
TSDBConstants
.
TSDB_DATA_TYPE_SMALLINT
:
return
((
Short
)
obj
)
==
1
?
Boolean
.
TRUE
:
Boolean
.
FALSE
;
case
TSDBConstants
.
TSDB_DATA_TYPE_INT
:
return
((
Integer
)
obj
)
==
1
?
Boolean
.
TRUE
:
Boolean
.
FALSE
;
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
:
return
((
Long
)
obj
)
==
1L
?
Boolean
.
TRUE
:
Boolean
.
FALSE
;
case
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
:
case
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
:
{
return
obj
.
toString
().
contains
(
"1"
);
}
default
:
return
false
;
}
}
/**
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setByteValue
(
int
colIndex
,
byte
value
)
{
setByte
(
colIndex
-
1
,
value
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
*/
public
void
setByte
(
int
col
,
byte
value
)
{
data
.
set
(
col
,
value
);
}
/**
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setShortValue
(
int
colIndex
,
short
value
)
{
setShort
(
colIndex
-
1
,
value
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
*/
public
void
setShort
(
int
col
,
short
value
)
{
data
.
set
(
col
,
value
);
}
/**
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setIntValue
(
int
colIndex
,
int
value
)
{
setInt
(
colIndex
-
1
,
value
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
*/
public
void
setInt
(
int
col
,
int
value
)
{
data
.
set
(
col
,
value
);
}
public
int
getInt
(
int
col
,
int
srcType
)
throws
SQLException
{
Object
obj
=
data
.
get
(
col
);
public
int
getInt
(
int
col
,
int
nativeType
)
throws
SQLException
{
Object
obj
=
data
.
get
(
col
-
1
);
if
(
obj
==
null
)
return
NullType
.
getIntNull
();
switch
(
src
Type
)
{
switch
(
native
Type
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_BOOL
:
return
Boolean
.
TRUE
.
equals
(
obj
)
?
1
:
0
;
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
return
((
Float
)
obj
).
intValue
();
case
TSDBConstants
.
TSDB_DATA_TYPE_DOUBLE
:
return
((
Double
)
obj
).
intValue
();
case
TSDBConstants
.
TSDB_DATA_TYPE_TINYINT
:
return
(
Byte
)
obj
;
case
TSDBConstants
.
TSDB_DATA_TYPE_SMALLINT
:
return
(
Short
)
obj
;
case
TSDBConstants
.
TSDB_DATA_TYPE_INT
:
return
(
Integer
)
obj
;
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
return
((
Long
)
obj
).
intValue
();
case
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
:
case
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
:
...
...
@@ -128,35 +169,48 @@ public class TSDBResultSetRowData {
long
value
=
(
long
)
obj
;
if
(
value
<
0
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_NUMERIC_VALUE_OUT_OF_RANGE
);
return
new
Long
(
value
).
intValue
();
return
Long
.
valueOf
(
value
).
intValue
();
}
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
return
((
Float
)
obj
).
intValue
();
case
TSDBConstants
.
TSDB_DATA_TYPE_DOUBLE
:
return
((
Double
)
obj
).
intValue
();
default
:
return
0
;
}
}
return
0
;
/**
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setLongValue
(
int
colIndex
,
long
value
)
{
setLong
(
colIndex
-
1
,
value
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
*/
public
void
setLong
(
int
col
,
long
value
)
{
data
.
set
(
col
,
value
);
}
public
long
getLong
(
int
col
,
int
srcType
)
throws
SQLException
{
Object
obj
=
data
.
get
(
col
);
public
long
getLong
(
int
col
,
int
nativeType
)
throws
SQLException
{
Object
obj
=
data
.
get
(
col
-
1
);
if
(
obj
==
null
)
{
return
NullType
.
getBigIntNull
();
}
switch
(
src
Type
)
{
switch
(
native
Type
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_BOOL
:
return
Boolean
.
TRUE
.
equals
(
obj
)
?
1
:
0
;
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
return
((
Float
)
obj
).
longValue
();
case
TSDBConstants
.
TSDB_DATA_TYPE_DOUBLE
:
return
((
Double
)
obj
).
longValue
();
case
TSDBConstants
.
TSDB_DATA_TYPE_TINYINT
:
return
(
Byte
)
obj
;
case
TSDBConstants
.
TSDB_DATA_TYPE_SMALLINT
:
return
(
Short
)
obj
;
case
TSDBConstants
.
TSDB_DATA_TYPE_INT
:
return
(
Integer
)
obj
;
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
return
(
Long
)
obj
;
case
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
:
case
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
:
...
...
@@ -185,19 +239,35 @@ public class TSDBResultSetRowData {
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_NUMERIC_VALUE_OUT_OF_RANGE
);
return
value
;
}
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
return
((
Float
)
obj
).
longValue
();
case
TSDBConstants
.
TSDB_DATA_TYPE_DOUBLE
:
return
((
Double
)
obj
).
longValue
();
default
:
return
0
;
}
}
return
0
;
/**
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setFloatValue
(
int
colIndex
,
float
value
)
{
setFloat
(
colIndex
-
1
,
value
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
*/
public
void
setFloat
(
int
col
,
float
value
)
{
data
.
set
(
col
,
value
);
}
public
float
getFloat
(
int
col
,
int
srcType
)
{
Object
obj
=
data
.
get
(
col
);
public
float
getFloat
(
int
col
,
int
nativeType
)
{
Object
obj
=
data
.
get
(
col
-
1
);
if
(
obj
==
null
)
return
NullType
.
getFloatNull
();
switch
(
src
Type
)
{
switch
(
native
Type
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_BOOL
:
return
Boolean
.
TRUE
.
equals
(
obj
)
?
1
:
0
;
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
...
...
@@ -213,19 +283,31 @@ public class TSDBResultSetRowData {
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
:
return
(
Long
)
obj
;
default
:
return
NullType
.
getFloatNull
();
}
}
return
0
;
/**
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setDoubleValue
(
int
colIndex
,
double
value
)
{
setDouble
(
colIndex
-
1
,
value
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
*/
public
void
setDouble
(
int
col
,
double
value
)
{
data
.
set
(
col
,
value
);
}
public
double
getDouble
(
int
col
,
int
srcType
)
{
Object
obj
=
data
.
get
(
col
);
public
double
getDouble
(
int
col
,
int
nativeType
)
{
Object
obj
=
data
.
get
(
col
-
1
);
if
(
obj
==
null
)
return
NullType
.
getDoubleNull
();
switch
(
src
Type
)
{
switch
(
native
Type
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_BOOL
:
return
Boolean
.
TRUE
.
equals
(
obj
)
?
1
:
0
;
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
...
...
@@ -241,16 +323,46 @@ public class TSDBResultSetRowData {
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
:
return
(
Long
)
obj
;
default
:
return
NullType
.
getDoubleNull
();
}
}
return
0
;
/**
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setStringValue
(
int
colIndex
,
String
value
)
{
data
.
set
(
colIndex
-
1
,
value
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
*/
public
void
setString
(
int
col
,
String
value
)
{
data
.
set
(
col
,
value
);
// TODO:
// !!!NOTE!!!
// this is very confusing problem which related to JNI-method implementation,
// the JNI method return a String(encoded in UTF) for BINARY value, which means the JNI method will invoke
// this setString(int, String) to handle BINARY value, we need to build a byte[] with default charsetEncoding
data
.
set
(
col
,
value
==
null
?
null
:
value
.
getBytes
());
}
/**
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setByteArrayValue
(
int
colIndex
,
byte
[]
value
)
{
setByteArray
(
colIndex
-
1
,
value
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
*/
public
void
setByteArray
(
int
col
,
byte
[]
value
)
{
// TODO:
// !!!NOTE!!!
// this is very confusing problem which related to JNI-method implementation,
// the JNI method return a byte[] for NCHAR value, which means the JNI method will invoke
// this setByteArr(int, byte[]) to handle NCHAR value, we need to build a String with charsetEncoding by TaosGlobalConfig
try
{
data
.
set
(
col
,
new
String
(
value
,
TaosGlobalConfig
.
getCharset
()));
}
catch
(
Exception
e
)
{
...
...
@@ -258,47 +370,56 @@ public class TSDBResultSetRowData {
}
}
/**
* The original type may not be a string type, but will be converted to by calling this method
*
* @param col column index
* @return
*/
public
String
getString
(
int
col
,
int
srcType
)
{
switch
(
srcType
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
:
case
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
:
return
(
String
)
data
.
get
(
col
);
public
String
getString
(
int
col
,
int
nativeType
)
{
Object
obj
=
data
.
get
(
col
-
1
);
if
(
obj
==
null
)
return
null
;
switch
(
nativeType
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_UTINYINT
:
{
Byte
value
=
new
Byte
(
String
.
valueOf
(
data
.
get
(
col
)
));
Byte
value
=
new
Byte
(
String
.
valueOf
(
obj
));
if
(
value
>=
0
)
return
value
.
toString
();
return
Integer
.
toString
(
value
&
0xff
);
}
case
TSDBConstants
.
TSDB_DATA_TYPE_USMALLINT
:
{
Short
value
=
new
Short
(
String
.
valueOf
(
data
.
get
(
col
)
));
Short
value
=
new
Short
(
String
.
valueOf
(
obj
));
if
(
value
>=
0
)
return
value
.
toString
();
return
Integer
.
toString
(
value
&
0xffff
);
}
case
TSDBConstants
.
TSDB_DATA_TYPE_UINT
:
{
Integer
value
=
new
Integer
(
String
.
valueOf
(
data
.
get
(
col
)
));
Integer
value
=
new
Integer
(
String
.
valueOf
(
obj
));
if
(
value
>=
0
)
return
value
.
toString
();
return
Long
.
toString
(
value
&
0xffffffff
l
);
}
case
TSDBConstants
.
TSDB_DATA_TYPE_UBIGINT
:
{
Long
value
=
new
Long
(
String
.
valueOf
(
data
.
get
(
col
)
));
Long
value
=
new
Long
(
String
.
valueOf
(
obj
));
if
(
value
>=
0
)
return
value
.
toString
();
long
lowValue
=
value
&
0x7fffffffffffffff
L
;
return
BigDecimal
.
valueOf
(
lowValue
).
add
(
BigDecimal
.
valueOf
(
Long
.
MAX_VALUE
)).
add
(
BigDecimal
.
valueOf
(
1
)).
toString
();
}
case
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
:
return
new
String
((
byte
[])
obj
);
case
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
:
return
(
String
)
obj
;
default
:
return
String
.
valueOf
(
data
.
get
(
col
));
return
String
.
valueOf
(
obj
);
}
}
/**
* $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api
*/
public
void
setTimestampValue
(
int
colIndex
,
long
value
)
{
setTimestamp
(
colIndex
-
1
,
value
);
}
/**
* !!! this method is invoked by JNI method and the index start from 0 in C implementations
*/
public
void
setTimestamp
(
int
col
,
long
ts
)
{
//TODO: this implementation contains logical error
// when precision is us the (long ts) is 16 digital number
...
...
@@ -315,28 +436,20 @@ public class TSDBResultSetRowData {
}
}
public
Timestamp
getTimestamp
(
int
col
)
{
return
(
Timestamp
)
data
.
get
(
col
);
}
public
Object
get
(
int
col
)
{
return
data
.
get
(
col
);
}
public
int
getColSize
()
{
return
colSize
;
public
Timestamp
getTimestamp
(
int
col
,
int
nativeType
)
{
Object
obj
=
data
.
get
(
col
-
1
);
if
(
obj
==
null
)
return
null
;
switch
(
nativeType
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
:
return
new
Timestamp
((
Long
)
obj
);
default
:
return
(
Timestamp
)
obj
;
}
private
void
setColSize
(
int
colSize
)
{
this
.
colSize
=
colSize
;
this
.
clear
();
}
public
ArrayList
<
Object
>
getData
(
)
{
return
data
;
public
Object
getObject
(
int
col
)
{
return
data
.
get
(
col
-
1
)
;
}
public
void
setData
(
ArrayList
<
Object
>
data
)
{
this
.
data
=
(
ArrayList
<
Object
>)
data
.
clone
();
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
浏览文件 @
6f6a02f8
...
...
@@ -19,8 +19,6 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
public
class
TSDBStatement
extends
AbstractStatement
{
private
TSDBJNIConnector
connector
;
/**
* Status of current statement
*/
...
...
@@ -29,29 +27,27 @@ public class TSDBStatement extends AbstractStatement {
private
TSDBConnection
connection
;
private
TSDBResultSet
resultSet
;
public
void
setConnection
(
TSDBConnection
connection
)
{
TSDBStatement
(
TSDBConnection
connection
)
{
this
.
connection
=
connection
;
}
TSDBStatement
(
TSDBConnection
connection
,
TSDBJNIConnector
connector
)
{
this
.
connection
=
connection
;
this
.
connector
=
connector
;
}
public
ResultSet
executeQuery
(
String
sql
)
throws
SQLException
{
// check if closed
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
//TODO: 如果在executeQuery方法中执行insert语句,那么先执行了SQL,再通过pSql来检查是否为一个insert语句,但这个insert SQL已经执行成功了
// execute query
long
pSql
=
this
.
connector
.
executeQuery
(
sql
);
}
//TODO:
// this is an unreasonable implementation, if the paratemer is a insert statement,
// the JNI connector will execute the sql at first and return a pointer: pSql,
// we use this pSql and invoke the isUpdateQuery(long pSql) method to decide .
// but the insert sql is already executed in database.
//execute query
long
pSql
=
this
.
connection
.
getConnector
().
executeQuery
(
sql
);
// if pSql is create/insert/update/delete/alter SQL
if
(
this
.
connect
or
.
isUpdateQuery
(
pSql
))
{
this
.
connect
or
.
freeResultSet
(
pSql
);
if
(
this
.
connect
ion
.
getConnector
()
.
isUpdateQuery
(
pSql
))
{
this
.
connect
ion
.
getConnector
()
.
freeResultSet
(
pSql
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_WITH_EXECUTEQUERY
);
}
TSDBResultSet
res
=
new
TSDBResultSet
(
this
,
this
.
connect
or
,
pSql
);
TSDBResultSet
res
=
new
TSDBResultSet
(
this
,
this
.
connect
ion
.
getConnector
()
,
pSql
);
res
.
setBatchFetch
(
this
.
connection
.
getBatchFetch
());
return
res
;
}
...
...
@@ -60,14 +56,14 @@ public class TSDBStatement extends AbstractStatement {
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
long
pSql
=
this
.
connect
or
.
executeQuery
(
sql
);
long
pSql
=
this
.
connect
ion
.
getConnector
()
.
executeQuery
(
sql
);
// if pSql is create/insert/update/delete/alter SQL
if
(!
this
.
connect
or
.
isUpdateQuery
(
pSql
))
{
this
.
connect
or
.
freeResultSet
(
pSql
);
if
(!
this
.
connect
ion
.
getConnector
()
.
isUpdateQuery
(
pSql
))
{
this
.
connect
ion
.
getConnector
()
.
freeResultSet
(
pSql
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_WITH_EXECUTEUPDATE
);
}
int
affectedRows
=
this
.
connect
or
.
getAffectedRows
(
pSql
);
this
.
connect
or
.
freeResultSet
(
pSql
);
int
affectedRows
=
this
.
connect
ion
.
getConnector
()
.
getAffectedRows
(
pSql
);
this
.
connect
ion
.
getConnector
()
.
freeResultSet
(
pSql
);
return
affectedRows
;
}
...
...
@@ -81,30 +77,29 @@ public class TSDBStatement extends AbstractStatement {
public
boolean
execute
(
String
sql
)
throws
SQLException
{
// check if closed
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
}
// execute query
long
pSql
=
this
.
connect
or
.
executeQuery
(
sql
);
long
pSql
=
this
.
connect
ion
.
getConnector
()
.
executeQuery
(
sql
);
// if pSql is create/insert/update/delete/alter SQL
if
(
this
.
connect
or
.
isUpdateQuery
(
pSql
))
{
this
.
affectedRows
=
this
.
connect
or
.
getAffectedRows
(
pSql
);
this
.
connect
or
.
freeResultSet
(
pSql
);
if
(
this
.
connect
ion
.
getConnector
()
.
isUpdateQuery
(
pSql
))
{
this
.
affectedRows
=
this
.
connect
ion
.
getConnector
()
.
getAffectedRows
(
pSql
);
this
.
connect
ion
.
getConnector
()
.
freeResultSet
(
pSql
);
return
false
;
}
this
.
resultSet
=
new
TSDBResultSet
(
this
,
this
.
connect
or
,
pSql
);
this
.
resultSet
=
new
TSDBResultSet
(
this
,
this
.
connect
ion
.
getConnector
()
,
pSql
);
this
.
resultSet
.
setBatchFetch
(
this
.
connection
.
getBatchFetch
());
return
true
;
}
public
ResultSet
getResultSet
()
throws
SQLException
{
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
// long resultSetPointer = connector.getResultSet();
// TSDBResultSet resSet = null;
// if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) {
// resSet = new TSDBResultSet(connector, resultSetPointer);
// }
}
return
this
.
resultSet
;
}
...
...
@@ -115,13 +110,21 @@ public class TSDBStatement extends AbstractStatement {
}
public
Connection
getConnection
()
throws
SQLException
{
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
this
.
connector
==
null
)
}
if
(
this
.
connection
.
getConnector
()
==
null
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
return
this
.
connection
;
}
public
void
setConnection
(
TSDBConnection
connection
)
{
this
.
connection
=
connection
;
}
public
boolean
isClosed
()
throws
SQLException
{
return
isClosed
;
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/NullType.java
0 → 100755
浏览文件 @
6f6a02f8
package
com.taosdata.jdbc.utils
;
public
class
NullType
{
private
static
final
byte
NULL_BOOL_VAL
=
0x2
;
private
static
final
String
NULL_STR
=
"null"
;
public
String
toString
()
{
return
NullType
.
NULL_STR
;
}
public
static
boolean
isBooleanNull
(
byte
val
)
{
return
val
==
NullType
.
NULL_BOOL_VAL
;
}
public
static
boolean
isTinyIntNull
(
byte
val
)
{
return
val
==
Byte
.
MIN_VALUE
;
}
public
static
boolean
isSmallIntNull
(
short
val
)
{
return
val
==
Short
.
MIN_VALUE
;
}
public
static
boolean
isIntNull
(
int
val
)
{
return
val
==
Integer
.
MIN_VALUE
;
}
public
static
boolean
isBigIntNull
(
long
val
)
{
return
val
==
Long
.
MIN_VALUE
;
}
public
static
boolean
isFloatNull
(
float
val
)
{
return
Float
.
isNaN
(
val
);
}
public
static
boolean
isDoubleNull
(
double
val
)
{
return
Double
.
isNaN
(
val
);
}
public
static
boolean
isBinaryNull
(
byte
[]
val
,
int
length
)
{
if
(
length
!=
Byte
.
BYTES
)
{
return
false
;
}
return
val
[
0
]
==
0xFF
;
}
public
static
boolean
isNcharNull
(
byte
[]
val
,
int
length
)
{
if
(
length
!=
Integer
.
BYTES
)
{
return
false
;
}
return
(
val
[
0
]
&
val
[
1
]
&
val
[
2
]
&
val
[
3
])
==
0xFF
;
}
public
static
byte
getBooleanNull
()
{
return
NullType
.
NULL_BOOL_VAL
;
}
public
static
byte
getTinyintNull
()
{
return
Byte
.
MIN_VALUE
;
}
public
static
int
getIntNull
()
{
return
Integer
.
MIN_VALUE
;
}
public
static
short
getSmallIntNull
()
{
return
Short
.
MIN_VALUE
;
}
public
static
long
getBigIntNull
()
{
return
Long
.
MIN_VALUE
;
}
public
static
int
getFloatNull
()
{
return
0x7FF00000
;
}
public
static
long
getDoubleNull
()
{
return
0x7FFFFF0000000000
L
;
}
public
static
byte
getBinaryNull
()
{
return
(
byte
)
0xFF
;
}
public
static
byte
[]
getNcharNull
()
{
return
new
byte
[]
{(
byte
)
0xFF
,
(
byte
)
0xFF
,
(
byte
)
0xFF
,
(
byte
)
0xFF
};
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java
浏览文件 @
6f6a02f8
...
...
@@ -95,16 +95,7 @@ public class Utils {
public
static
String
getNativeSql
(
String
rawSql
,
Object
[]
parameters
)
{
// toLowerCase
String
preparedSql
=
rawSql
.
trim
().
toLowerCase
();
String
[]
clause
=
new
String
[
0
];
if
(
SqlSyntaxValidator
.
isInsertSql
(
preparedSql
))
{
// insert or import
clause
=
new
String
[]{
"values\\s*\\(.*?\\)"
,
"tags\\s*\\(.*?\\)"
};
}
if
(
SqlSyntaxValidator
.
isSelectSql
(
preparedSql
))
{
// select
clause
=
new
String
[]{
"where\\s*.*"
};
}
String
[]
clause
=
new
String
[]{
"values\\s*\\(.*?\\)"
,
"tags\\s*\\(.*?\\)"
,
"where\\s*.*"
};
Map
<
Integer
,
Integer
>
placeholderPositions
=
new
HashMap
<>();
RangeSet
<
Integer
>
clauseRangeSet
=
TreeRangeSet
.
create
();
findPlaceholderPosition
(
preparedSql
,
placeholderPositions
);
...
...
@@ -146,6 +137,7 @@ public class Utils {
*/
private
static
String
transformSql
(
String
rawSql
,
Object
[]
paramArr
,
Map
<
Integer
,
Integer
>
placeholderPosition
,
RangeSet
<
Integer
>
clauseRangeSet
)
{
String
[]
sqlArr
=
rawSql
.
split
(
"\\?"
);
return
IntStream
.
range
(
0
,
sqlArr
.
length
).
mapToObj
(
index
->
{
if
(
index
==
paramArr
.
length
)
return
sqlArr
[
index
];
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java
浏览文件 @
6f6a02f8
...
...
@@ -32,20 +32,34 @@ public class TSDBConnectionTest {
}
@Test
public
void
s
ubscribe
()
{
public
void
runS
ubscribe
()
{
try
{
// given
TSDBConnection
unwrap
=
conn
.
unwrap
(
TSDBConnection
.
class
);
TSDBSubscribe
subscribe
=
unwrap
.
subscribe
(
"topic1"
,
"select * from log.log"
,
false
);
// when
TSDBResultSet
rs
=
subscribe
.
consume
();
ResultSetMetaData
metaData
=
rs
.
getMetaData
();
for
(
int
count
=
0
;
count
<
10
&&
rs
.
next
();
count
++)
{
for
(
int
i
=
1
;
i
<=
metaData
.
getColumnCount
();
i
++)
{
String
value
=
rs
.
getString
(
i
);
System
.
out
.
print
(
metaData
.
getColumnLabel
(
i
)
+
":"
+
value
+
"\t"
);
}
System
.
out
.
println
();
}
// then
Assert
.
assertNotNull
(
rs
);
Assert
.
assertEquals
(
4
,
metaData
.
getColumnCount
());
Assert
.
assertEquals
(
"ts"
,
metaData
.
getColumnLabel
(
1
));
Assert
.
assertEquals
(
"level"
,
metaData
.
getColumnLabel
(
2
));
Assert
.
assertEquals
(
"content"
,
metaData
.
getColumnLabel
(
3
));
Assert
.
assertEquals
(
"ipaddr"
,
metaData
.
getColumnLabel
(
4
));
rs
.
next
();
// row 1
{
Assert
.
assertNotNull
(
rs
.
getTimestamp
(
1
));
Assert
.
assertNotNull
(
rs
.
getTimestamp
(
"ts"
));
Assert
.
assertNotNull
(
rs
.
getByte
(
2
));
Assert
.
assertNotNull
(
rs
.
getByte
(
"level"
));
Assert
.
assertNotNull
(
rs
.
getString
(
3
));
Assert
.
assertNotNull
(
rs
.
getString
(
"content"
));
Assert
.
assertNotNull
(
rs
.
getString
(
4
));
Assert
.
assertNotNull
(
rs
.
getString
(
"ipaddr"
));
}
subscribe
.
close
(
false
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
浏览文件 @
6f6a02f8
...
...
@@ -7,9 +7,11 @@ import java.util.Properties;
public
class
TSDBDatabaseMetaDataTest
{
private
static
final
String
host
=
"127.0.0.1"
;
private
static
final
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
;
private
static
Connection
connection
;
private
static
TSDBDatabaseMetaData
metaData
;
@Test
public
void
unwrap
()
throws
SQLException
{
TSDBDatabaseMetaData
unwrap
=
metaData
.
unwrap
(
TSDBDatabaseMetaData
.
class
);
...
...
@@ -33,7 +35,7 @@ public class TSDBDatabaseMetaDataTest {
@Test
public
void
getURL
()
throws
SQLException
{
Assert
.
assertEquals
(
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
,
metaData
.
getURL
());
Assert
.
assertEquals
(
url
,
metaData
.
getURL
());
}
@Test
...
...
@@ -627,17 +629,32 @@ 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
())
{
System
.
out
.
print
(
metaData
.
getColumnLabel
(
1
)
+
":"
+
tables
.
getString
(
1
)
+
"\t"
);
System
.
out
.
print
(
metaData
.
getColumnLabel
(
3
)
+
":"
+
tables
.
getString
(
3
)
+
"\t"
);
System
.
out
.
print
(
metaData
.
getColumnLabel
(
4
)
+
":"
+
tables
.
getString
(
4
)
+
"\t"
);
System
.
out
.
print
(
metaData
.
getColumnLabel
(
5
)
+
":"
+
tables
.
getString
(
5
)
+
"\n"
);
ResultSet
rs
=
metaData
.
getTables
(
"log"
,
""
,
null
,
null
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
Assert
.
assertNotNull
(
rs
);
rs
.
next
();
{
// TABLE_CAT
Assert
.
assertEquals
(
"TABLE_CAT"
,
meta
.
getColumnLabel
(
1
));
Assert
.
assertEquals
(
"log"
,
rs
.
getString
(
1
));
Assert
.
assertEquals
(
"log"
,
rs
.
getString
(
"TABLE_CAT"
));
// TABLE_SCHEM
Assert
.
assertEquals
(
"TABLE_SCHEM"
,
meta
.
getColumnLabel
(
2
));
Assert
.
assertEquals
(
null
,
rs
.
getString
(
2
));
Assert
.
assertEquals
(
null
,
rs
.
getString
(
"TABLE_SCHEM"
));
// TABLE_NAME
Assert
.
assertEquals
(
"TABLE_NAME"
,
meta
.
getColumnLabel
(
3
));
Assert
.
assertNotNull
(
rs
.
getString
(
3
));
Assert
.
assertNotNull
(
rs
.
getString
(
"TABLE_NAME"
));
// TABLE_TYPE
Assert
.
assertEquals
(
"TABLE_TYPE"
,
meta
.
getColumnLabel
(
4
));
Assert
.
assertEquals
(
"TABLE"
,
rs
.
getString
(
4
));
Assert
.
assertEquals
(
"TABLE"
,
rs
.
getString
(
"TABLE_TYPE"
));
// REMARKS
Assert
.
assertEquals
(
"REMARKS"
,
meta
.
getColumnLabel
(
5
));
Assert
.
assertEquals
(
""
,
rs
.
getString
(
5
));
Assert
.
assertEquals
(
""
,
rs
.
getString
(
"REMARKS"
));
}
System
.
out
.
println
();
Assert
.
assertNotNull
(
tables
);
}
@Test
...
...
@@ -647,46 +664,130 @@ public class TSDBDatabaseMetaDataTest {
@Test
public
void
getCatalogs
()
throws
SQLException
{
System
.
out
.
println
(
"****************************************************"
);
ResultSet
catalogs
=
metaData
.
getCatalogs
();
ResultSetMetaData
meta
=
catalogs
.
getMetaData
();
while
(
catalogs
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
System
.
out
.
print
(
meta
.
getColumnLabel
(
i
)
+
": "
+
catalogs
.
getString
(
i
));
}
System
.
out
.
println
();
ResultSet
rs
=
metaData
.
getCatalogs
();
ResultSetMetaData
meta
=
rs
.
getMetaData
();
rs
.
next
();
{
// TABLE_CAT
Assert
.
assertEquals
(
"TABLE_CAT"
,
meta
.
getColumnLabel
(
1
));
Assert
.
assertNotNull
(
rs
.
getString
(
1
));
Assert
.
assertNotNull
(
rs
.
getString
(
"TABLE_CAT"
));
}
}
@Test
public
void
getTableTypes
()
throws
SQLException
{
System
.
out
.
println
(
"****************************************************"
);
ResultSet
tableTypes
=
metaData
.
getTableTypes
();
while
(
tableTypes
.
next
())
{
System
.
out
.
println
(
tableTypes
.
getString
(
"TABLE_TYPE"
));
tableTypes
.
next
();
// tableTypes: table
{
Assert
.
assertEquals
(
"TABLE"
,
tableTypes
.
getString
(
1
));
Assert
.
assertEquals
(
"TABLE"
,
tableTypes
.
getString
(
"TABLE_TYPE"
));
}
tableTypes
.
next
();
// tableTypes: stable
{
Assert
.
assertEquals
(
"STABLE"
,
tableTypes
.
getString
(
1
));
Assert
.
assertEquals
(
"STABLE"
,
tableTypes
.
getString
(
"TABLE_TYPE"
));
}
Assert
.
assertNotNull
(
metaData
.
getTableTypes
());
}
@Test
public
void
getColumns
()
throws
SQLException
{
System
.
out
.
println
(
"****************************************************"
);
// when
ResultSet
columns
=
metaData
.
getColumns
(
"log"
,
""
,
"dn"
,
""
);
// then
ResultSetMetaData
meta
=
columns
.
getMetaData
();
while
(
columns
.
next
())
{
System
.
out
.
print
(
meta
.
getColumnLabel
(
1
)
+
": "
+
columns
.
getString
(
1
)
+
"\t"
);
System
.
out
.
print
(
meta
.
getColumnLabel
(
3
)
+
": "
+
columns
.
getString
(
3
)
+
"\t"
);
System
.
out
.
print
(
meta
.
getColumnLabel
(
4
)
+
": "
+
columns
.
getString
(
4
)
+
"\t"
);
System
.
out
.
print
(
meta
.
getColumnLabel
(
5
)
+
": "
+
columns
.
getString
(
5
)
+
"\t"
);
System
.
out
.
print
(
meta
.
getColumnLabel
(
6
)
+
": "
+
columns
.
getString
(
6
)
+
"\t"
);
System
.
out
.
print
(
meta
.
getColumnLabel
(
7
)
+
": "
+
columns
.
getString
(
7
)
+
"\t"
);
System
.
out
.
print
(
meta
.
getColumnLabel
(
9
)
+
": "
+
columns
.
getString
(
9
)
+
"\t"
);
System
.
out
.
print
(
meta
.
getColumnLabel
(
10
)
+
": "
+
columns
.
getString
(
10
)
+
"\t"
);
System
.
out
.
print
(
meta
.
getColumnLabel
(
11
)
+
": "
+
columns
.
getString
(
11
)
+
"\n"
);
System
.
out
.
print
(
meta
.
getColumnLabel
(
12
)
+
": "
+
columns
.
getString
(
12
)
+
"\n"
);
columns
.
next
();
// column: 1
{
// TABLE_CAT
Assert
.
assertEquals
(
"TABLE_CAT"
,
meta
.
getColumnLabel
(
1
));
Assert
.
assertEquals
(
"log"
,
columns
.
getString
(
1
));
Assert
.
assertEquals
(
"log"
,
columns
.
getString
(
"TABLE_CAT"
));
// TABLE_NAME
Assert
.
assertEquals
(
"TABLE_NAME"
,
meta
.
getColumnLabel
(
3
));
Assert
.
assertEquals
(
"dn"
,
columns
.
getString
(
3
));
Assert
.
assertEquals
(
"dn"
,
columns
.
getString
(
"TABLE_NAME"
));
// COLUMN_NAME
Assert
.
assertEquals
(
"COLUMN_NAME"
,
meta
.
getColumnLabel
(
4
));
Assert
.
assertEquals
(
"ts"
,
columns
.
getString
(
4
));
Assert
.
assertEquals
(
"ts"
,
columns
.
getString
(
"COLUMN_NAME"
));
// DATA_TYPE
Assert
.
assertEquals
(
"DATA_TYPE"
,
meta
.
getColumnLabel
(
5
));
Assert
.
assertEquals
(
Types
.
TIMESTAMP
,
columns
.
getInt
(
5
));
Assert
.
assertEquals
(
Types
.
TIMESTAMP
,
columns
.
getInt
(
"DATA_TYPE"
));
// TYPE_NAME
Assert
.
assertEquals
(
"TYPE_NAME"
,
meta
.
getColumnLabel
(
6
));
Assert
.
assertEquals
(
"TIMESTAMP"
,
columns
.
getString
(
6
));
Assert
.
assertEquals
(
"TIMESTAMP"
,
columns
.
getString
(
"TYPE_NAME"
));
// COLUMN_SIZE
Assert
.
assertEquals
(
"COLUMN_SIZE"
,
meta
.
getColumnLabel
(
7
));
Assert
.
assertEquals
(
26
,
columns
.
getInt
(
7
));
Assert
.
assertEquals
(
26
,
columns
.
getInt
(
"COLUMN_SIZE"
));
// DECIMAL_DIGITS
Assert
.
assertEquals
(
"DECIMAL_DIGITS"
,
meta
.
getColumnLabel
(
9
));
Assert
.
assertEquals
(
Integer
.
MIN_VALUE
,
columns
.
getInt
(
9
));
Assert
.
assertEquals
(
Integer
.
MIN_VALUE
,
columns
.
getInt
(
"DECIMAL_DIGITS"
));
Assert
.
assertEquals
(
null
,
columns
.
getString
(
9
));
Assert
.
assertEquals
(
null
,
columns
.
getString
(
"DECIMAL_DIGITS"
));
// NUM_PREC_RADIX
Assert
.
assertEquals
(
"NUM_PREC_RADIX"
,
meta
.
getColumnLabel
(
10
));
Assert
.
assertEquals
(
10
,
columns
.
getInt
(
10
));
Assert
.
assertEquals
(
10
,
columns
.
getInt
(
"NUM_PREC_RADIX"
));
// NULLABLE
Assert
.
assertEquals
(
"NULLABLE"
,
meta
.
getColumnLabel
(
11
));
Assert
.
assertEquals
(
DatabaseMetaData
.
columnNoNulls
,
columns
.
getInt
(
11
));
Assert
.
assertEquals
(
DatabaseMetaData
.
columnNoNulls
,
columns
.
getInt
(
"NULLABLE"
));
// REMARKS
Assert
.
assertEquals
(
"REMARKS"
,
meta
.
getColumnLabel
(
12
));
Assert
.
assertEquals
(
null
,
columns
.
getString
(
12
));
Assert
.
assertEquals
(
null
,
columns
.
getString
(
"REMARKS"
));
}
columns
.
next
();
// column: 2
{
// TABLE_CAT
Assert
.
assertEquals
(
"TABLE_CAT"
,
meta
.
getColumnLabel
(
1
));
Assert
.
assertEquals
(
"log"
,
columns
.
getString
(
1
));
Assert
.
assertEquals
(
"log"
,
columns
.
getString
(
"TABLE_CAT"
));
// TABLE_NAME
Assert
.
assertEquals
(
"TABLE_NAME"
,
meta
.
getColumnLabel
(
3
));
Assert
.
assertEquals
(
"dn"
,
columns
.
getString
(
3
));
Assert
.
assertEquals
(
"dn"
,
columns
.
getString
(
"TABLE_NAME"
));
// COLUMN_NAME
Assert
.
assertEquals
(
"COLUMN_NAME"
,
meta
.
getColumnLabel
(
4
));
Assert
.
assertEquals
(
"cpu_taosd"
,
columns
.
getString
(
4
));
Assert
.
assertEquals
(
"cpu_taosd"
,
columns
.
getString
(
"COLUMN_NAME"
));
// DATA_TYPE
Assert
.
assertEquals
(
"DATA_TYPE"
,
meta
.
getColumnLabel
(
5
));
Assert
.
assertEquals
(
Types
.
FLOAT
,
columns
.
getInt
(
5
));
Assert
.
assertEquals
(
Types
.
FLOAT
,
columns
.
getInt
(
"DATA_TYPE"
));
// TYPE_NAME
Assert
.
assertEquals
(
"TYPE_NAME"
,
meta
.
getColumnLabel
(
6
));
Assert
.
assertEquals
(
"FLOAT"
,
columns
.
getString
(
6
));
Assert
.
assertEquals
(
"FLOAT"
,
columns
.
getString
(
"TYPE_NAME"
));
// COLUMN_SIZE
Assert
.
assertEquals
(
"COLUMN_SIZE"
,
meta
.
getColumnLabel
(
7
));
Assert
.
assertEquals
(
12
,
columns
.
getInt
(
7
));
Assert
.
assertEquals
(
12
,
columns
.
getInt
(
"COLUMN_SIZE"
));
// DECIMAL_DIGITS
Assert
.
assertEquals
(
"DECIMAL_DIGITS"
,
meta
.
getColumnLabel
(
9
));
Assert
.
assertEquals
(
Integer
.
MIN_VALUE
,
columns
.
getInt
(
9
));
Assert
.
assertEquals
(
Integer
.
MIN_VALUE
,
columns
.
getInt
(
"DECIMAL_DIGITS"
));
Assert
.
assertEquals
(
null
,
columns
.
getString
(
9
));
Assert
.
assertEquals
(
null
,
columns
.
getString
(
"DECIMAL_DIGITS"
));
// NUM_PREC_RADIX
Assert
.
assertEquals
(
"NUM_PREC_RADIX"
,
meta
.
getColumnLabel
(
10
));
Assert
.
assertEquals
(
10
,
columns
.
getInt
(
10
));
Assert
.
assertEquals
(
10
,
columns
.
getInt
(
"NUM_PREC_RADIX"
));
// NULLABLE
Assert
.
assertEquals
(
"NULLABLE"
,
meta
.
getColumnLabel
(
11
));
Assert
.
assertEquals
(
DatabaseMetaData
.
columnNullable
,
columns
.
getInt
(
11
));
Assert
.
assertEquals
(
DatabaseMetaData
.
columnNullable
,
columns
.
getInt
(
"NULLABLE"
));
// REMARKS
Assert
.
assertEquals
(
"REMARKS"
,
meta
.
getColumnLabel
(
12
));
Assert
.
assertEquals
(
null
,
columns
.
getString
(
12
));
}
}
...
...
@@ -712,17 +813,35 @@ public class TSDBDatabaseMetaDataTest {
@Test
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"
));
System
.
out
.
println
(
"COLUMN_NAME: "
+
rs
.
getString
(
"COLUMN_NAME"
));
System
.
out
.
println
(
"KEY_SEQ: "
+
rs
.
getString
(
"KEY_SEQ"
));
System
.
out
.
println
(
"PK_NAME: "
+
rs
.
getString
(
"PK_NAME"
));
ResultSetMetaData
meta
=
rs
.
getMetaData
();
rs
.
next
();
{
// TABLE_CAT
Assert
.
assertEquals
(
"TABLE_CAT"
,
meta
.
getColumnLabel
(
1
));
Assert
.
assertEquals
(
"log"
,
rs
.
getString
(
1
));
Assert
.
assertEquals
(
"log"
,
rs
.
getString
(
"TABLE_CAT"
));
// TABLE_SCHEM
Assert
.
assertEquals
(
"TABLE_SCHEM"
,
meta
.
getColumnLabel
(
2
));
Assert
.
assertEquals
(
null
,
rs
.
getString
(
2
));
Assert
.
assertEquals
(
null
,
rs
.
getString
(
"TABLE_SCHEM"
));
// TABLE_NAME
Assert
.
assertEquals
(
"TABLE_NAME"
,
meta
.
getColumnLabel
(
3
));
Assert
.
assertEquals
(
"dn1"
,
rs
.
getString
(
3
));
Assert
.
assertEquals
(
"dn1"
,
rs
.
getString
(
"TABLE_NAME"
));
// COLUMN_NAME
Assert
.
assertEquals
(
"COLUMN_NAME"
,
meta
.
getColumnLabel
(
4
));
Assert
.
assertEquals
(
"ts"
,
rs
.
getString
(
4
));
Assert
.
assertEquals
(
"ts"
,
rs
.
getString
(
"COLUMN_NAME"
));
// KEY_SEQ
Assert
.
assertEquals
(
"KEY_SEQ"
,
meta
.
getColumnLabel
(
5
));
Assert
.
assertEquals
(
1
,
rs
.
getShort
(
5
));
Assert
.
assertEquals
(
1
,
rs
.
getShort
(
"KEY_SEQ"
));
// DATA_TYPE
Assert
.
assertEquals
(
"PK_NAME"
,
meta
.
getColumnLabel
(
6
));
Assert
.
assertEquals
(
"ts"
,
rs
.
getString
(
6
));
Assert
.
assertEquals
(
"ts"
,
rs
.
getString
(
"PK_NAME"
));
}
Assert
.
assertNotNull
(
rs
);
}
@Test
...
...
@@ -847,14 +966,27 @@ 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"
));
System
.
out
.
println
(
"SUPERTABLE_NAME: "
+
rs
.
getString
(
"SUPERTABLE_NAME"
));
ResultSetMetaData
meta
=
rs
.
getMetaData
();
rs
.
next
();
{
// TABLE_CAT
Assert
.
assertEquals
(
"TABLE_CAT"
,
meta
.
getColumnLabel
(
1
));
Assert
.
assertEquals
(
"log"
,
rs
.
getString
(
1
));
Assert
.
assertEquals
(
"log"
,
rs
.
getString
(
"TABLE_CAT"
));
// TABLE_CAT
Assert
.
assertEquals
(
"TABLE_SCHEM"
,
meta
.
getColumnLabel
(
2
));
Assert
.
assertEquals
(
null
,
rs
.
getString
(
2
));
Assert
.
assertEquals
(
null
,
rs
.
getString
(
"TABLE_SCHEM"
));
// TABLE_CAT
Assert
.
assertEquals
(
"TABLE_NAME"
,
meta
.
getColumnLabel
(
3
));
Assert
.
assertEquals
(
"dn1"
,
rs
.
getString
(
3
));
Assert
.
assertEquals
(
"dn1"
,
rs
.
getString
(
"TABLE_NAME"
));
// TABLE_CAT
Assert
.
assertEquals
(
"SUPERTABLE_NAME"
,
meta
.
getColumnLabel
(
4
));
Assert
.
assertEquals
(
"dn"
,
rs
.
getString
(
4
));
Assert
.
assertEquals
(
"dn"
,
rs
.
getString
(
"SUPERTABLE_NAME"
));
}
Assert
.
assertNotNull
(
rs
);
}
@Test
...
...
@@ -951,15 +1083,12 @@ public class TSDBDatabaseMetaDataTest {
@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
);
connection
=
DriverManager
.
getConnection
(
url
,
properties
);
metaData
=
connection
.
getMetaData
().
unwrap
(
TSDBDatabaseMetaData
.
class
);
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java
浏览文件 @
6f6a02f8
...
...
@@ -45,9 +45,9 @@ public class TSDBJNIConnectorTest {
rowData
=
new
TSDBResultSetRowData
(
columnSize
);
// iterate resultSet
for
(
int
i
=
0
;
next
(
connector
,
pSql
);
i
++)
{
System
.
out
.
println
(
"col["
+
i
+
"] size: "
+
rowData
.
getColSize
());
rowData
.
getData
().
stream
().
forEach
(
col
->
System
.
out
.
print
(
col
+
"\t"
));
System
.
out
.
println
();
//
System.out.println("col[" + i + "] size: " + rowData.getColSize());
//
rowData.getData().stream().forEach(col -> System.out.print(col + "\t"));
//
System.out.println();
}
// close resultSet
code
=
connector
.
freeResultSet
(
pSql
);
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java
浏览文件 @
6f6a02f8
...
...
@@ -54,16 +54,17 @@ public class TSDBParameterMetaDataTest {
@Test
public
void
getPrecision
()
throws
SQLException
{
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
1
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
2
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
3
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
4
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
5
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
6
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
7
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
8
));
Assert
.
assertEquals
(
5
,
parameterMetaData_insert
.
getPrecision
(
9
));
Assert
.
assertEquals
(
5
,
parameterMetaData_insert
.
getPrecision
(
10
));
//create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64))
Assert
.
assertEquals
(
TSDBConstants
.
TIMESTAMP_MS_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
1
));
Assert
.
assertEquals
(
TSDBConstants
.
INT_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
2
));
Assert
.
assertEquals
(
TSDBConstants
.
BIGINT_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
3
));
Assert
.
assertEquals
(
TSDBConstants
.
FLOAT_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
4
));
Assert
.
assertEquals
(
TSDBConstants
.
DOUBLE_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
5
));
Assert
.
assertEquals
(
TSDBConstants
.
SMALLINT_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
6
));
Assert
.
assertEquals
(
TSDBConstants
.
TINYINT_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
7
));
Assert
.
assertEquals
(
TSDBConstants
.
BOOLEAN_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
8
));
Assert
.
assertEquals
(
"hello"
.
getBytes
().
length
,
parameterMetaData_insert
.
getPrecision
(
9
));
Assert
.
assertEquals
(
"涛思数据"
.
length
(),
parameterMetaData_insert
.
getPrecision
(
10
));
}
@Test
...
...
@@ -71,8 +72,8 @@ public class TSDBParameterMetaDataTest {
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
1
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
2
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
3
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
4
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
5
));
Assert
.
assertEquals
(
31
,
parameterMetaData_insert
.
getScale
(
4
));
Assert
.
assertEquals
(
31
,
parameterMetaData_insert
.
getScale
(
5
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
6
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
7
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
8
));
...
...
@@ -124,10 +125,16 @@ public class TSDBParameterMetaDataTest {
@Test
public
void
getParameterMode
()
throws
SQLException
{
for
(
int
i
=
1
;
i
<=
parameterMetaData_insert
.
getParameterCount
();
i
++)
{
int
parameterMode
=
parameterMetaData_insert
.
getParameterMode
(
i
);
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMode
);
}
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMetaData_insert
.
getParameterMode
(
1
));
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMetaData_insert
.
getParameterMode
(
2
));
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMetaData_insert
.
getParameterMode
(
3
));
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMetaData_insert
.
getParameterMode
(
4
));
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMetaData_insert
.
getParameterMode
(
5
));
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMetaData_insert
.
getParameterMode
(
6
));
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMetaData_insert
.
getParameterMode
(
7
));
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMetaData_insert
.
getParameterMode
(
8
));
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMetaData_insert
.
getParameterMode
(
9
));
Assert
.
assertEquals
(
ParameterMetaData
.
parameterModeUnknown
,
parameterMetaData_insert
.
getParameterMode
(
10
));
}
@Test
...
...
@@ -144,7 +151,6 @@ public class TSDBParameterMetaDataTest {
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
);
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"drop database if exists test_pstmt"
);
...
...
@@ -164,7 +170,7 @@ public class TSDBParameterMetaDataTest {
pstmt_insert
.
setObject
(
7
,
Byte
.
MAX_VALUE
);
pstmt_insert
.
setObject
(
8
,
true
);
pstmt_insert
.
setObject
(
9
,
"hello"
.
getBytes
());
pstmt_insert
.
setObject
(
10
,
"
Hello
"
);
pstmt_insert
.
setObject
(
10
,
"
涛思数据
"
);
parameterMetaData_insert
=
pstmt_insert
.
getParameterMetaData
();
pstmt_select
=
conn
.
prepareStatement
(
sql_select
);
...
...
@@ -173,7 +179,7 @@ public class TSDBParameterMetaDataTest {
pstmt_select
.
setInt
(
3
,
0
);
parameterMetaData_select
=
pstmt_select
.
getParameterMetaData
();
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java
浏览文件 @
6f6a02f8
...
...
@@ -3,7 +3,6 @@ package com.taosdata.jdbc;
import
com.google.common.primitives.Ints
;
import
com.google.common.primitives.Longs
;
import
com.google.common.primitives.Shorts
;
import
com.taosdata.jdbc.rs.RestfulResultSet
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
...
...
@@ -15,6 +14,7 @@ import java.math.BigDecimal;
import
java.sql.*
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Arrays
;
public
class
TSDBResultSetTest
{
...
...
@@ -134,7 +134,7 @@ public class TSDBResultSetTest {
Assert
.
assertEquals
(
3.1415926
,
Double
.
valueOf
(
new
String
(
f5
)),
0.000000f
);
byte
[]
f6
=
rs
.
getBytes
(
"f6"
);
Assert
.
assert
Equals
(
"abc"
,
new
String
(
f6
));
Assert
.
assert
True
(
Arrays
.
equals
(
"abc"
.
getBytes
(),
f6
));
byte
[]
f7
=
rs
.
getBytes
(
"f7"
);
Assert
.
assertEquals
((
short
)
10
,
Shorts
.
fromByteArray
(
f7
));
...
...
@@ -177,6 +177,7 @@ public class TSDBResultSetTest {
rs
.
getAsciiStream
(
"f1"
);
}
@SuppressWarnings
(
"deprecation"
)
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getUnicodeStream
()
throws
SQLException
{
rs
.
getUnicodeStream
(
"f1"
);
...
...
@@ -326,7 +327,7 @@ public class TSDBResultSetTest {
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
getRow
()
throws
SQLException
{
int
row
=
rs
.
getRow
();
rs
.
getRow
();
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
...
...
@@ -405,12 +406,12 @@ public class TSDBResultSetTest {
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateByte
()
throws
SQLException
{
rs
.
updateByte
(
1
,
new
Byte
(
"0"
)
);
rs
.
updateByte
(
1
,
(
byte
)
0
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
updateShort
()
throws
SQLException
{
rs
.
updateShort
(
1
,
new
Short
(
"0"
)
);
rs
.
updateShort
(
1
,
(
short
)
0
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
...
...
@@ -646,7 +647,6 @@ public class TSDBResultSetTest {
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
);
stmt
=
conn
.
createStatement
();
stmt
.
execute
(
"create database if not exists restful_test"
);
...
...
@@ -656,10 +656,9 @@ public class TSDBResultSetTest {
stmt
.
execute
(
"insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"
);
rs
=
stmt
.
executeQuery
(
"select * from restful_test.weather"
);
rs
.
next
();
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@AfterClass
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java
浏览文件 @
6f6a02f8
...
...
@@ -387,15 +387,12 @@ public class TSDBStatementTest {
@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"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
,
properties
);
stmt
=
conn
.
createStatement
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java
浏览文件 @
6f6a02f8
...
...
@@ -345,6 +345,7 @@ public class InsertSpecialCharacterJniTest {
}
}
@Test
public
void
testCase12
()
throws
SQLException
{
final
long
now
=
System
.
currentTimeMillis
();
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java
浏览文件 @
6f6a02f8
...
...
@@ -54,16 +54,17 @@ public class RestfulParameterMetaDataTest {
@Test
public
void
getPrecision
()
throws
SQLException
{
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
1
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
2
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
3
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
4
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
5
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
6
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
7
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getPrecision
(
8
));
Assert
.
assertEquals
(
5
,
parameterMetaData_insert
.
getPrecision
(
9
));
Assert
.
assertEquals
(
5
,
parameterMetaData_insert
.
getPrecision
(
10
));
//create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64))
Assert
.
assertEquals
(
TSDBConstants
.
TIMESTAMP_MS_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
1
));
Assert
.
assertEquals
(
TSDBConstants
.
INT_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
2
));
Assert
.
assertEquals
(
TSDBConstants
.
BIGINT_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
3
));
Assert
.
assertEquals
(
TSDBConstants
.
FLOAT_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
4
));
Assert
.
assertEquals
(
TSDBConstants
.
DOUBLE_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
5
));
Assert
.
assertEquals
(
TSDBConstants
.
SMALLINT_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
6
));
Assert
.
assertEquals
(
TSDBConstants
.
TINYINT_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
7
));
Assert
.
assertEquals
(
TSDBConstants
.
BOOLEAN_PRECISION
,
parameterMetaData_insert
.
getPrecision
(
8
));
Assert
.
assertEquals
(
"hello"
.
getBytes
().
length
,
parameterMetaData_insert
.
getPrecision
(
9
));
Assert
.
assertEquals
(
"涛思数据"
.
length
(),
parameterMetaData_insert
.
getPrecision
(
10
));
}
@Test
...
...
@@ -71,8 +72,8 @@ public class RestfulParameterMetaDataTest {
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
1
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
2
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
3
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
4
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
5
));
Assert
.
assertEquals
(
31
,
parameterMetaData_insert
.
getScale
(
4
));
Assert
.
assertEquals
(
31
,
parameterMetaData_insert
.
getScale
(
5
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
6
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
7
));
Assert
.
assertEquals
(
0
,
parameterMetaData_insert
.
getScale
(
8
));
...
...
@@ -164,7 +165,7 @@ public class RestfulParameterMetaDataTest {
pstmt_insert
.
setObject
(
7
,
Byte
.
MAX_VALUE
);
pstmt_insert
.
setObject
(
8
,
true
);
pstmt_insert
.
setObject
(
9
,
"hello"
.
getBytes
());
pstmt_insert
.
setObject
(
10
,
"
Hello
"
);
pstmt_insert
.
setObject
(
10
,
"
涛思数据
"
);
parameterMetaData_insert
=
pstmt_insert
.
getParameterMetaData
();
pstmt_select
=
conn
.
prepareStatement
(
sql_select
);
...
...
src/connector/python/taos/cinterface.py
浏览文件 @
6f6a02f8
...
...
@@ -242,7 +242,7 @@ def _load_taos_linux():
def
_load_taos_darwin
():
return
ctypes
.
c
DLL
(
'libtaos.dylib'
)
return
ctypes
.
C
DLL
(
'libtaos.dylib'
)
def
_load_taos_windows
():
...
...
src/cq/src/cqMain.c
浏览文件 @
6f6a02f8
...
...
@@ -38,21 +38,6 @@
#define cDebug(...) { if (cqDebugFlag & DEBUG_DEBUG) { taosPrintLog("CQ ", cqDebugFlag, __VA_ARGS__); }}
#define cTrace(...) { if (cqDebugFlag & DEBUG_TRACE) { taosPrintLog("CQ ", cqDebugFlag, __VA_ARGS__); }}
typedef
struct
{
int32_t
vgId
;
int32_t
master
;
int32_t
num
;
// number of continuous streams
char
user
[
TSDB_USER_LEN
];
char
pass
[
TSDB_KEY_LEN
];
char
db
[
TSDB_DB_NAME_LEN
];
FCqWrite
cqWrite
;
struct
SCqObj
*
pHead
;
void
*
dbConn
;
void
*
tmrCtrl
;
pthread_mutex_t
mutex
;
int32_t
delete
;
int32_t
cqObjNum
;
}
SCqContext
;
typedef
struct
SCqObj
{
tmr_h
tmrId
;
...
...
@@ -439,7 +424,7 @@ static void cqProcessCreateTimer(void *param, void *tmrId) {
// inner implement in tscStream.c
TAOS_STREAM
*
taos_open_stream_withname
(
TAOS
*
taos
,
const
char
*
desName
,
const
char
*
sqlstr
,
void
(
*
fp
)(
void
*
param
,
TAOS_RES
*
,
TAOS_ROW
row
),
int64_t
stime
,
void
*
param
,
void
(
*
callback
)(
void
*
));
int64_t
stime
,
void
*
param
,
void
(
*
callback
)(
void
*
)
,
void
*
cqhandle
);
static
void
cqCreateStream
(
SCqContext
*
pContext
,
SCqObj
*
pObj
)
{
pObj
->
pContext
=
pContext
;
...
...
@@ -453,7 +438,8 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) {
pObj
->
tmrId
=
0
;
if
(
pObj
->
pStream
==
NULL
)
{
pObj
->
pStream
=
taos_open_stream_withname
(
pContext
->
dbConn
,
pObj
->
dstTable
,
pObj
->
sqlStr
,
cqProcessStreamRes
,
INT64_MIN
,
(
void
*
)
pObj
->
rid
,
NULL
);
pObj
->
pStream
=
taos_open_stream_withname
(
pContext
->
dbConn
,
pObj
->
dstTable
,
pObj
->
sqlStr
,
cqProcessStreamRes
,
\
INT64_MIN
,
(
void
*
)
pObj
->
rid
,
NULL
,
pContext
);
// TODO the pObj->pStream may be released if error happens
if
(
pObj
->
pStream
)
{
...
...
src/inc/tcq.h
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
src/kit/taosdemo/taosdemo.c
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
src/os/src/detail/osTime.c
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
src/util/inc/tutil.h
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
src/util/src/tutil.c
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
tests/mas/Jenkinsfile
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
tests/pytest/cluster/clusterSetup.py
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
tests/pytest/functions/showOfflineThresholdIs864000.py
浏览文件 @
6f6a02f8
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录