Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
653601b8
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,发现更多精彩内容 >>
提交
653601b8
编写于
1月 20, 2018
作者:
S
serge-rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Oracle (and others) - SQL blocks processing (trailing delimiters)
上级
ec0ba17b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
14 deletion
+40
-14
bundles/org.jkiss.utils/src/org/jkiss/utils/CommonUtils.java
bundles/org.jkiss.utils/src/org/jkiss/utils/CommonUtils.java
+4
-1
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
...eaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
+36
-13
未找到文件。
bundles/org.jkiss.utils/src/org/jkiss/utils/CommonUtils.java
浏览文件 @
653601b8
...
...
@@ -29,7 +29,10 @@ import java.util.*;
public
class
CommonUtils
{
public
static
boolean
isJavaIdentifier
(
@NotNull
CharSequence
str
)
{
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++)
{
if
(
str
.
length
()
==
0
||
!
Character
.
isJavaIdentifierStart
(
str
.
charAt
(
0
)))
{
return
false
;
}
for
(
int
i
=
1
;
i
<
str
.
length
();
i
++)
{
if
(!
Character
.
isJavaIdentifierPart
(
str
.
charAt
(
i
)))
{
return
false
;
}
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
浏览文件 @
653601b8
...
...
@@ -311,12 +311,14 @@ public final class SQLUtils {
public
static
String
trimQueryStatement
(
SQLSyntaxManager
syntaxManager
,
String
sql
,
boolean
trimDelimiter
)
{
//sql = sql.trim();
if
(!
trimDelimiter
)
{
if
(
sql
.
isEmpty
()
||
!
trimDelimiter
)
{
// Do not trim delimiter
return
sql
;
}
// Here we cur trailing query delimiter. most of DBs don't expect it in the end of query
// However Oracle REQUIRES that block queries (e.g. DDL like CREATE PROCEDURE) must have trailing delimiter
// So we check whether this query is a block query (by checking for all SQL dialect block delimiters)
String
trailingSpaces
=
""
;
{
int
trailingSpacesCount
=
0
;
...
...
@@ -332,21 +334,42 @@ public final class SQLUtils {
}
}
for
(
String
statementDelimiter
:
syntaxManager
.
getStatementDelimiters
())
{
if
(
sql
.
endsWith
(
statementDelimiter
)
&&
sql
.
length
()
>
statementDelimiter
.
length
())
{
if
(
Character
.
isAlphabetic
(
statementDelimiter
.
charAt
(
0
)))
{
// Delimiter is alphabetic (e.g. "GO") so it must be prefixed with whitespace
char
lastChar
=
sql
.
charAt
(
sql
.
length
()
-
statementDelimiter
.
length
()
-
1
);
if
(
Character
.
isUnicodeIdentifierPart
(
lastChar
))
{
return
sql
+
trailingSpaces
;
}
if
(!
sql
.
endsWith
(
statementDelimiter
)
&&
sql
.
length
()
>
statementDelimiter
.
length
())
{
continue
;
}
if
(
Character
.
isAlphabetic
(
statementDelimiter
.
charAt
(
0
)))
{
// Delimiter is alphabetic (e.g. "GO") so it must be prefixed with whitespace
char
lastChar
=
sql
.
charAt
(
sql
.
length
()
-
statementDelimiter
.
length
()
-
1
);
if
(
Character
.
isUnicodeIdentifierPart
(
lastChar
))
{
break
;
}
// Remove trailing delimiter only if it is not block end
String
trimmed
=
sql
.
substring
(
0
,
sql
.
length
()
-
statementDelimiter
.
length
());
}
// Remove trailing delimiter only if it is not block end
boolean
isBlockQuery
=
false
;
String
trimmed
=
sql
.
substring
(
0
,
sql
.
length
()
-
statementDelimiter
.
length
());
{
String
test
=
trimmed
.
toUpperCase
().
trim
();
if
(!
test
.
endsWith
(
SQLConstants
.
BLOCK_END
))
{
sql
=
trimmed
;
for
(
String
[]
blocks
:
syntaxManager
.
getDialect
().
getBlockBoundStrings
())
{
int
endIndex
=
test
.
indexOf
(
blocks
[
1
]);
if
(
endIndex
>
0
)
{
// This is a block query if it ends with 'END' or with 'END id'
if
(
test
.
endsWith
(
blocks
[
1
]))
{
isBlockQuery
=
true
;
break
;
}
else
{
String
afterEnd
=
test
.
substring
(
endIndex
+
blocks
[
1
].
length
()).
trim
();
if
(
CommonUtils
.
isJavaIdentifier
(
afterEnd
))
{
isBlockQuery
=
true
;
break
;
}
}
}
}
}
if
(!
isBlockQuery
)
{
sql
=
trimmed
;
}
break
;
}
return
sql
+
trailingSpaces
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录