Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d963ef7f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d963ef7f
编写于
11月 30, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TS-601]<fix>: no invalid database error in jdbc-restful with wrong db
上级
eafe0f62
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
8 deletion
+15
-8
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
.../src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
+9
-7
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java
...ava/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java
+6
-1
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java
浏览文件 @
d963ef7f
...
...
@@ -65,7 +65,11 @@ public class RestfulStatement extends AbstractStatement {
boolean
result
=
true
;
if
(
SqlSyntaxValidator
.
isUseSql
(
sql
))
{
HttpClientPoolUtil
.
execute
(
getUrl
(),
sql
,
this
.
conn
.
getToken
());
String
ret
=
HttpClientPoolUtil
.
execute
(
getUrl
(),
sql
,
this
.
conn
.
getToken
());
JSONObject
resultJson
=
JSON
.
parseObject
(
ret
);
if
(
resultJson
.
getString
(
"status"
).
equals
(
"error"
))
{
throw
TSDBError
.
createSQLException
(
resultJson
.
getInteger
(
"code"
),
"sql: "
+
sql
+
", desc: "
+
resultJson
.
getString
(
"desc"
));
}
this
.
database
=
sql
.
trim
().
replace
(
"use"
,
""
).
trim
();
this
.
conn
.
setCatalog
(
this
.
database
);
result
=
false
;
...
...
@@ -114,7 +118,7 @@ public class RestfulStatement extends AbstractStatement {
String
result
=
HttpClientPoolUtil
.
execute
(
getUrl
(),
sql
,
this
.
conn
.
getToken
());
JSONObject
resultJson
=
JSON
.
parseObject
(
result
);
if
(
resultJson
.
getString
(
"status"
).
equals
(
"error"
))
{
throw
TSDBError
.
createSQLException
(
resultJson
.
getInteger
(
"code"
),
resultJson
.
getString
(
"desc"
));
throw
TSDBError
.
createSQLException
(
resultJson
.
getInteger
(
"code"
),
"sql: "
+
sql
+
", desc: "
+
resultJson
.
getString
(
"desc"
));
}
this
.
resultSet
=
new
RestfulResultSet
(
database
,
this
,
resultJson
);
this
.
affectedRows
=
-
1
;
...
...
@@ -125,7 +129,7 @@ public class RestfulStatement extends AbstractStatement {
String
result
=
HttpClientPoolUtil
.
execute
(
getUrl
(),
sql
,
this
.
conn
.
getToken
());
JSONObject
jsonObject
=
JSON
.
parseObject
(
result
);
if
(
jsonObject
.
getString
(
"status"
).
equals
(
"error"
))
{
throw
TSDBError
.
createSQLException
(
jsonObject
.
getInteger
(
"code"
),
jsonObject
.
getString
(
"desc"
));
throw
TSDBError
.
createSQLException
(
jsonObject
.
getInteger
(
"code"
),
"sql: "
+
sql
+
", desc: "
+
jsonObject
.
getString
(
"desc"
));
}
this
.
resultSet
=
null
;
this
.
affectedRows
=
getAffectedRows
(
jsonObject
);
...
...
@@ -133,16 +137,14 @@ public class RestfulStatement extends AbstractStatement {
}
private
int
getAffectedRows
(
JSONObject
jsonObject
)
throws
SQLException
{
// create ... SQLs should return 0 , and Restful result like this:
// {"status": "succ", "head": ["affected_rows"], "data": [[0]], "rows": 1}
JSONArray
head
=
jsonObject
.
getJSONArray
(
"head"
);
if
(
head
.
size
()
!=
1
||
!
"affected_rows"
.
equals
(
head
.
getString
(
0
)))
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
,
"invalid variable: ["
+
head
.
toJSONString
()
+
"]"
);
JSONArray
data
=
jsonObject
.
getJSONArray
(
"data"
);
if
(
data
!=
null
)
{
return
data
.
getJSONArray
(
0
).
getInteger
(
0
);
}
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_VARIABLE
,
"invalid variable: ["
+
jsonObject
.
toJSONString
()
+
"]"
);
}
@Override
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java
浏览文件 @
d963ef7f
...
...
@@ -8,8 +8,13 @@ import java.sql.SQLException;
public
class
ConnectWrongDatabaseTest
{
@Test
(
expected
=
SQLException
.
class
)
public
void
connect
()
throws
SQLException
{
public
void
connect
ByJni
()
throws
SQLException
{
DriverManager
.
getConnection
(
"jdbc:TAOS://localhost:6030/wrong_db?user=root&password=taosdata"
);
}
@Test
(
expected
=
SQLException
.
class
)
public
void
connectByRestful
()
throws
SQLException
{
DriverManager
.
getConnection
(
"jdbc:TAOS-RS://localhost:6041/wrong_db?user=root&password=taosdata"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录