Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
81bb6b2e
Unverified
提交
81bb6b2e
authored
7月 07, 2018
作者:
Evgenij Ryazanov
提交者:
GitHub
7月 07, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1272 from katzyn/misc
Reduce code duplication in Parser
上级
c98efe8f
47463ab4
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
56 行增加
和
93 行删除
+56
-93
Parser.java
h2/src/main/org/h2/command/Parser.java
+56
-93
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
81bb6b2e
...
@@ -807,13 +807,7 @@ public class Parser {
...
@@ -807,13 +807,7 @@ public class Parser {
do
{
do
{
Column
column
=
readTableColumn
(
filter
);
Column
column
=
readTableColumn
(
filter
);
read
(
"="
);
read
(
"="
);
Expression
expression
;
command
.
setAssignment
(
column
,
readExpressionOrDefault
());
if
(
readIf
(
"DEFAULT"
))
{
expression
=
ValueExpression
.
getDefault
();
}
else
{
expression
=
readExpression
();
}
command
.
setAssignment
(
column
,
expression
);
}
while
(
readIf
(
","
));
}
while
(
readIf
(
","
));
}
}
if
(
readIf
(
"WHERE"
))
{
if
(
readIf
(
"WHERE"
))
{
...
@@ -1105,18 +1099,8 @@ public class Parser {
...
@@ -1105,18 +1099,8 @@ public class Parser {
}
}
if
(
readIf
(
"VALUES"
))
{
if
(
readIf
(
"VALUES"
))
{
do
{
do
{
ArrayList
<
Expression
>
values
=
Utils
.
newSmallArrayList
();
read
(
"("
);
read
(
"("
);
if
(!
readIf
(
")"
))
{
command
.
addRow
(
parseValuesForInsert
());
do
{
if
(
readIf
(
"DEFAULT"
))
{
values
.
add
(
null
);
}
else
{
values
.
add
(
readExpression
());
}
}
while
(
readIfMore
(
false
));
}
command
.
addRow
(
values
.
toArray
(
new
Expression
[
0
]));
}
while
(
readIf
(
","
));
}
while
(
readIf
(
","
));
}
else
{
}
else
{
command
.
setQuery
(
parseSelect
());
command
.
setQuery
(
parseSelect
());
...
@@ -1294,13 +1278,7 @@ public class Parser {
...
@@ -1294,13 +1278,7 @@ public class Parser {
}
}
Column
column
=
table
.
getColumn
(
columnName
);
Column
column
=
table
.
getColumn
(
columnName
);
read
(
"="
);
read
(
"="
);
Expression
expression
;
command
.
addAssignmentForDuplicate
(
column
,
readExpressionOrDefault
());
if
(
readIf
(
"DEFAULT"
))
{
expression
=
ValueExpression
.
getDefault
();
}
else
{
expression
=
readExpression
();
}
command
.
addAssignmentForDuplicate
(
column
,
expression
);
}
while
(
readIf
(
","
));
}
while
(
readIf
(
","
));
}
}
}
}
...
@@ -1334,17 +1312,7 @@ public class Parser {
...
@@ -1334,17 +1312,7 @@ public class Parser {
}
else
if
(
readIf
(
"VALUES"
))
{
}
else
if
(
readIf
(
"VALUES"
))
{
read
(
"("
);
read
(
"("
);
do
{
do
{
ArrayList
<
Expression
>
values
=
Utils
.
newSmallArrayList
();
command
.
addRow
(
parseValuesForInsert
());
if
(!
readIf
(
")"
))
{
do
{
if
(
readIf
(
"DEFAULT"
))
{
values
.
add
(
null
);
}
else
{
values
.
add
(
readExpression
());
}
}
while
(
readIfMore
(
false
));
}
command
.
addRow
(
values
.
toArray
(
new
Expression
[
0
]));
// the following condition will allow (..),; and (..);
// the following condition will allow (..),; and (..);
}
while
(
readIf
(
","
)
&&
readIf
(
"("
));
}
while
(
readIf
(
","
)
&&
readIf
(
"("
));
}
else
if
(
readIf
(
"SET"
))
{
}
else
if
(
readIf
(
"SET"
))
{
...
@@ -1356,13 +1324,7 @@ public class Parser {
...
@@ -1356,13 +1324,7 @@ public class Parser {
do
{
do
{
columnList
.
add
(
parseColumn
(
table
));
columnList
.
add
(
parseColumn
(
table
));
read
(
"="
);
read
(
"="
);
Expression
expression
;
values
.
add
(
readExpressionOrDefault
());
if
(
readIf
(
"DEFAULT"
))
{
expression
=
ValueExpression
.
getDefault
();
}
else
{
expression
=
readExpression
();
}
values
.
add
(
expression
);
}
while
(
readIf
(
","
));
}
while
(
readIf
(
","
));
command
.
setColumns
(
columnList
.
toArray
(
new
Column
[
0
]));
command
.
setColumns
(
columnList
.
toArray
(
new
Column
[
0
]));
command
.
addRow
(
values
.
toArray
(
new
Expression
[
0
]));
command
.
addRow
(
values
.
toArray
(
new
Expression
[
0
]));
...
@@ -1392,18 +1354,8 @@ public class Parser {
...
@@ -1392,18 +1354,8 @@ public class Parser {
}
}
if
(
readIf
(
"VALUES"
))
{
if
(
readIf
(
"VALUES"
))
{
do
{
do
{
ArrayList
<
Expression
>
values
=
Utils
.
newSmallArrayList
();
read
(
"("
);
read
(
"("
);
if
(!
readIf
(
")"
))
{
command
.
addRow
(
parseValuesForInsert
());
do
{
if
(
readIf
(
"DEFAULT"
))
{
values
.
add
(
null
);
}
else
{
values
.
add
(
readExpression
());
}
}
while
(
readIfMore
(
false
));
}
command
.
addRow
(
values
.
toArray
(
new
Expression
[
0
]));
}
while
(
readIf
(
","
));
}
while
(
readIf
(
","
));
}
else
{
}
else
{
command
.
setQuery
(
parseSelect
());
command
.
setQuery
(
parseSelect
());
...
@@ -1411,6 +1363,20 @@ public class Parser {
...
@@ -1411,6 +1363,20 @@ public class Parser {
return
command
;
return
command
;
}
}
private
Expression
[]
parseValuesForInsert
()
{
ArrayList
<
Expression
>
values
=
Utils
.
newSmallArrayList
();
if
(!
readIf
(
")"
))
{
do
{
if
(
readIf
(
"DEFAULT"
))
{
values
.
add
(
null
);
}
else
{
values
.
add
(
readExpression
());
}
}
while
(
readIfMore
(
false
));
}
return
values
.
toArray
(
new
Expression
[
0
]);
}
private
TableFilter
readTableFilter
()
{
private
TableFilter
readTableFilter
()
{
Table
table
;
Table
table
;
String
alias
=
null
;
String
alias
=
null
;
...
@@ -1774,10 +1740,9 @@ public class Parser {
...
@@ -1774,10 +1740,9 @@ public class Parser {
command
.
setSchemaName
(
readUniqueIdentifier
());
command
.
setSchemaName
(
readUniqueIdentifier
());
ifExists
=
readIfExists
(
ifExists
);
ifExists
=
readIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
if
(
readIf
(
"CASCADE"
))
{
ConstraintActionType
dropAction
=
parseCascadeOrRestrict
();
command
.
setDropAction
(
ConstraintActionType
.
CASCADE
);
if
(
dropAction
!=
null
)
{
}
else
if
(
readIf
(
"RESTRICT"
))
{
command
.
setDropAction
(
dropAction
);
command
.
setDropAction
(
ConstraintActionType
.
RESTRICT
);
}
}
return
command
;
return
command
;
}
else
if
(
readIf
(
"ALL"
))
{
}
else
if
(
readIf
(
"ALL"
))
{
...
@@ -1811,10 +1776,9 @@ public class Parser {
...
@@ -1811,10 +1776,9 @@ public class Parser {
command
.
setTypeName
(
readUniqueIdentifier
());
command
.
setTypeName
(
readUniqueIdentifier
());
ifExists
=
readIfExists
(
ifExists
);
ifExists
=
readIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
if
(
readIf
(
"CASCADE"
))
{
ConstraintActionType
dropAction
=
parseCascadeOrRestrict
();
command
.
setDropAction
(
ConstraintActionType
.
CASCADE
);
if
(
dropAction
!=
null
)
{
}
else
if
(
readIf
(
"RESTRICT"
))
{
command
.
setDropAction
(
dropAction
);
command
.
setDropAction
(
ConstraintActionType
.
RESTRICT
);
}
}
return
command
;
return
command
;
}
}
...
@@ -1951,10 +1915,9 @@ public class Parser {
...
@@ -1951,10 +1915,9 @@ public class Parser {
if
(
readIf
(
"("
))
{
if
(
readIf
(
"("
))
{
for
(
int
i
=
0
;;
i
++)
{
for
(
int
i
=
0
;;
i
++)
{
command
.
setExpression
(
i
,
readExpression
());
command
.
setExpression
(
i
,
readExpression
());
if
(
readIf
(
")"
))
{
if
(
!
readIfMore
(
true
))
{
break
;
break
;
}
}
read
(
","
);
}
}
}
}
return
command
;
return
command
;
...
@@ -2365,6 +2328,13 @@ public class Parser {
...
@@ -2365,6 +2328,13 @@ public class Parser {
command
.
setSQL
(
sql
);
command
.
setSQL
(
sql
);
}
}
private
Expression
readExpressionOrDefault
()
{
if
(
readIf
(
"DEFAULT"
))
{
return
ValueExpression
.
getDefault
();
}
return
readExpression
();
}
private
Expression
readExpression
()
{
private
Expression
readExpression
()
{
Expression
r
=
readAnd
();
Expression
r
=
readAnd
();
while
(
readIf
(
"OR"
))
{
while
(
readIf
(
"OR"
))
{
...
@@ -2697,12 +2667,8 @@ public class Parser {
...
@@ -2697,12 +2667,8 @@ public class Parser {
distinct
);
distinct
);
}
}
read
(
")"
);
read
(
")"
);
if
(
r
!=
null
&&
readIf
(
"FILTER"
))
{
if
(
r
!=
null
)
{
read
(
"("
);
r
.
setFilterCondition
(
readFilterCondition
());
read
(
"WHERE"
);
Expression
condition
=
readExpression
();
read
(
")"
);
r
.
setFilterCondition
(
condition
);
}
}
return
r
;
return
r
;
}
}
...
@@ -2735,12 +2701,10 @@ public class Parser {
...
@@ -2735,12 +2701,10 @@ public class Parser {
}
}
Expression
[]
args
;
Expression
[]
args
;
ArrayList
<
Expression
>
argList
=
Utils
.
newSmallArrayList
();
ArrayList
<
Expression
>
argList
=
Utils
.
newSmallArrayList
();
int
numArgs
=
0
;
if
(!
readIf
(
")"
))
{
while
(!
readIf
(
")"
))
{
do
{
if
(
numArgs
++
>
0
)
{
argList
.
add
(
readExpression
());
read
(
","
);
}
while
(
readIfMore
(
true
));
}
argList
.
add
(
readExpression
());
}
}
args
=
argList
.
toArray
(
new
Expression
[
0
]);
args
=
argList
.
toArray
(
new
Expression
[
0
]);
return
new
JavaFunction
(
functionAlias
,
args
);
return
new
JavaFunction
(
functionAlias
,
args
);
...
@@ -2752,19 +2716,22 @@ public class Parser {
...
@@ -2752,19 +2716,22 @@ public class Parser {
do
{
do
{
params
.
add
(
readExpression
());
params
.
add
(
readExpression
());
}
while
(
readIfMore
(
true
));
}
while
(
readIfMore
(
true
));
Expression
filterCondition
;
Expression
filterCondition
=
readFilterCondition
();
Expression
[]
list
=
params
.
toArray
(
new
Expression
[
0
]);
JavaAggregate
agg
=
new
JavaAggregate
(
aggregate
,
list
,
currentSelect
,
distinct
,
filterCondition
);
currentSelect
.
setGroupQuery
();
return
agg
;
}
private
Expression
readFilterCondition
()
{
if
(
readIf
(
"FILTER"
))
{
if
(
readIf
(
"FILTER"
))
{
read
(
"("
);
read
(
"("
);
read
(
"WHERE"
);
read
(
"WHERE"
);
filterCondition
=
readExpression
();
Expression
filterCondition
=
readExpression
();
read
(
")"
);
read
(
")"
);
}
else
{
return
filterCondition
;
filterCondition
=
null
;
}
}
Expression
[]
list
=
params
.
toArray
(
new
Expression
[
0
]);
return
null
;
JavaAggregate
agg
=
new
JavaAggregate
(
aggregate
,
list
,
currentSelect
,
distinct
,
filterCondition
);
currentSelect
.
setGroupQuery
();
return
agg
;
}
}
private
AggregateType
getAggregateType
(
String
name
)
{
private
AggregateType
getAggregateType
(
String
name
)
{
...
@@ -3303,12 +3270,10 @@ public class Parser {
...
@@ -3303,12 +3270,10 @@ public class Parser {
if
(
readIfMore
(
true
))
{
if
(
readIfMore
(
true
))
{
ArrayList
<
Expression
>
list
=
Utils
.
newSmallArrayList
();
ArrayList
<
Expression
>
list
=
Utils
.
newSmallArrayList
();
list
.
add
(
r
);
list
.
add
(
r
);
while
(!
readIf
(
")"
))
{
if
(!
readIf
(
")"
))
{
r
=
readExpression
();
do
{
list
.
add
(
r
);
list
.
add
(
readExpression
());
if
(!
readIfMore
(
true
))
{
}
while
(
readIfMore
(
false
));
break
;
}
}
}
r
=
new
ExpressionList
(
list
.
toArray
(
new
Expression
[
0
]));
r
=
new
ExpressionList
(
list
.
toArray
(
new
Expression
[
0
]));
}
}
...
@@ -3584,9 +3549,7 @@ public class Parser {
...
@@ -3584,9 +3549,7 @@ public class Parser {
}
}
private
boolean
isToken
(
String
token
)
{
private
boolean
isToken
(
String
token
)
{
boolean
result
=
equalsToken
(
token
,
currentToken
)
&&
if
(!
currentTokenQuoted
&&
equalsToken
(
token
,
currentToken
))
{
!
currentTokenQuoted
;
if
(
result
)
{
return
true
;
return
true
;
}
}
addExpected
(
token
);
addExpected
(
token
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论