Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
a8133047
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看板
提交
a8133047
编写于
2月 24, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add TSDBPreparedStatement test cases
上级
d7dfde2d
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
317 addition
and
107 deletion
+317
-107
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
...ector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
+1
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
+2
-0
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
...rc/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
+203
-48
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
...est/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
+111
-59
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
浏览文件 @
a8133047
...
@@ -22,6 +22,7 @@ public class TSDBError {
...
@@ -22,6 +22,7 @@ public class TSDBError {
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
,
"Database not specified or available"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
,
"Database not specified or available"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE_UPDATE
,
"not a valid sql for executeUpdate: (?)"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE_UPDATE
,
"not a valid sql for executeUpdate: (?)"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE
,
"not a valid sql for execute: (?)"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_INVALID_FOR_EXECUTE
,
"not a valid sql for execute: (?)"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_PARAMETER_INDEX_OUT_BOUNDARY
,
"parameter index out of range"
);
/**************************************************/
/**************************************************/
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"unknown error"
);
TSDBErrorMap
.
put
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"unknown error"
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
浏览文件 @
a8133047
...
@@ -16,6 +16,7 @@ public class TSDBErrorNumbers {
...
@@ -16,6 +16,7 @@ public class TSDBErrorNumbers {
public
static
final
int
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
=
0x2310
;
//Database not specified or available
public
static
final
int
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
=
0x2310
;
//Database not specified or available
public
static
final
int
ERROR_INVALID_FOR_EXECUTE_UPDATE
=
0x2311
;
//not a valid sql for executeUpdate: (SQL)
public
static
final
int
ERROR_INVALID_FOR_EXECUTE_UPDATE
=
0x2311
;
//not a valid sql for executeUpdate: (SQL)
public
static
final
int
ERROR_INVALID_FOR_EXECUTE
=
0x2312
;
//not a valid sql for execute: (SQL)
public
static
final
int
ERROR_INVALID_FOR_EXECUTE
=
0x2312
;
//not a valid sql for execute: (SQL)
public
static
final
int
ERROR_PARAMETER_INDEX_OUT_BOUNDARY
=
0x2313
;
// parameter index out of range
public
static
final
int
ERROR_UNKNOWN
=
0x2350
;
//unknown error
public
static
final
int
ERROR_UNKNOWN
=
0x2350
;
//unknown error
...
@@ -45,6 +46,7 @@ public class TSDBErrorNumbers {
...
@@ -45,6 +46,7 @@ public class TSDBErrorNumbers {
errorNumbers
.
add
(
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
);
errorNumbers
.
add
(
ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE
);
errorNumbers
.
add
(
ERROR_INVALID_FOR_EXECUTE_UPDATE
);
errorNumbers
.
add
(
ERROR_INVALID_FOR_EXECUTE_UPDATE
);
errorNumbers
.
add
(
ERROR_INVALID_FOR_EXECUTE
);
errorNumbers
.
add
(
ERROR_INVALID_FOR_EXECUTE
);
errorNumbers
.
add
(
ERROR_PARAMETER_INDEX_OUT_BOUNDARY
);
/*****************************************************/
/*****************************************************/
errorNumbers
.
add
(
ERROR_SUBSCRIBE_FAILED
);
errorNumbers
.
add
(
ERROR_SUBSCRIBE_FAILED
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
浏览文件 @
a8133047
此差异已折叠。
点击以展开。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
浏览文件 @
a8133047
package
com.taosdata.jdbc
;
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.AfterClass
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.*
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
public
class
TSDBPreparedStatementTest
{
public
class
TSDBPreparedStatementTest
{
private
static
final
String
host
=
"127.0.0.1"
;
private
static
final
String
host
=
"127.0.0.1"
;
private
static
Connection
conn
;
private
static
Connection
conn
;
private
static
final
String
sql_insert
=
"insert into t1 values(?, ?)"
;
@Test
private
static
PreparedStatement
pstmt_insert
;
public
void
executeQuery
()
{
private
static
final
String
sql_select
=
"select * from t1 where ts > ? and ts <= ? and temperature >= ?"
;
private
static
PreparedStatement
pstmt_select
;
@Test
public
void
executeQuery
()
throws
SQLException
{
pstmt_select
.
setString
(
1
,
"now - 1h"
);
pstmt_select
.
setString
(
2
,
"now"
);
pstmt_select
.
setFloat
(
3
,
0
);
ResultSet
rs
=
pstmt_select
.
executeQuery
();
Assert
.
assertNotNull
(
rs
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
System
.
out
.
print
(
meta
.
getColumnLabel
(
i
)
+
": "
+
rs
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
();
}
}
}
@Test
@Test
public
void
executeUpdate
()
{
public
void
executeUpdate
()
throws
SQLException
{
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setFloat
(
2
,
3.14f
);
int
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
}
}
@Test
@Test
public
void
setNull
()
{
public
void
setNull
()
throws
SQLException
{
pstmt_insert
.
setNull
(
2
,
Types
.
FLOAT
);
}
}
@Test
@Test
public
void
setBoolean
()
{
public
void
setBoolean
()
throws
SQLException
{
pstmt_insert
.
setBoolean
(
2
,
true
);
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setByte
()
{
public
void
setByte
()
throws
SQLException
{
pstmt_insert
.
setByte
(
1
,
(
byte
)
0x001
);
}
}
@Test
@Test
...
@@ -54,120 +75,150 @@ public class TSDBPreparedStatementTest {
...
@@ -54,120 +75,150 @@ public class TSDBPreparedStatementTest {
public
void
setDouble
()
{
public
void
setDouble
()
{
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBigDecimal
()
{
public
void
setBigDecimal
()
throws
SQLException
{
pstmt_insert
.
setBigDecimal
(
1
,
null
);
}
}
@Test
@Test
public
void
setString
()
{
public
void
setString
()
{
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBytes
()
{
public
void
setBytes
()
throws
SQLException
{
pstmt_insert
.
setBytes
(
1
,
new
byte
[]{});
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setDate
()
{
public
void
setDate
()
throws
SQLException
{
pstmt_insert
.
setDate
(
1
,
new
Date
(
System
.
currentTimeMillis
()));
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setTime
()
{
public
void
setTime
()
throws
SQLException
{
pstmt_insert
.
setTime
(
1
,
new
Time
(
System
.
currentTimeMillis
()));
}
}
@Test
@Test
public
void
setTimestamp
()
{
public
void
setTimestamp
()
{
//TODO
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setAsciiStream
()
{
public
void
setAsciiStream
()
throws
SQLException
{
}
pstmt_insert
.
setAsciiStream
(
1
,
null
);
@Test
public
void
setUnicodeStream
()
{
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBinaryStream
()
{
public
void
setBinaryStream
()
throws
SQLException
{
pstmt_insert
.
setBinaryStream
(
1
,
null
);
}
}
@Test
@Test
public
void
clearParameters
()
{
public
void
clearParameters
()
{
//TODO
}
}
@Test
@Test
public
void
setObject
()
{
public
void
setObject
()
throws
SQLException
{
pstmt_insert
.
setObject
(
1
,
System
.
currentTimeMillis
());
//TODO
}
}
@Test
@Test
public
void
execute
()
{
public
void
execute
()
{
//TODO
}
}
@Test
@Test
public
void
addBatch
()
{
public
void
addBatch
()
{
//TODO:
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setCharacterStream
()
{
public
void
setCharacterStream
()
throws
SQLException
{
pstmt_insert
.
setCharacterStream
(
1
,
null
);
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setRef
()
{
public
void
setRef
()
throws
SQLException
{
pstmt_insert
.
setRef
(
1
,
null
);
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setBlob
()
{
public
void
setBlob
()
throws
SQLException
{
pstmt_insert
.
setBlob
(
1
,
(
Blob
)
null
);
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setClob
()
{
public
void
setClob
()
throws
SQLException
{
pstmt_insert
.
setClob
(
1
,
(
Clob
)
null
);
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setArray
()
{
public
void
setArray
()
throws
SQLException
{
pstmt_insert
.
setArray
(
1
,
null
);
}
}
@Test
@Test
public
void
getMetaData
()
{
public
void
getMetaData
()
throws
SQLException
{
ResultSetMetaData
metaData
=
pstmt_insert
.
getMetaData
();
Assert
.
assertNotNull
(
metaData
);
//TODO
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setURL
()
{
public
void
setURL
()
throws
SQLException
{
pstmt_insert
.
setURL
(
1
,
null
);
}
}
@Test
@Test
public
void
getParameterMetaData
()
{
public
void
getParameterMetaData
()
throws
SQLException
{
ParameterMetaData
parameterMetaData
=
pstmt_insert
.
getParameterMetaData
();
Assert
.
assertNotNull
(
parameterMetaData
);
//TODO:
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setRowId
()
{
public
void
setRowId
()
throws
SQLException
{
pstmt_insert
.
setRowId
(
1
,
null
);
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNString
()
{
public
void
setNString
()
throws
SQLException
{
pstmt_insert
.
setNString
(
1
,
null
);
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNCharacterStream
()
{
public
void
setNCharacterStream
()
throws
SQLException
{
pstmt_insert
.
setNCharacterStream
(
1
,
null
);
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setNClob
()
{
public
void
setNClob
()
throws
SQLException
{
pstmt_insert
.
setNClob
(
1
,
(
NClob
)
null
);
}
}
@Test
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
setSQLXML
()
{
public
void
setSQLXML
()
throws
SQLException
{
pstmt_insert
.
setSQLXML
(
1
,
null
);
}
}
@BeforeClass
@BeforeClass
public
static
void
beforeClass
()
{
public
static
void
beforeClass
()
{
try
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.
rs.Restful
Driver"
);
Class
.
forName
(
"com.taosdata.jdbc.
TSDB
Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
);
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"drop database if exists test_pstmt"
);
stmt
.
execute
(
"create database if not exists test_pstmt"
);
stmt
.
execute
(
"use test_pstmt"
);
stmt
.
execute
(
"create table weather(ts timestamp, temperature float) tags(loc nchar(64))"
);
stmt
.
execute
(
"create table t1 using weather tags('beijing')"
);
}
pstmt_insert
=
conn
.
prepareStatement
(
sql_insert
);
pstmt_select
=
conn
.
prepareStatement
(
sql_select
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -176,6 +227,7 @@ public class TSDBPreparedStatementTest {
...
@@ -176,6 +227,7 @@ public class TSDBPreparedStatementTest {
@AfterClass
@AfterClass
public
static
void
afterClass
()
{
public
static
void
afterClass
()
{
try
{
try
{
if
(
conn
!=
null
)
if
(
conn
!=
null
)
conn
.
close
();
conn
.
close
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录