Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
16530a22
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看板
提交
16530a22
编写于
1月 19, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
4509e2c3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
104 addition
and
71 deletion
+104
-71
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java
...src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java
+94
-68
src/connector/jdbc/src/test/java/TestTSDBDatabaseMetaData.java
...onnector/jdbc/src/test/java/TestTSDBDatabaseMetaData.java
+2
-2
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
...test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
+8
-1
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java
浏览文件 @
16530a22
...
...
@@ -616,7 +616,6 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
columnMetaDataList
.
add
(
col10
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
tables
=
stmt
.
executeQuery
(
"show tables"
);
while
(
tables
.
next
())
{
...
...
@@ -655,8 +654,10 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
}
public
ResultSet
getTableTypes
()
throws
SQLException
{
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>(
1
);
ColumnMetaData
colMetaData
=
new
ColumnMetaData
();
...
...
@@ -681,91 +682,113 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
}
public
ResultSet
getColumns
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
columnNamePattern
)
throws
SQLException
{
// add by zyyang-taosdata
Statement
stmt
;
if
(
null
!=
conn
&&
!
conn
.
isClosed
())
{
stmt
=
conn
.
createStatement
();
if
(
conn
==
null
||
conn
.
isClosed
())
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
))
;
try
(
Statement
stmt
=
conn
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
stmt
.
executeUpdate
(
"use "
+
catalog
);
ResultSet
databases
=
stmt
.
executeQuery
(
"show databases"
);
String
dbname
=
null
;
while
(
databases
.
next
())
{
dbname
=
databases
.
getString
(
"name"
);
if
(
dbname
.
equalsIgnoreCase
(
catalog
))
break
;
}
databases
.
close
();
if
(
dbname
==
null
)
return
null
;
stmt
.
execute
(
"use "
+
dbname
);
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>(
24
);
// TABLE_CAT
ColumnMetaData
col1
=
new
ColumnMetaData
();
col1
.
setColIndex
(
1
);
col1
.
setColName
(
"TABLE_CAT"
);
col1
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col1
);
// TABLE_SCHEM
ColumnMetaData
col2
=
new
ColumnMetaData
();
col2
.
setColIndex
(
2
);
col2
.
setColName
(
"TABLE_SCHEM"
);
col2
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col2
);
// TABLE_NAME
ColumnMetaData
col3
=
new
ColumnMetaData
();
col3
.
setColIndex
(
3
);
col3
.
setColName
(
"TABLE_NAME"
);
col3
.
setColSize
(
193
);
col3
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col3
);
// COLUMN_NAME
ColumnMetaData
col4
=
new
ColumnMetaData
();
col4
.
setColIndex
(
4
);
col4
.
setColName
(
"COLUMN_NAME"
);
col4
.
setColSize
(
65
);
col4
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col4
);
// DATA_TYPE
ColumnMetaData
col5
=
new
ColumnMetaData
();
col5
.
setColIndex
(
5
);
col5
.
setColName
(
"DATA_TYPE"
);
col5
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col5
);
// TYPE_NAME
ColumnMetaData
col6
=
new
ColumnMetaData
();
col6
.
setColIndex
(
6
);
col6
.
setColName
(
"TYPE_NAME"
);
col6
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
columnMetaDataList
.
add
(
col6
);
// COLUMN_SIZE
ColumnMetaData
col7
=
new
ColumnMetaData
();
col7
.
setColIndex
(
7
);
col7
.
setColName
(
"COLUMN_SIZE"
);
col7
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col7
);
// BUFFER_LENGTH ,not used
columnMetaDataList
.
add
(
null
);
columnMetaDataList
.
add
(
null
);
// add TABLE_NAME
ColumnMetaData
colMetaData
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
3
);
colMetaData
.
setColName
(
"TABLE_NAME"
);
colMetaData
.
setColSize
(
193
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
);
columnMetaDataList
.
add
(
colMetaData
);
// add COLUMN_NAME
colMetaData
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
4
);
colMetaData
.
setColName
(
"COLUMN_NAME"
);
colMetaData
.
setColSize
(
65
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
);
columnMetaDataList
.
add
(
colMetaData
);
// add DATA_TYPE
colMetaData
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
5
);
colMetaData
.
setColName
(
"DATA_TYPE"
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
colMetaData
);
// add TYPE_NAME
colMetaData
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
6
);
colMetaData
.
setColName
(
"TYPE_NAME"
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
);
columnMetaDataList
.
add
(
colMetaData
);
// add COLUMN_SIZE
colMetaData
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
7
);
colMetaData
.
setColName
(
"COLUMN_SIZE"
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
colMetaData
);
// add BUFFER_LENGTH ,not used
columnMetaDataList
.
add
(
null
);
// add DECIMAL_DIGITS
colMetaData
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
9
);
colMetaData
.
setColName
(
"DECIMAL_DIGITS"
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
colMetaData
);
// DECIMAL_DIGITS
ColumnMetaData
col9
=
new
ColumnMetaData
();
col9
.
setColIndex
(
9
);
col9
.
setColName
(
"DECIMAL_DIGITS"
);
col9
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col9
);
// add NUM_PREC_RADIX
colMetaData
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
10
);
colMetaData
.
setColName
(
"NUM_PREC_RADIX"
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
colMetaData
);
// add NULLABLE
colMetaData
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
11
);
colMetaData
.
setColName
(
"NULLABLE"
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
colMetaData
);
ColumnMetaData
col10
=
new
ColumnMetaData
();
col10
.
setColIndex
(
10
);
col10
.
setColName
(
"NUM_PREC_RADIX"
);
col10
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col10
);
// NULLABLE
ColumnMetaData
col11
=
new
ColumnMetaData
();
col11
.
setColIndex
(
11
);
col11
.
setColName
(
"NULLABLE"
);
col11
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
col11
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
// set up rowDataList
ResultSet
r
esultSet0
=
stmt
.
executeQuery
(
"describe
"
+
tableNamePattern
);
ResultSet
r
s
=
stmt
.
executeQuery
(
"describe "
+
dbname
+
".
"
+
tableNamePattern
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
int
index
=
0
;
while
(
r
esultSet0
.
next
())
{
while
(
r
s
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
24
);
// set TABLE_CAT
rowData
.
setString
(
0
,
dbname
);
// set TABLE_NAME
rowData
.
setString
(
2
,
tableNamePattern
);
// set COLUMN_NAME
rowData
.
setString
(
3
,
r
esultSet0
.
getString
(
1
));
rowData
.
setString
(
3
,
r
s
.
getString
(
"Field"
));
// set DATA_TYPE
String
typeName
=
r
esultSet0
.
getString
(
2
);
String
typeName
=
r
s
.
getString
(
"Type"
);
rowData
.
setInt
(
4
,
getDataType
(
typeName
));
// set TYPE_NAME
rowData
.
setString
(
5
,
typeName
);
// set COLUMN_SIZE
int
length
=
r
esultSet0
.
getInt
(
3
);
int
length
=
r
s
.
getInt
(
"Length"
);
rowData
.
setInt
(
6
,
getColumnSize
(
typeName
,
length
));
// set DECIMAL_DIGITS
rowData
.
setInt
(
8
,
getDecimalDigits
(
typeName
));
...
...
@@ -773,15 +796,18 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
rowData
.
setInt
(
9
,
10
);
// set NULLABLE
rowData
.
setInt
(
10
,
getNullable
(
index
,
typeName
));
// set REMARKS
rowData
.
setString
(
11
,
rs
.
getString
(
"Note"
));
rowDataList
.
add
(
rowData
);
index
++;
}
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
}
else
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
private
int
getNullable
(
int
index
,
String
typeName
)
{
...
...
src/connector/jdbc/src/test/java/TestTSDBDatabaseMetaData.java
浏览文件 @
16530a22
...
...
@@ -7,8 +7,8 @@ public class TestTSDBDatabaseMetaData {
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
Connection
connection
=
null
;
DatabaseMetaData
dbMetaData
=
null
;
ResultSet
resSet
=
null
;
DatabaseMetaData
dbMetaData
;
ResultSet
resSet
;
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
浏览文件 @
16530a22
...
...
@@ -667,7 +667,14 @@ public class TSDBDatabaseMetaDataTest {
@Test
public
void
getColumns
()
throws
SQLException
{
Assert
.
assertNotNull
(
metaData
.
getColumns
(
""
,
""
,
""
,
""
));
ResultSet
columns
=
metaData
.
getColumns
(
"log"
,
""
,
"dn"
,
""
);
ResultSetMetaData
meta
=
columns
.
getMetaData
();
while
(
columns
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
System
.
out
.
print
(
meta
.
getColumnLabel
(
i
)
+
": "
+
columns
.
getString
(
i
));
}
System
.
out
.
println
();
}
}
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录