Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
75686a8e
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看板
提交
75686a8e
编写于
6月 09, 2020
作者:
S
Shuaiqiang Chang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: affectRows
上级
bd22f941
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
282 addition
and
10 deletion
+282
-10
src/client/src/TSDBJNIConnector.c
src/client/src/TSDBJNIConnector.c
+1
-1
src/connector/jdbc/pom.xml
src/connector/jdbc/pom.xml
+14
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+4
-9
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java
...c/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java
+96
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java
.../jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java
+77
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java
...bc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java
+90
-0
未找到文件。
src/client/src/TSDBJNIConnector.c
浏览文件 @
75686a8e
...
@@ -344,7 +344,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp(
...
@@ -344,7 +344,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp(
STscObj
*
pObj
=
pSql
->
pTscObj
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
if
(
tscIsUpdateQuery
(
pSql
))
{
if
(
tscIsUpdateQuery
(
pSql
))
{
taos_free_result
(
pSql
);
// free result here
//
taos_free_result(pSql); // free result here
jniTrace
(
"jobj:%p, conn:%p, no resultset, %p"
,
jobj
,
pObj
,
(
void
*
)
tres
);
jniTrace
(
"jobj:%p, conn:%p, no resultset, %p"
,
jobj
,
pObj
,
(
void
*
)
tres
);
return
0
;
return
0
;
}
else
{
}
else
{
...
...
src/connector/jdbc/pom.xml
浏览文件 @
75686a8e
...
@@ -62,6 +62,12 @@
...
@@ -62,6 +62,12 @@
<artifactId>
commons-lang3
</artifactId>
<artifactId>
commons-lang3
</artifactId>
<version>
${commons-lang3.version}
</version>
<version>
${commons-lang3.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.8.2
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
@@ -98,6 +104,14 @@
...
@@ -98,6 +104,14 @@
<showDeprecation>
true
</showDeprecation>
<showDeprecation>
true
</showDeprecation>
</configuration>
</configuration>
</plugin>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
2.12.4
</version>
<configuration>
<testFailureIgnore>
true
</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</plugins>
</build>
</build>
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
浏览文件 @
75686a8e
...
@@ -51,8 +51,6 @@ public class TSDBJNIConnector {
...
@@ -51,8 +51,6 @@ public class TSDBJNIConnector {
/**
/**
* Returns the status of last result set in current connection
* Returns the status of last result set in current connection
*
* @return
*/
*/
public
boolean
isResultsetClosed
()
{
public
boolean
isResultsetClosed
()
{
return
this
.
isResultsetClosed
;
return
this
.
isResultsetClosed
;
...
@@ -112,7 +110,7 @@ public class TSDBJNIConnector {
...
@@ -112,7 +110,7 @@ public class TSDBJNIConnector {
*
*
* @throws SQLException
* @throws SQLException
*/
*/
public
int
executeQuery
(
String
sql
)
throws
SQLException
{
public
long
executeQuery
(
String
sql
)
throws
SQLException
{
if
(!
this
.
isResultsetClosed
)
{
if
(!
this
.
isResultsetClosed
)
{
freeResultSet
(
taosResultSetPointer
);
freeResultSet
(
taosResultSetPointer
);
}
}
...
@@ -127,7 +125,6 @@ public class TSDBJNIConnector {
...
@@ -127,7 +125,6 @@ public class TSDBJNIConnector {
}
}
int
code
=
this
.
getErrCode
(
pSql
);
int
code
=
this
.
getErrCode
(
pSql
);
affectedRows
=
code
;
if
(
code
<
0
)
{
if
(
code
<
0
)
{
affectedRows
=
-
1
;
affectedRows
=
-
1
;
if
(
code
==
TSDBConstants
.
JNI_TDENGINE_ERROR
)
{
if
(
code
==
TSDBConstants
.
JNI_TDENGINE_ERROR
)
{
...
@@ -146,7 +143,7 @@ public class TSDBJNIConnector {
...
@@ -146,7 +143,7 @@ public class TSDBJNIConnector {
if
(
taosResultSetPointer
!=
TSDBConstants
.
JNI_NULL_POINTER
)
{
if
(
taosResultSetPointer
!=
TSDBConstants
.
JNI_NULL_POINTER
)
{
isResultsetClosed
=
false
;
isResultsetClosed
=
false
;
}
}
return
code
;
return
pSql
;
}
}
private
native
long
executeQueryImp
(
byte
[]
sqlBytes
,
long
connection
);
private
native
long
executeQueryImp
(
byte
[]
sqlBytes
,
long
connection
);
...
@@ -199,8 +196,6 @@ public class TSDBJNIConnector {
...
@@ -199,8 +196,6 @@ public class TSDBJNIConnector {
/**
/**
* Close the open result set which is associated to the current connection. If the result set is already
* Close the open result set which is associated to the current connection. If the result set is already
* closed, return 0 for success.
* closed, return 0 for success.
*
* @return
*/
*/
public
int
freeResultSet
()
{
public
int
freeResultSet
()
{
int
resCode
=
TSDBConstants
.
JNI_SUCCESS
;
int
resCode
=
TSDBConstants
.
JNI_SUCCESS
;
...
@@ -217,7 +212,7 @@ public class TSDBJNIConnector {
...
@@ -217,7 +212,7 @@ public class TSDBJNIConnector {
/**
/**
* Get affected rows count
* Get affected rows count
*/
*/
public
int
getAffectedRows
(
L
ong
pSql
)
{
public
int
getAffectedRows
(
l
ong
pSql
)
{
int
affectedRows
=
this
.
affectedRows
;
int
affectedRows
=
this
.
affectedRows
;
if
(
affectedRows
<
0
)
{
if
(
affectedRows
<
0
)
{
affectedRows
=
this
.
getAffectedRowsImp
(
this
.
taos
,
pSql
);
affectedRows
=
this
.
getAffectedRowsImp
(
this
.
taos
,
pSql
);
...
@@ -225,7 +220,7 @@ public class TSDBJNIConnector {
...
@@ -225,7 +220,7 @@ public class TSDBJNIConnector {
return
affectedRows
;
return
affectedRows
;
}
}
private
native
int
getAffectedRowsImp
(
long
connection
,
L
ong
pSql
);
private
native
int
getAffectedRowsImp
(
long
connection
,
l
ong
pSql
);
/**
/**
* Get schema metadata
* Get schema metadata
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java
0 → 100644
浏览文件 @
75686a8e
package
com.taosdata.jdbc
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
TSDBAsyncSubscribeTest
{
Connection
connection
=
null
;
Statement
statement
=
null
;
String
dbName
=
"test"
;
String
tName
=
"t0"
;
String
host
=
"localhost"
;
String
topic
=
"test"
;
long
subscribId
=
0
;
// @Before
public
void
createDatabase
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
+
"?user=root&password=taosdata"
,
properties
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"create table if not exists "
+
dbName
+
"."
+
tName
+
" (ts timestamp, k int, v int)"
);
long
ts
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
ts
+=
i
;
statement
.
executeUpdate
(
"insert into \" + dbName + \".\" + tName + \" values ("
+
ts
+
", "
+
(
100
+
i
)
+
", "
+
i
+
")"
);
}
}
// @Test
public
void
subscribe
()
throws
Exception
{
TSDBSubscribe
subscribe
=
null
;
try
{
String
rawSql
=
"select * from "
+
dbName
+
"."
+
tName
+
";"
;
System
.
out
.
println
(
rawSql
);
subscribe
=
((
TSDBConnection
)
connection
).
createSubscribe
();
subscribId
=
subscribe
.
subscribe
(
topic
,
rawSql
,
false
,
1000
,
new
CallBack
(
"first"
));
assertTrue
(
subscribId
>
0
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
Thread
.
sleep
(
2000
);
subscribe
.
unsubscribe
(
subscribId
,
true
);
}
private
static
class
CallBack
implements
TSDBSubscribeCallBack
{
private
String
name
=
""
;
public
CallBack
(
String
name
)
{
this
.
name
=
name
;
}
@Override
public
void
invoke
(
TSDBResultSet
resultSet
)
{
System
.
out
.
println
(
"resultSet"
);
try
{
while
(
null
!=
resultSet
&&
resultSet
.
next
())
{
System
.
out
.
print
(
"callback_"
+
name
+
": "
);
for
(
int
i
=
1
;
i
<=
resultSet
.
getMetaData
().
getColumnCount
();
i
++)
{
System
.
out
.
printf
(
i
+
": "
+
resultSet
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
();
}
resultSet
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
// @After
public
void
close
()
throws
Exception
{
statement
.
executeQuery
(
"drop database test"
);
statement
.
close
();
connection
.
close
();
}
}
\ No newline at end of file
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java
0 → 100644
浏览文件 @
75686a8e
package
com.taosdata.jdbc
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
TSDBImportTest
{
Connection
connection
=
null
;
Statement
statement
=
null
;
String
dbName
=
"test"
;
String
tName
=
"t0"
;
String
host
=
"localhost"
;
@Before
public
void
createDatabase
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
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, k int, v int)"
);
}
@Test
public
void
insertInto
()
throws
Exception
{
long
ts
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
50
;
i
++)
{
ts
+=
i
;
int
row
=
statement
.
executeUpdate
(
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", "
+
(
100
+
i
)
+
", "
+
i
+
")"
);
System
.
out
.
println
(
"insert into "
+
dbName
+
"."
+
tName
+
" values ("
+
ts
+
", "
+
(
100
+
i
)
+
", "
+
i
+
")"
+
"\t"
+
row
);
assertEquals
(
1
,
row
);
}
}
@Test
public
void
importInto
()
throws
Exception
{
// 避免时间重复
long
ts
=
System
.
currentTimeMillis
()
+
1000
;
StringBuilder
sqlBuilder
=
new
StringBuilder
(
"insert into "
).
append
(
dbName
).
append
(
"."
).
append
(
tName
).
append
(
" values "
);
for
(
int
i
=
0
;
i
<
50
;
i
++)
{
int
a
=
i
/
5
;
long
t
=
ts
+
a
;
sqlBuilder
.
append
(
"("
).
append
(
t
).
append
(
","
).
append
((
100
+
i
)).
append
(
","
).
append
(
i
).
append
(
") "
);
}
System
.
out
.
println
(
sqlBuilder
.
toString
());
int
rows
=
statement
.
executeUpdate
(
sqlBuilder
.
toString
());
System
.
out
.
println
(
rows
);
assertEquals
(
10
,
rows
);
}
@After
public
void
close
()
throws
Exception
{
statement
.
executeQuery
(
"drop database "
+
dbName
);
statement
.
close
();
connection
.
close
();
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java
0 → 100644
浏览文件 @
75686a8e
package
com.taosdata.jdbc
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
TSDBSubscribeTest
{
Connection
connection
=
null
;
Statement
statement
=
null
;
String
dbName
=
"test"
;
String
tName
=
"t0"
;
String
host
=
"localhost"
;
String
topic
=
"test"
;
// @Before
public
void
createDatabase
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
+
"?user=root&password=taosdata"
,
properties
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeUpdate
(
"create table if not exists "
+
dbName
+
"."
+
tName
+
" (ts timestamp, k int, v int)"
);
long
ts
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
ts
+=
i
;
statement
.
executeUpdate
(
"insert into \" + dbName + \".\" + tName + \" values ("
+
ts
+
", "
+
(
100
+
i
)
+
", "
+
i
+
")"
);
}
}
// @Test
public
void
subscribe
()
throws
Exception
{
TSDBSubscribe
subscribe
=
null
;
long
subscribId
=
0
;
try
{
String
rawSql
=
"select * from "
+
dbName
+
"."
+
tName
+
";"
;
System
.
out
.
println
(
rawSql
);
subscribe
=
((
TSDBConnection
)
connection
).
createSubscribe
();
subscribId
=
subscribe
.
subscribe
(
topic
,
rawSql
,
false
,
1000
);
assertTrue
(
subscribId
>
0
);
int
a
=
0
;
while
(
true
)
{
Thread
.
sleep
(
900
);
TSDBResultSet
resSet
=
subscribe
.
consume
(
subscribId
);
while
(
resSet
.
next
())
{
for
(
int
i
=
1
;
i
<=
resSet
.
getMetaData
().
getColumnCount
();
i
++)
{
System
.
out
.
printf
(
i
+
": "
+
resSet
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
(
"\n======"
+
a
+
"=========="
);
}
resSet
.
close
();
a
++;
if
(
a
>=
3
)
{
break
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
null
!=
subscribe
&&
0
!=
subscribId
)
{
subscribe
.
unsubscribe
(
subscribId
,
true
);
}
}
}
// @After
public
void
close
()
throws
Exception
{
statement
.
executeQuery
(
"drop database "
+
dbName
);
statement
.
close
();
connection
.
close
();
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录