Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
35c92cc8
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
35c92cc8
编写于
6月 11, 2020
作者:
S
Shuaiqiang Chang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tests: add test
上级
029fb026
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
314 addition
and
24 deletion
+314
-24
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
+12
-10
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java
.../jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java
+13
-11
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java
+129
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java
...ctor/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java
+2
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java
+155
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
+3
-3
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
浏览文件 @
35c92cc8
...
...
@@ -51,17 +51,16 @@ public class TSDBStatement implements Statement {
if
(
isClosed
)
{
throw
new
SQLException
(
"Invalid method call on a closed statement."
);
}
System
.
out
.
println
(
sql
);
long
res
=
this
.
connecter
.
executeQuery
(
sql
);
pSql
=
this
.
connecter
.
executeQuery
(
sql
);
long
resultSetPointer
=
this
.
connecter
.
getResultSet
();
if
(
resultSetPointer
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
this
.
connecter
.
freeResultSet
(
res
);
this
.
connecter
.
freeResultSet
(
pSql
);
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
}
else
if
(
resultSetPointer
==
TSDBConstants
.
JNI_NULL_POINTER
)
{
// create/insert/update/del/alter
this
.
connecter
.
freeResultSet
(
res
);
this
.
connecter
.
freeResultSet
(
pSql
);
return
null
;
}
else
{
return
new
TSDBResultSet
(
this
.
connecter
,
resultSetPointer
);
...
...
@@ -72,18 +71,18 @@ public class TSDBStatement implements Statement {
if
(
isClosed
)
{
throw
new
SQLException
(
"Invalid method call on a closed statement."
);
}
long
res
=
this
.
connecter
.
executeQuery
(
sql
);
pSql
=
this
.
connecter
.
executeQuery
(
sql
);
long
resultSetPointer
=
this
.
connecter
.
getResultSet
();
if
(
resultSetPointer
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
this
.
connecter
.
freeResultSet
(
res
);
this
.
connecter
.
freeResultSet
(
pSql
);
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
}
else
if
(
resultSetPointer
!=
TSDBConstants
.
JNI_NULL_POINTER
)
{
this
.
connecter
.
freeResultSet
();
throw
new
SQLException
(
"The executed SQL is not a DML or a DDL"
);
}
else
{
int
num
=
this
.
connecter
.
getAffectedRows
(
res
);
this
.
connecter
.
freeResultSet
(
res
);
int
num
=
this
.
connecter
.
getAffectedRows
(
pSql
);
this
.
connecter
.
freeResultSet
(
pSql
);
return
num
;
}
}
...
...
@@ -151,16 +150,19 @@ public class TSDBStatement implements Statement {
throw
new
SQLException
(
"Invalid method call on a closed statement."
);
}
boolean
res
=
true
;
this
.
connecter
.
executeQuery
(
sql
);
pSql
=
this
.
connecter
.
executeQuery
(
sql
);
long
resultSetPointer
=
this
.
connecter
.
getResultSet
();
if
(
resultSetPointer
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
this
.
connecter
.
freeResultSet
(
pSql
);
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
}
else
if
(
resultSetPointer
==
TSDBConstants
.
JNI_NULL_POINTER
)
{
// no result set is retrieved
res
=
false
;
}
return
res
;
this
.
connecter
.
freeResultSet
(
pSql
);
return
res
;
}
public
ResultSet
getResultSet
()
throws
SQLException
{
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java
浏览文件 @
35c92cc8
...
...
@@ -18,7 +18,7 @@ public class ConnectionTest {
static
String
host
=
"localhost"
;
@Test
public
static
void
create
Connection
()
throws
SQLException
{
public
void
test
Connection
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
...
...
@@ -30,23 +30,25 @@ public class ConnectionTest {
,
properties
);
assertTrue
(
null
!=
connection
);
}
statement
=
connection
.
createStatement
();
assertTrue
(
null
!=
statement
);
// try reconnect
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
+
"?user=root&password=taosdata"
,
properties
);
@Test
public
void
createDatabase
()
{
try
{
statement
.
execute
Update
(
"create database if not exists "
+
dbName
);
statement
.
execute
(
"create database if not exists "
+
dbName
);
}
catch
(
SQLException
e
)
{
assert
false
:
"create database error: "
+
e
.
getMessage
();
}
}
@Test
public
void
close
()
{
try
{
if
(!
statement
.
isClosed
())
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
statement
.
close
();
if
(!
connection
.
isClosed
())
{
if
(!
statement
.
isClosed
())
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
statement
.
close
();
}
connection
.
close
();
}
}
catch
(
SQLException
e
)
{
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java
0 → 100644
浏览文件 @
35c92cc8
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.sql.*
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
ResultSetTest
{
static
Connection
connection
=
null
;
static
Statement
statement
=
null
;
static
String
dbName
=
"test"
;
static
String
tName
=
"t0"
;
static
String
host
=
"localhost"
;
static
ResultSet
resSet
=
null
;
@BeforeClass
public
static
void
createDatabaseAndTable
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
+
"?user=root&password=taosdata"
,
properties
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"create table if not exists "
+
dbName
+
"."
+
tName
+
" (ts timestamp, k1 int, k2 bigint, k3 float, k4 double, k5 binary(30), k6 smallint, k7 bool, k8 nchar(20))"
);
statement
.
executeQuery
(
"use "
+
dbName
);
}
@Test
public
void
testResultSet
()
{
String
sql
=
null
;
long
ts
=
1496732686000
l
;
int
v1
=
2147483600
;
long
v2
=
ts
+
1000
;
float
v3
=
3.1415926f
;
double
v4
=
3.1415926535897
;
String
v5
=
"涛思数据,强~!"
;
short
v6
=
12
;
boolean
v7
=
false
;
String
v8
=
"TDengine is powerful"
;
sql
=
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
","
+
v1
+
","
+
v2
+
","
+
v3
+
","
+
v4
+
",\""
+
v5
+
"\","
+
v6
+
","
+
v7
+
",\""
+
v8
+
"\")"
;
// System.out.println(sql);
try
{
statement
.
executeUpdate
(
sql
);
assertEquals
(
1
,
statement
.
getUpdateCount
());
}
catch
(
SQLException
e
)
{
assert
false
:
"insert error "
+
e
.
getMessage
();
}
try
{
statement
.
executeQuery
(
"select * from "
+
dbName
+
"."
+
tName
);
resSet
=
statement
.
getResultSet
();
System
.
out
.
println
(((
TSDBResultSet
)
resSet
).
getRowData
());
while
(
resSet
.
next
())
{
assertEquals
(
ts
,
resSet
.
getLong
(
1
));
assertEquals
(
ts
,
resSet
.
getLong
(
"ts"
));
System
.
out
.
println
(
resSet
.
getTimestamp
(
1
));
assertEquals
(
v1
,
resSet
.
getInt
(
2
));
assertEquals
(
v1
,
resSet
.
getInt
(
"k1"
));
assertEquals
(
v2
,
resSet
.
getLong
(
3
));
assertEquals
(
v2
,
resSet
.
getLong
(
"k2"
));
assertEquals
(
v3
,
resSet
.
getFloat
(
4
),
7
);
assertEquals
(
v3
,
resSet
.
getFloat
(
"k3"
),
7
);
assertEquals
(
v4
,
resSet
.
getDouble
(
5
),
13
);
assertEquals
(
v4
,
resSet
.
getDouble
(
"k4"
),
13
);
assertEquals
(
v5
,
resSet
.
getString
(
6
));
assertEquals
(
v5
,
resSet
.
getString
(
"k5"
));
assertEquals
(
v6
,
resSet
.
getShort
(
7
));
assertEquals
(
v6
,
resSet
.
getShort
(
"k6"
));
assertEquals
(
v7
,
resSet
.
getBoolean
(
8
));
assertEquals
(
v7
,
resSet
.
getBoolean
(
"k7"
));
assertEquals
(
v8
,
resSet
.
getString
(
9
));
assertEquals
(
v8
,
resSet
.
getString
(
"k8"
));
resSet
.
getBytes
(
9
);
resSet
.
getObject
(
6
);
resSet
.
getObject
(
"k8"
);
}
resSet
.
close
();
}
catch
(
SQLException
e
)
{
assert
false
:
"insert error "
+
e
.
getMessage
();
}
}
@Test
public
void
testBatch
()
throws
SQLException
{
String
[]
sqls
=
new
String
[]{
"insert into test.t0 values (1496732686001,2147483600,1496732687000,3.1415925,3.1415926\n"
+
"535897,\"涛思数据,强~!\",12,12,\"TDengine is powerful\")"
,
"insert into test.t0 values (1496732686002,2147483600,1496732687000,3.1415925,3.1415926\n"
+
"535897,\"涛思数据,强~!\",12,12,\"TDengine is powerful\")"
};
for
(
String
sql
:
sqls
)
{
statement
.
addBatch
(
sql
);
}
int
[]
res
=
statement
.
executeBatch
();
assertEquals
(
res
.
length
,
2
);
statement
.
clearBatch
();
}
@AfterClass
public
static
void
close
()
throws
SQLException
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
statement
.
close
();
connection
.
close
();
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java
浏览文件 @
35c92cc8
package
com.taosdata.jdbc
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -57,6 +58,7 @@ public class SelectTest {
assertEquals
(
num
,
50
);
}
@After
public
void
close
()
throws
SQLException
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
statement
.
close
();
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java
0 → 100644
浏览文件 @
35c92cc8
package
com.taosdata.jdbc
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.sql.*
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
StatementTest
{
static
Connection
connection
=
null
;
static
Statement
statement
=
null
;
static
String
dbName
=
"test"
;
static
String
tName
=
"t0"
;
static
String
host
=
"localhost"
;
static
ResultSet
resSet
=
null
;
@BeforeClass
public
static
void
createConnection
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
+
"?user=root&password=taosdata"
,
properties
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"drop database if exists "
+
dbName
);
}
@Test
public
void
createTableAndQuery
()
throws
SQLException
{
long
ts
=
System
.
currentTimeMillis
();
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"create table if not exists "
+
dbName
+
"."
+
tName
+
"(ts timestamp, k1 int)"
);
statement
.
executeUpdate
(
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", 1)"
);
statement
.
executeQuery
(
"select * from "
+
dbName
+
"."
+
tName
);
ResultSet
resultSet
=
statement
.
getResultSet
();
assertTrue
(
null
!=
resultSet
);
}
@Test
public
void
testUnsupport
()
{
// if(null == resSet) {
// return;
// }
TSDBStatement
tsdbStatement
=
(
TSDBStatement
)
statement
;
try
{
tsdbStatement
.
unwrap
(
null
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
isWrapperFor
(
null
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getMaxFieldSize
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
setMaxFieldSize
(
0
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
setEscapeProcessing
(
true
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
cancel
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getWarnings
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
clearWarnings
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
setCursorName
(
null
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getMoreResults
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
setFetchDirection
(
0
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getFetchDirection
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getResultSetConcurrency
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getResultSetType
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getConnection
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getMoreResults
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getGeneratedKeys
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
executeUpdate
(
null
,
0
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
executeUpdate
(
null
,
new
int
[]{
0
});
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
executeUpdate
(
null
,
new
String
[]{
"str1"
,
"str2"
});
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
getResultSetHoldability
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
setPoolable
(
true
);
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
isPoolable
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
closeOnCompletion
();
}
catch
(
SQLException
e
)
{
}
try
{
tsdbStatement
.
isCloseOnCompletion
();
}
catch
(
SQLException
e
)
{
}
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
浏览文件 @
35c92cc8
...
...
@@ -20,7 +20,7 @@ public class SubscribeTest {
String
host
=
"localhost"
;
String
topic
=
"test"
;
@Before
//
@Before
public
void
createDatabase
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
...
...
@@ -42,7 +42,7 @@ public class SubscribeTest {
}
}
@Test
//
@Test
public
void
subscribe
()
throws
Exception
{
TSDBSubscribe
subscribe
=
null
;
long
subscribId
=
0
;
...
...
@@ -81,7 +81,7 @@ public class SubscribeTest {
}
}
@After
//
@After
public
void
close
()
throws
Exception
{
statement
.
executeQuery
(
"drop database "
+
dbName
);
statement
.
close
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录