Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
f1f6a572
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看板
未验证
提交
f1f6a572
编写于
4月 12, 2021
作者:
Z
zyyang
提交者:
GitHub
4月 12, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Hotfix/td 3689 (#5754)
* [TD-3689]<fix>: fix setNull exception in JDBC * change * change
上级
60e6729d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
102 addition
and
133 deletion
+102
-133
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
...rc/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
+6
-131
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
...est/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
+46
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java
...bc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java
+1
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DriverAutoloadTest.java
...test/java/com/taosdata/jdbc/cases/DriverAutoloadTest.java
+2
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java
...va/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java
+46
-1
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java
.../test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java
+1
-0
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
浏览文件 @
f1f6a572
...
...
@@ -33,17 +33,9 @@ import java.util.regex.Pattern;
public
class
TSDBPreparedStatement
extends
TSDBStatement
implements
PreparedStatement
{
private
String
rawSql
;
private
String
sql
;
// private ArrayList<Object> parameters = new ArrayList<>();
private
Object
[]
parameters
;
private
boolean
isPrepared
;
//start with insert or import and is case-insensitive
private
static
Pattern
savePattern
=
Pattern
.
compile
(
"(?i)^\\s*(insert|import)"
);
// is insert or import
private
boolean
isSaved
;
// private SavedPreparedStatement savedPreparedStatement;
private
volatile
TSDBParameterMetaData
parameterMetaData
;
TSDBPreparedStatement
(
TSDBConnection
connection
,
TSDBJNIConnector
connecter
,
String
sql
)
{
...
...
@@ -65,35 +57,11 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
private
void
init
(
String
sql
)
{
this
.
rawSql
=
sql
;
preprocessSql
();
// this.isSaved = isSavedSql(this.rawSql);
// if (this.isSaved) {
// try {
// this.savedPreparedStatement = new SavedPreparedStatement(this.rawSql, this);
// } catch (SQLException e) {
// e.printStackTrace();
// }
// }
}
/**
* if the precompiled sql is insert or import
*
* @param sql
* @return
*/
private
boolean
isSavedSql
(
String
sql
)
{
Matcher
matcher
=
savePattern
.
matcher
(
sql
);
return
matcher
.
find
();
}
@Override
public
int
[]
executeBatch
()
throws
SQLException
{
// if (isSaved) {
// return this.savedPreparedStatement.executeBatch();
// } else {
return
super
.
executeBatch
();
// }
}
/*
...
...
@@ -157,23 +125,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
*
* @return a string of the native sql statement for TSDB
*/
// private String getNativeSql(String rawSql) {
// for (int i = 0; i < parameters.length; i++) {
// Object para = parameters[i];
// if (para != null) {
// String paraStr = para.toString();
// if (para instanceof Timestamp || para instanceof String) {
// paraStr = "'" + paraStr + "'";
// }
// this.sql = this.sql.replaceFirst("[?]", paraStr);
// } else {
// this.sql = this.sql.replaceFirst("[?]", "NULL");
// }
// }
// parameters = new Object[parameters.length];
// return sql;
// }
private
String
getNativeSql
(
String
rawSql
)
throws
SQLException
{
String
sql
=
rawSql
;
for
(
int
i
=
0
;
i
<
parameters
.
length
;
++
i
)
{
...
...
@@ -201,108 +152,58 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override
public
ResultSet
executeQuery
()
throws
SQLException
{
// if (isSaved) {
// this.savedPreparedStatement.executeBatchInternal();
// return null;
// } else {
if
(!
isPrepared
)
return
executeQuery
(
this
.
rawSql
);
final
String
sql
=
getNativeSql
(
this
.
rawSql
);
return
executeQuery
(
sql
);
// }
}
@Override
public
int
executeUpdate
()
throws
SQLException
{
// if (isSaved) {
// return this.savedPreparedStatement.executeBatchInternal();
// } else {
if
(!
isPrepared
)
return
executeUpdate
(
this
.
rawSql
);
String
sql
=
getNativeSql
(
this
.
rawSql
);
return
executeUpdate
(
sql
);
// }
}
private
boolean
isSupportedSQLType
(
int
sqlType
)
{
switch
(
sqlType
)
{
case
Types
.
TIMESTAMP
:
case
Types
.
INTEGER
:
case
Types
.
BIGINT
:
case
Types
.
FLOAT
:
case
Types
.
DOUBLE
:
case
Types
.
SMALLINT
:
case
Types
.
TINYINT
:
case
Types
.
BOOLEAN
:
case
Types
.
BINARY
:
case
Types
.
NCHAR
:
return
true
;
default
:
return
false
;
}
}
@Override
public
void
setNull
(
int
parameterIndex
,
int
sqlType
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(!
isSupportedSQLType
(
sqlType
)
||
parameterIndex
<
0
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
// if (parameterIndex >= parameters.size())
// throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_BOUNDARY);
setObject
(
parameterIndex
,
"NULL"
);
setObject
(
parameterIndex
,
null
);
}
@Override
public
void
setBoolean
(
int
parameterIndex
,
boolean
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setByte
(
int
parameterIndex
,
byte
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setShort
(
int
parameterIndex
,
short
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setInt
(
int
parameterIndex
,
int
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setLong
(
int
parameterIndex
,
long
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setFloat
(
int
parameterIndex
,
float
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setDouble
(
int
parameterIndex
,
double
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
...
...
@@ -315,17 +216,12 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override
public
void
setString
(
int
parameterIndex
,
String
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setBytes
(
int
parameterIndex
,
byte
[]
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
setObject
(
parameterIndex
,
x
);
}
@Override
...
...
@@ -344,8 +240,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
@Override
public
void
setTimestamp
(
int
parameterIndex
,
Timestamp
x
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
setObject
(
parameterIndex
,
x
);
}
...
...
@@ -360,7 +254,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
public
void
setUnicodeStream
(
int
parameterIndex
,
InputStream
x
,
int
length
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
...
...
@@ -375,8 +268,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
public
void
clearParameters
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
// parameters.clear();
parameters
=
new
Object
[
parameters
.
length
];
}
...
...
@@ -384,43 +275,29 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
public
void
setObject
(
int
parameterIndex
,
Object
x
,
int
targetSqlType
)
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
setObject
(
parameterIndex
,
x
);
}
@Override
public
void
setObject
(
int
parameterIndex
,
Object
x
)
throws
SQLException
{
// if (isSaved) {
// this.savedPreparedStatement.setParam(parameterIndex, x);
// } else {
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
parameterIndex
<
1
&&
parameterIndex
>=
parameters
.
length
)
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_PARAMETER_INDEX_OUT_RANGE
);
parameters
[
parameterIndex
-
1
]
=
x
;
// parameters.add(x);
// }
}
@Override
public
boolean
execute
()
throws
SQLException
{
// if (isSaved) {
// int result = this.savedPreparedStatement.executeBatchInternal();
// return result > 0;
// } else {
if
(!
isPrepared
)
return
execute
(
this
.
rawSql
);
final
String
sql
=
getNativeSql
(
this
.
rawSql
);
return
execute
(
sql
);
// }
}
@Override
public
void
addBatch
()
throws
SQLException
{
// if (isSaved) {
// this.savedPreparedStatement.addBatch();
// } else {
if
(
this
.
batchedArgs
==
null
)
{
batchedArgs
=
new
ArrayList
<>();
}
...
...
@@ -431,7 +308,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
String
sql
=
this
.
getConnection
().
nativeSQL
(
this
.
rawSql
);
addBatch
(
sql
);
}
// }
}
@Override
...
...
@@ -475,7 +351,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
public
ResultSetMetaData
getMetaData
()
throws
SQLException
{
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
// return this.getResultSet().getMetaData();
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_METHOD
);
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
浏览文件 @
f1f6a572
...
...
@@ -50,6 +50,51 @@ public class TSDBPreparedStatementTest {
pstmt_insert
.
setNull
(
2
,
Types
.
INTEGER
);
int
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
3
,
Types
.
BIGINT
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
4
,
Types
.
FLOAT
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
5
,
Types
.
DOUBLE
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
6
,
Types
.
SMALLINT
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
7
,
Types
.
TINYINT
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
8
,
Types
.
BOOLEAN
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
9
,
Types
.
BINARY
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
10
,
Types
.
NCHAR
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
10
,
Types
.
OTHER
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
}
@Test
...
...
@@ -129,7 +174,7 @@ public class TSDBPreparedStatementTest {
Assert
.
assertFalse
(
pstmt_insert
.
execute
());
}
class
Person
implements
Serializable
{
class
Person
{
String
name
;
int
age
;
boolean
sex
;
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java
浏览文件 @
f1f6a572
...
...
@@ -160,6 +160,7 @@ public class TSDBResultSetTest {
@Test
public
void
getTime
()
throws
SQLException
{
Time
f1
=
rs
.
getTime
(
"f1"
);
Assert
.
assertNotNull
(
f1
);
Assert
.
assertEquals
(
"00:00:00"
,
f1
.
toString
());
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DriverAutoloadTest.java
浏览文件 @
f1f6a572
...
...
@@ -20,6 +20,7 @@ public class DriverAutoloadTest {
final
String
url
=
"jdbc:TAOS-RS://"
+
host
+
":6041/?user=root&password=taosdata"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
,
properties
);
Assert
.
assertNotNull
(
conn
);
conn
.
close
();
}
@Test
...
...
@@ -27,6 +28,7 @@ public class DriverAutoloadTest {
final
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
,
properties
);
Assert
.
assertNotNull
(
conn
);
conn
.
close
();
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java
浏览文件 @
f1f6a572
...
...
@@ -50,6 +50,51 @@ public class RestfulPreparedStatementTest {
pstmt_insert
.
setNull
(
2
,
Types
.
INTEGER
);
int
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
3
,
Types
.
BIGINT
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
4
,
Types
.
FLOAT
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
5
,
Types
.
DOUBLE
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
6
,
Types
.
SMALLINT
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
7
,
Types
.
TINYINT
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
8
,
Types
.
BOOLEAN
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
9
,
Types
.
BINARY
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
10
,
Types
.
NCHAR
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
pstmt_insert
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
pstmt_insert
.
setNull
(
10
,
Types
.
OTHER
);
result
=
pstmt_insert
.
executeUpdate
();
Assert
.
assertEquals
(
1
,
result
);
}
@Test
...
...
@@ -129,7 +174,7 @@ public class RestfulPreparedStatementTest {
Assert
.
assertFalse
(
pstmt_insert
.
execute
());
}
class
Person
implements
Serializable
{
private
class
Person
{
String
name
;
int
age
;
boolean
sex
;
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java
浏览文件 @
f1f6a572
...
...
@@ -160,6 +160,7 @@ public class RestfulResultSetTest {
@Test
public
void
getTime
()
throws
SQLException
{
Time
f1
=
rs
.
getTime
(
"f1"
);
Assert
.
assertNotNull
(
f1
);
Assert
.
assertEquals
(
"00:00:00"
,
f1
.
toString
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录