Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
afb2cd5e
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
afb2cd5e
编写于
10月 29, 2021
作者:
Z
Zhiyu Yang
提交者:
GitHub
10月 29, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TS-522]<fix>: fix JDBC-RESTful didn't change wasNull after getString (#8470)
上级
472cf28a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
146 addition
and
62 deletion
+146
-62
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
+25
-25
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
.../src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
+25
-35
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java
.../test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java
+1
-2
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/WasNullTest.java
.../jdbc/src/test/java/com/taosdata/jdbc/rs/WasNullTest.java
+95
-0
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
浏览文件 @
afb2cd5e
...
...
@@ -19,6 +19,7 @@ import com.google.common.primitives.Longs;
import
com.google.common.primitives.Shorts
;
import
java.math.BigDecimal
;
import
java.nio.charset.StandardCharsets
;
import
java.sql.*
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
...
...
@@ -256,7 +257,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
public
byte
[]
getBytes
(
int
columnIndex
)
throws
SQLException
{
checkAvailability
(
columnIndex
,
this
.
columnMetaDataList
.
size
());
if
(
this
.
getBatchFetch
())
return
this
.
blockData
.
getString
(
columnIndex
).
getBytes
();
Object
value
=
this
.
rowData
.
getObject
(
columnIndex
);
this
.
lastWasNull
=
value
==
null
;
if
(
value
==
null
)
return
null
;
...
...
@@ -331,25 +336,26 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
return
new
BigDecimal
(
this
.
blockData
.
getLong
(
columnIndex
-
1
));
this
.
lastWasNull
=
this
.
rowData
.
wasNull
(
columnIndex
);
BigDecimal
res
=
null
;
if
(!
lastWasNull
)
{
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
switch
(
nativeType
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_TINYINT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_SMALLINT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_INT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
:
res
=
new
BigDecimal
(
Long
.
parseLong
(
this
.
rowData
.
getObject
(
columnIndex
).
toString
()));
break
;
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_DOUBLE
:
res
=
BigDecimal
.
valueOf
(
Double
.
parseDouble
(
this
.
rowData
.
getObject
(
columnIndex
).
toString
()));
break
;
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
return
new
BigDecimal
(((
Timestamp
)
this
.
rowData
.
getObject
(
columnIndex
)).
getTime
());
default
:
res
=
new
BigDecimal
(
this
.
rowData
.
getObject
(
columnIndex
).
toString
());
}
if
(
lastWasNull
)
return
null
;
BigDecimal
res
;
int
nativeType
=
this
.
columnMetaDataList
.
get
(
columnIndex
-
1
).
getColType
();
switch
(
nativeType
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_TINYINT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_SMALLINT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_INT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
:
res
=
new
BigDecimal
(
Long
.
parseLong
(
this
.
rowData
.
getObject
(
columnIndex
).
toString
()));
break
;
case
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
:
case
TSDBConstants
.
TSDB_DATA_TYPE_DOUBLE
:
res
=
BigDecimal
.
valueOf
(
Double
.
parseDouble
(
this
.
rowData
.
getObject
(
columnIndex
).
toString
()));
break
;
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
return
new
BigDecimal
(((
Timestamp
)
this
.
rowData
.
getObject
(
columnIndex
)).
getTime
());
default
:
res
=
new
BigDecimal
(
this
.
rowData
.
getObject
(
columnIndex
).
toString
());
}
return
res
;
}
...
...
@@ -465,12 +471,6 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet {
public
boolean
isClosed
()
throws
SQLException
{
return
isClosed
;
// if (isClosed)
// return true;
// if (jniConnector != null) {
// isClosed = jniConnector.isResultsetClosed();
// }
// return isClosed;
}
public
String
getNString
(
int
columnIndex
)
throws
SQLException
{
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
浏览文件 @
afb2cd5e
...
...
@@ -255,11 +255,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
if
(
value
==
null
)
{
wasNull
=
true
;
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
null
;
}
wasNull
=
false
;
if
(
value
instanceof
byte
[])
return
new
String
((
byte
[])
value
);
return
value
.
toString
();
...
...
@@ -270,11 +268,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
if
(
value
==
null
)
{
wasNull
=
true
;
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
false
;
}
wasNull
=
false
;
if
(
value
instanceof
Boolean
)
return
(
boolean
)
value
;
return
Boolean
.
parseBoolean
(
value
.
toString
());
...
...
@@ -285,11 +281,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
if
(
value
==
null
)
{
wasNull
=
true
;
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
0
;
}
wasNull
=
false
;
long
valueAsLong
=
Long
.
parseLong
(
value
.
toString
());
if
(
valueAsLong
==
Byte
.
MIN_VALUE
)
return
0
;
...
...
@@ -309,11 +303,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
if
(
value
==
null
)
{
wasNull
=
true
;
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
0
;
}
wasNull
=
false
;
long
valueAsLong
=
Long
.
parseLong
(
value
.
toString
());
if
(
valueAsLong
==
Short
.
MIN_VALUE
)
return
0
;
...
...
@@ -327,11 +319,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
if
(
value
==
null
)
{
wasNull
=
true
;
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
0
;
}
wasNull
=
false
;
long
valueAsLong
=
Long
.
parseLong
(
value
.
toString
());
if
(
valueAsLong
==
Integer
.
MIN_VALUE
)
return
0
;
...
...
@@ -345,15 +335,11 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
if
(
value
==
null
)
{
wasNull
=
true
;
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
0
;
}
wasNull
=
false
;
if
(
value
instanceof
Timestamp
)
{
if
(
value
instanceof
Timestamp
)
return
((
Timestamp
)
value
).
getTime
();
}
long
valueAsLong
=
0
;
try
{
valueAsLong
=
Long
.
parseLong
(
value
.
toString
());
...
...
@@ -370,11 +356,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
if
(
value
==
null
)
{
wasNull
=
true
;
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
0
;
}
wasNull
=
false
;
if
(
value
instanceof
Float
)
return
(
float
)
value
;
if
(
value
instanceof
Double
)
...
...
@@ -387,11 +371,10 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
wasNull
=
value
==
null
;
if
(
value
==
null
)
{
wasNull
=
true
;
return
0
;
}
wasNull
=
false
;
if
(
value
instanceof
Double
||
value
instanceof
Float
)
return
(
double
)
value
;
return
Double
.
parseDouble
(
value
.
toString
());
...
...
@@ -402,6 +385,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
null
;
if
(
value
instanceof
byte
[])
...
...
@@ -428,6 +412,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
null
;
if
(
value
instanceof
Timestamp
)
...
...
@@ -440,6 +425,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
null
;
if
(
value
instanceof
Timestamp
)
...
...
@@ -457,6 +443,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
null
;
if
(
value
instanceof
Timestamp
)
...
...
@@ -473,6 +460,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
ret
=
Utils
.
parseTimestamp
(
value
.
toString
());
}
catch
(
Exception
e
)
{
ret
=
null
;
wasNull
=
true
;
}
return
ret
;
}
...
...
@@ -488,7 +476,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
public
Object
getObject
(
int
columnIndex
)
throws
SQLException
{
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
return
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
wasNull
=
value
==
null
;
return
value
;
}
@Override
...
...
@@ -507,9 +497,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
checkAvailability
(
columnIndex
,
resultSet
.
get
(
pos
).
size
());
Object
value
=
resultSet
.
get
(
pos
).
get
(
columnIndex
-
1
);
wasNull
=
value
==
null
;
if
(
value
==
null
)
return
null
;
if
(
value
instanceof
Long
||
value
instanceof
Integer
||
value
instanceof
Short
||
value
instanceof
Byte
)
return
new
BigDecimal
(
Long
.
parseLong
(
value
.
toString
()));
if
(
value
instanceof
Double
||
value
instanceof
Float
)
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java
浏览文件 @
afb2cd5e
...
...
@@ -660,7 +660,6 @@ public class RestfulResultSetTest {
@BeforeClass
public
static
void
beforeClass
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.rs.RestfulDriver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS-RS://"
+
host
+
":6041/restful_test?user=root&password=taosdata"
);
stmt
=
conn
.
createStatement
();
stmt
.
execute
(
"create database if not exists restful_test"
);
...
...
@@ -670,7 +669,7 @@ public class RestfulResultSetTest {
stmt
.
execute
(
"insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"
);
rs
=
stmt
.
executeQuery
(
"select * from restful_test.weather"
);
rs
.
next
();
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/WasNullTest.java
0 → 100644
浏览文件 @
afb2cd5e
package
com.taosdata.jdbc.rs
;
import
org.junit.*
;
import
java.sql.*
;
public
class
WasNullTest
{
// private static final String host = "127.0.0.1";
private
static
final
String
host
=
"master"
;
private
Connection
conn
;
@Test
public
void
testGetTimestamp
()
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"drop table if exists weather"
);
stmt
.
execute
(
"create table if not exists weather(f1 timestamp, f2 timestamp, f3 int)"
);
stmt
.
execute
(
"insert into restful_test.weather values('2021-01-01 00:00:00.000', NULL, 100)"
);
ResultSet
rs
=
stmt
.
executeQuery
(
"select * from restful_test.weather"
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
if
(
i
==
2
)
{
Object
value
=
rs
.
getTimestamp
(
i
);
boolean
wasNull
=
rs
.
wasNull
();
Assert
.
assertNull
(
value
);
Assert
.
assertTrue
(
wasNull
);
}
else
{
Object
value
=
rs
.
getObject
(
i
);
boolean
wasNull
=
rs
.
wasNull
();
Assert
.
assertNotNull
(
value
);
Assert
.
assertFalse
(
wasNull
);
}
}
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
testGetObject
()
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"drop table if exists weather"
);
stmt
.
execute
(
"create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))"
);
stmt
.
execute
(
"insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, NULL, 10, 10, true, '涛思数据')"
);
ResultSet
rs
=
stmt
.
executeQuery
(
"select * from restful_test.weather"
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
Object
value
=
rs
.
getObject
(
i
);
boolean
wasNull
=
rs
.
wasNull
();
if
(
i
==
6
)
{
Assert
.
assertNull
(
value
);
Assert
.
assertTrue
(
wasNull
);
}
else
{
Assert
.
assertNotNull
(
value
);
Assert
.
assertFalse
(
wasNull
);
}
}
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Before
public
void
before
()
{
try
{
conn
=
DriverManager
.
getConnection
(
"jdbc:TAOS-RS://"
+
host
+
":6041/restful_test?user=root&password=taosdata"
);
Statement
stmt
=
conn
.
createStatement
();
stmt
.
execute
(
"drop database if exists restful_test"
);
stmt
.
execute
(
"create database if not exists restful_test"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@After
public
void
after
()
{
try
{
Statement
statement
=
conn
.
createStatement
();
statement
.
execute
(
"drop database if exists restful_test"
);
if
(
conn
!=
null
)
conn
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录