Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
16530a22
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
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 {
...
@@ -616,7 +616,6 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
columnMetaDataList
.
add
(
col10
);
columnMetaDataList
.
add
(
col10
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
ResultSet
tables
=
stmt
.
executeQuery
(
"show tables"
);
ResultSet
tables
=
stmt
.
executeQuery
(
"show tables"
);
while
(
tables
.
next
())
{
while
(
tables
.
next
())
{
...
@@ -655,8 +654,10 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
...
@@ -655,8 +654,10 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
}
}
public
ResultSet
getTableTypes
()
throws
SQLException
{
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
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>(
1
);
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>(
1
);
ColumnMetaData
colMetaData
=
new
ColumnMetaData
();
ColumnMetaData
colMetaData
=
new
ColumnMetaData
();
...
@@ -681,91 +682,113 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
...
@@ -681,91 +682,113 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
}
}
public
ResultSet
getColumns
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
columnNamePattern
)
throws
SQLException
{
public
ResultSet
getColumns
(
String
catalog
,
String
schemaPattern
,
String
tableNamePattern
,
String
columnNamePattern
)
throws
SQLException
{
// add by zyyang-taosdata
if
(
conn
==
null
||
conn
.
isClosed
())
Statement
stmt
;
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
))
;
if
(
null
!=
conn
&&
!
conn
.
isClosed
())
{
stmt
=
conn
.
createStatement
();
try
(
Statement
stmt
=
conn
.
createStatement
())
{
if
(
catalog
==
null
||
catalog
.
isEmpty
())
if
(
catalog
==
null
||
catalog
.
isEmpty
())
return
null
;
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
();
DatabaseMetaDataResultSet
resultSet
=
new
DatabaseMetaDataResultSet
();
// set up ColumnMetaDataList
// set up ColumnMetaDataList
List
<
ColumnMetaData
>
columnMetaDataList
=
new
ArrayList
<>(
24
);
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
);
columnMetaDataList
.
add
(
null
);
// DECIMAL_DIGITS
// add TABLE_NAME
ColumnMetaData
col9
=
new
ColumnMetaData
();
ColumnMetaData
colMetaData
=
new
ColumnMetaData
();
col9
.
setColIndex
(
9
);
colMetaData
.
setColIndex
(
3
);
col9
.
setColName
(
"DECIMAL_DIGITS"
);
colMetaData
.
setColName
(
"TABLE_NAME"
);
col9
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
colMetaData
.
setColSize
(
193
);
columnMetaDataList
.
add
(
col9
);
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
);
// add NUM_PREC_RADIX
// add NUM_PREC_RADIX
colMetaData
=
new
ColumnMetaData
();
ColumnMetaData
col10
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
10
);
col10
.
setColIndex
(
10
);
colMetaData
.
setColName
(
"NUM_PREC_RADIX"
);
col10
.
setColName
(
"NUM_PREC_RADIX"
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
col10
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
colMetaData
);
columnMetaDataList
.
add
(
col10
);
// add NULLABLE
// NULLABLE
colMetaData
=
new
ColumnMetaData
();
ColumnMetaData
col11
=
new
ColumnMetaData
();
colMetaData
.
setColIndex
(
11
);
col11
.
setColIndex
(
11
);
colMetaData
.
setColName
(
"NULLABLE"
);
col11
.
setColName
(
"NULLABLE"
);
colMetaData
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
col11
.
setColType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
columnMetaDataList
.
add
(
colMetaData
);
columnMetaDataList
.
add
(
col11
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
resultSet
.
setColumnMetaDataList
(
columnMetaDataList
);
// set up rowDataList
// set up rowDataList
ResultSet
r
esultSet0
=
stmt
.
executeQuery
(
"describe
"
+
tableNamePattern
);
ResultSet
r
s
=
stmt
.
executeQuery
(
"describe "
+
dbname
+
".
"
+
tableNamePattern
);
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
List
<
TSDBResultSetRowData
>
rowDataList
=
new
ArrayList
<>();
int
index
=
0
;
int
index
=
0
;
while
(
r
esultSet0
.
next
())
{
while
(
r
s
.
next
())
{
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
24
);
TSDBResultSetRowData
rowData
=
new
TSDBResultSetRowData
(
24
);
// set TABLE_CAT
rowData
.
setString
(
0
,
dbname
);
// set TABLE_NAME
// set TABLE_NAME
rowData
.
setString
(
2
,
tableNamePattern
);
rowData
.
setString
(
2
,
tableNamePattern
);
// set COLUMN_NAME
// set COLUMN_NAME
rowData
.
setString
(
3
,
r
esultSet0
.
getString
(
1
));
rowData
.
setString
(
3
,
r
s
.
getString
(
"Field"
));
// set DATA_TYPE
// set DATA_TYPE
String
typeName
=
r
esultSet0
.
getString
(
2
);
String
typeName
=
r
s
.
getString
(
"Type"
);
rowData
.
setInt
(
4
,
getDataType
(
typeName
));
rowData
.
setInt
(
4
,
getDataType
(
typeName
));
// set TYPE_NAME
// set TYPE_NAME
rowData
.
setString
(
5
,
typeName
);
rowData
.
setString
(
5
,
typeName
);
// set COLUMN_SIZE
// set COLUMN_SIZE
int
length
=
r
esultSet0
.
getInt
(
3
);
int
length
=
r
s
.
getInt
(
"Length"
);
rowData
.
setInt
(
6
,
getColumnSize
(
typeName
,
length
));
rowData
.
setInt
(
6
,
getColumnSize
(
typeName
,
length
));
// set DECIMAL_DIGITS
// set DECIMAL_DIGITS
rowData
.
setInt
(
8
,
getDecimalDigits
(
typeName
));
rowData
.
setInt
(
8
,
getDecimalDigits
(
typeName
));
...
@@ -773,15 +796,18 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
...
@@ -773,15 +796,18 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
rowData
.
setInt
(
9
,
10
);
rowData
.
setInt
(
9
,
10
);
// set NULLABLE
// set NULLABLE
rowData
.
setInt
(
10
,
getNullable
(
index
,
typeName
));
rowData
.
setInt
(
10
,
getNullable
(
index
,
typeName
));
// set REMARKS
rowData
.
setString
(
11
,
rs
.
getString
(
"Note"
));
rowDataList
.
add
(
rowData
);
rowDataList
.
add
(
rowData
);
index
++;
index
++;
}
}
resultSet
.
setRowDataList
(
rowDataList
);
resultSet
.
setRowDataList
(
rowDataList
);
return
resultSet
;
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
)
{
private
int
getNullable
(
int
index
,
String
typeName
)
{
...
...
src/connector/jdbc/src/test/java/TestTSDBDatabaseMetaData.java
浏览文件 @
16530a22
...
@@ -7,8 +7,8 @@ public class TestTSDBDatabaseMetaData {
...
@@ -7,8 +7,8 @@ public class TestTSDBDatabaseMetaData {
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
Connection
connection
=
null
;
Connection
connection
=
null
;
DatabaseMetaData
dbMetaData
=
null
;
DatabaseMetaData
dbMetaData
;
ResultSet
resSet
=
null
;
ResultSet
resSet
;
try
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
Properties
properties
=
new
Properties
();
...
...
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java
浏览文件 @
16530a22
...
@@ -667,7 +667,14 @@ public class TSDBDatabaseMetaDataTest {
...
@@ -667,7 +667,14 @@ public class TSDBDatabaseMetaDataTest {
@Test
@Test
public
void
getColumns
()
throws
SQLException
{
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
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录