Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
0ff5a53b
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,发现更多精彩内容 >>
提交
0ff5a53b
编写于
11月 04, 2020
作者:
S
Serge Rider
提交者:
GitHub
11月 04, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10223 from dbeaver/sql-parser-blocks#5467
#5467 Fix for parsing inner blocks Former-commit-id:
fa213e7f
上级
1aadffef
21556e0c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
43 addition
and
35 deletion
+43
-35
plugins/org.jkiss.dbeaver.ext.oracle/src/org/jkiss/dbeaver/ext/oracle/model/OracleSQLDialect.java
.../org/jkiss/dbeaver/ext/oracle/model/OracleSQLDialect.java
+11
-0
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreDialect.java
...rg/jkiss/dbeaver/ext/postgresql/model/PostgreDialect.java
+0
-6
plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParser.java
...c/org/jkiss/dbeaver/model/sql/parser/SQLScriptParser.java
+18
-29
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/sql/AbstractSQLDialect.java
.../org/jkiss/dbeaver/model/impl/sql/AbstractSQLDialect.java
+6
-0
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLDialect.java
...ver.model/src/org/jkiss/dbeaver/model/sql/SQLDialect.java
+8
-0
未找到文件。
plugins/org.jkiss.dbeaver.ext.oracle/src/org/jkiss/dbeaver/ext/oracle/model/OracleSQLDialect.java
浏览文件 @
0ff5a53b
...
...
@@ -63,6 +63,11 @@ class OracleSQLDialect extends JDBCSQLDialect {
"DECLARE"
,
};
public
static
final
String
[]
ORACLE_INNER_BLOCK_PREFIXES
=
new
String
[]{
"AS"
,
"IS"
,
};
public
static
final
String
[]
OTHER_TYPES_FUNCTIONS
=
{
//functions without parentheses #8710
"CURRENT_DATE"
,
...
...
@@ -350,6 +355,12 @@ class OracleSQLDialect extends JDBCSQLDialect {
return
ORACLE_BLOCK_HEADERS
;
}
@Nullable
@Override
public
String
[]
getInnerBlockPrefixes
()
{
return
ORACLE_INNER_BLOCK_PREFIXES
;
}
@NotNull
@Override
public
String
[]
getExecuteKeywords
()
{
...
...
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreDialect.java
浏览文件 @
0ff5a53b
...
...
@@ -779,12 +779,6 @@ public class PostgreDialect extends JDBCSQLDialect implements TPRuleProvider {
return
BLOCK_BOUND_KEYWORDS
;
}
@Nullable
@Override
public
String
[]
getBlockHeaderStrings
()
{
return
new
String
[]
{
"DECLARE"
};
}
@NotNull
@Override
public
String
getTypeCastClause
(
DBSAttributeBase
attribute
,
String
expression
)
{
...
...
plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParser.java
浏览文件 @
0ff5a53b
...
...
@@ -129,10 +129,7 @@ public class SQLScriptParser
}
if
(
tokenType
==
SQLTokenType
.
T_BLOCK_HEADER
)
{
if
(
curBlock
==
null
)
{
// Check for double block header, e.g. DO, DECLARE
curBlock
=
new
ScriptBlockInfo
(
curBlock
,
true
);
}
curBlock
=
new
ScriptBlockInfo
(
curBlock
,
true
);
hasBlocks
=
true
;
}
else
if
(
tokenType
==
SQLTokenType
.
T_BLOCK_TOGGLE
)
{
String
togglePattern
;
...
...
@@ -142,39 +139,28 @@ public class SQLScriptParser
log
.
warn
(
e
);
togglePattern
=
""
;
}
// Second toggle pattern must be the same as first one.
// Toggles can be nested (PostgreSQL) and we need to count only outer
if
(
curBlock
!=
null
&&
curBlock
.
parent
==
null
&&
togglePattern
.
equals
(
curBlock
.
togglePattern
))
{
if
(
curBlock
!=
null
&&
togglePattern
.
equals
(
curBlock
.
togglePattern
))
{
curBlock
=
curBlock
.
parent
;
}
else
if
(
curBlock
==
null
)
{
curBlock
=
new
ScriptBlockInfo
(
curBlock
,
togglePattern
);
}
else
{
log
.
debug
(
"Block toggle token inside another block. Can't process it"
);
curBlock
=
new
ScriptBlockInfo
(
curBlock
,
togglePattern
);
hasBlocks
=
true
;
}
hasBlocks
=
true
;
}
else
if
(
tokenType
==
SQLTokenType
.
T_BLOCK_BEGIN
)
{
if
(
curBlock
==
null
||
!
curBlock
.
isHeader
)
{
curBlock
=
new
ScriptBlockInfo
(
curBlock
,
false
);
}
else
{
curBlock
.
isHeader
=
false
;
// Drop header block if it is followed by a regular block and
// that block is not preceded by the prefix e.g 'AS', because in many dialects
// there's no direct header block terminators
// like 'BEGIN ... END' but 'DECLARE ... BEGIN ... END'
if
(
curBlock
!=
null
&&
curBlock
.
isHeader
)
{
if
(
prevNotEmptyTokenType
!=
SQLTokenType
.
T_KEYWORD
||
!
ArrayUtils
.
contains
(
dialect
.
getInnerBlockPrefixes
(),
lastKeyword
))
{
curBlock
=
curBlock
.
parent
;
}
}
curBlock
=
new
ScriptBlockInfo
(
curBlock
,
false
);
hasBlocks
=
true
;
}
else
if
(
tokenType
==
SQLTokenType
.
T_BLOCK_END
)
{
// Sometimes query contains END clause without BEGIN. E.g. CASE, IF, etc.
// This END doesn't mean block
if
(
curBlock
!=
null
)
{
if
(!
CommonUtils
.
isEmpty
(
curBlock
.
togglePattern
))
{
// Block end inside of block toggle (#7460).
// Actually it is a result of some wrong SQL parse (e.g. we didn't recognize block begin correctly).
// However block toggle has higher priority. At the moment it is PostgreSQL specific.
try
{
log
.
debug
(
"Block end '"
+
document
.
get
(
tokenOffset
,
tokenLength
)
+
"' inside of named block toggle '"
+
curBlock
.
togglePattern
+
"'. Ignore."
);
}
catch
(
Throwable
e
)
{
log
.
debug
(
e
);
}
}
else
{
curBlock
=
curBlock
.
parent
;
}
curBlock
=
curBlock
.
parent
;
}
}
else
if
(
isDelimiter
&&
curBlock
!=
null
)
{
// Delimiter in some brackets or inside block. Ignore it.
...
...
@@ -285,6 +271,9 @@ public class SQLScriptParser
if
(
tokenType
==
SQLTokenType
.
T_DELIMITER
)
{
queryEndPos
+=
tokenLength
;
}
if
(
curBlock
!=
null
)
{
log
.
warn
(
"Found leftover blocks in script after parsing"
);
}
// make script line
return
new
SQLQuery
(
context
.
getDataSource
(),
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/sql/AbstractSQLDialect.java
浏览文件 @
0ff5a53b
...
...
@@ -292,6 +292,12 @@ public abstract class AbstractSQLDialect implements SQLDialect {
return
null
;
}
@Nullable
@Override
public
String
[]
getInnerBlockPrefixes
()
{
return
null
;
}
@Override
public
boolean
validIdentifierStart
(
char
c
)
{
return
Character
.
isLetter
(
c
);
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLDialect.java
浏览文件 @
0ff5a53b
...
...
@@ -206,6 +206,14 @@ public interface SQLDialect {
@Nullable
String
[]
getBlockHeaderStrings
();
/**
* Inner block prefixes strings.
* Determines if the block is a child of the header block.
* @return inner block prefixes or null (if not supported)
*/
@Nullable
String
[]
getInnerBlockPrefixes
();
/**
* Retrieves whether a catalog appears at the start of a fully qualified
* table name. If not, the catalog appears at the end.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录