Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
2ce5de31
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2ce5de31
编写于
2月 22, 2019
作者:
S
serge-rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#5332 PG: structs with array items parse fix
Former-commit-id:
0750d4cc
上级
4f42093f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
6 deletion
+43
-6
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreUtils.java
...ql/src/org/jkiss/dbeaver/ext/postgresql/PostgreUtils.java
+39
-3
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/data/PostgreArrayValueHandler.java
...r/ext/postgresql/model/data/PostgreArrayValueHandler.java
+3
-2
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/data/PostgreStructValueHandler.java
.../ext/postgresql/model/data/PostgreStructValueHandler.java
+1
-1
未找到文件。
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreUtils.java
浏览文件 @
2ce5de31
...
...
@@ -34,9 +34,11 @@ import org.jkiss.dbeaver.model.DBPDataKind;
import
org.jkiss.dbeaver.model.DBPEvaluationContext
;
import
org.jkiss.dbeaver.model.DBUtils
;
import
org.jkiss.dbeaver.model.connection.DBPDriver
;
import
org.jkiss.dbeaver.model.data.DBDValueHandler
;
import
org.jkiss.dbeaver.model.edit.DBEPersistAction
;
import
org.jkiss.dbeaver.model.edit.DBERegistry
;
import
org.jkiss.dbeaver.model.exec.DBCException
;
import
org.jkiss.dbeaver.model.exec.DBCSession
;
import
org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement
;
import
org.jkiss.dbeaver.model.exec.jdbc.JDBCSession
;
import
org.jkiss.dbeaver.model.impl.AbstractObjectCache
;
...
...
@@ -45,8 +47,10 @@ import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistActionComment;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource
;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.struct.DBSDataType
;
import
org.jkiss.dbeaver.model.struct.DBSObject
;
import
org.jkiss.dbeaver.model.struct.DBSTypedObject
;
import
org.jkiss.dbeaver.model.struct.DBSTypedObjectEx
;
import
org.jkiss.utils.ArrayUtils
;
import
org.jkiss.utils.CommonUtils
;
...
...
@@ -415,7 +419,33 @@ public class PostgreUtils {
}
}
public
static
Object
convertStringToValue
(
DBSTypedObject
itemType
,
String
string
,
boolean
unescape
)
{
public
static
Object
convertStringToValue
(
DBCSession
session
,
DBSTypedObject
itemType
,
String
string
,
boolean
unescape
)
throws
DBCException
{
if
(
itemType
.
getDataKind
()
==
DBPDataKind
.
ARRAY
)
{
if
(
CommonUtils
.
isEmpty
(
string
))
{
return
new
Object
[
0
];
}
else
if
(
string
.
startsWith
(
"{"
)
&&
string
.
endsWith
(
"}"
))
{
DBSDataType
arrayDataType
=
itemType
instanceof
DBSDataType
?
(
DBSDataType
)
itemType
:
((
DBSTypedObjectEx
)
itemType
).
getDataType
();
try
{
DBSDataType
componentType
=
arrayDataType
.
getComponentType
(
session
.
getProgressMonitor
());
if
(
componentType
==
null
)
{
log
.
error
(
"Can't get component type from array '"
+
itemType
.
getFullTypeName
()
+
"'"
);
return
null
;
}
else
{
String
[]
itemStrings
=
parseObjectString
(
string
.
substring
(
1
,
string
.
length
()
-
1
));
Object
[]
itemValues
=
new
Object
[
itemStrings
.
length
];
for
(
int
i
=
0
;
i
<
itemStrings
.
length
;
i
++)
{
itemValues
[
i
]
=
convertStringToValue
(
session
,
componentType
,
itemStrings
[
i
],
unescape
);
}
return
itemValues
;
}
}
catch
(
Exception
e
)
{
throw
new
DBCException
(
"Error extracting array '"
+
itemType
.
getFullTypeName
()
+
"' items"
,
e
);
}
}
else
{
log
.
error
(
"Unsupported array string: '"
+
string
+
"'"
);
return
null
;
}
}
switch
(
itemType
.
getTypeID
())
{
case
Types
.
BOOLEAN
:
return
Boolean
.
valueOf
(
string
);
case
Types
.
TINYINT
:
return
Byte
.
parseByte
(
string
);
...
...
@@ -425,8 +455,14 @@ public class PostgreUtils {
case
Types
.
FLOAT
:
return
Float
.
parseFloat
(
string
);
case
Types
.
REAL
:
case
Types
.
DOUBLE
:
return
Double
.
parseDouble
(
string
);
default
:
return
string
;
default
:
{
DBDValueHandler
valueHandler
=
DBUtils
.
findValueHandler
(
session
,
itemType
);
if
(
valueHandler
!=
null
)
{
return
valueHandler
.
getValueFromObject
(
session
,
itemType
,
string
,
false
);
}
else
{
return
string
;
}
}
}
}
...
...
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/data/PostgreArrayValueHandler.java
浏览文件 @
2ce5de31
...
...
@@ -17,6 +17,7 @@
package
org.jkiss.dbeaver.ext.postgresql.model.data
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.ext.postgresql.PostgreConstants
;
import
org.jkiss.dbeaver.ext.postgresql.PostgreUtils
;
import
org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource
;
...
...
@@ -73,7 +74,7 @@ public class PostgreArrayValueHandler extends JDBCArrayValueHandler {
return
super
.
getValueFromObject
(
session
,
type
,
object
,
copy
);
}
private
JDBCCollection
convertStringToArray
(
@NotNull
DBCSession
session
,
@NotNull
PostgreDataType
itemType
,
@NotNull
String
value
)
{
private
JDBCCollection
convertStringToArray
(
@NotNull
DBCSession
session
,
@NotNull
PostgreDataType
itemType
,
@NotNull
String
value
)
throws
DBCException
{
List
<
String
>
strings
=
new
ArrayList
<>(
10
);
StringTokenizer
st
=
new
StringTokenizer
(
value
,
" "
);
while
(
st
.
hasMoreTokens
())
{
...
...
@@ -81,7 +82,7 @@ public class PostgreArrayValueHandler extends JDBCArrayValueHandler {
}
Object
[]
contents
=
new
Object
[
strings
.
size
()];
for
(
int
i
=
0
;
i
<
strings
.
size
();
i
++)
{
contents
[
i
]
=
PostgreUtils
.
convertStringToValue
(
itemType
,
strings
.
get
(
i
),
false
);
contents
[
i
]
=
PostgreUtils
.
convertStringToValue
(
session
,
itemType
,
strings
.
get
(
i
),
false
);
}
return
new
JDBCCollection
(
itemType
,
DBUtils
.
findValueHandler
(
session
,
itemType
),
contents
);
}
...
...
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/data/PostgreStructValueHandler.java
浏览文件 @
2ce5de31
...
...
@@ -115,7 +115,7 @@ public class PostgreStructValueHandler extends JDBCStructValueHandler {
Iterator
<
PostgreDataTypeAttribute
>
attrIter
=
attributes
.
iterator
();
for
(
int
i
=
0
;
i
<
parsedValues
.
length
&&
attrIter
.
hasNext
();
i
++)
{
final
PostgreDataTypeAttribute
itemAttr
=
attrIter
.
next
();
attrValues
[
i
]
=
PostgreUtils
.
convertStringToValue
(
itemAttr
,
parsedValues
[
i
],
true
);
attrValues
[
i
]
=
PostgreUtils
.
convertStringToValue
(
session
,
itemAttr
,
parsedValues
[
i
],
true
);
}
Struct
contents
=
new
JDBCStructImpl
(
compType
.
getTypeName
(),
attrValues
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录