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 {
do
{
Column
column
=
readTableColumn
(
filter
);
read
(
"="
);
Expression
expression
;
if
(
readIf
(
"DEFAULT"
))
{
expression
=
ValueExpression
.
getDefault
();
}
else
{
expression
=
readExpression
();
}
command
.
setAssignment
(
column
,
expression
);
command
.
setAssignment
(
column
,
readExpressionOrDefault
());
}
while
(
readIf
(
","
));
}
if
(
readIf
(
"WHERE"
))
{
...
...
@@ -1105,18 +1099,8 @@ public class Parser {
}
if
(
readIf
(
"VALUES"
))
{
do
{
ArrayList
<
Expression
>
values
=
Utils
.
newSmallArrayList
();
read
(
"("
);
if
(!
readIf
(
")"
))
{
do
{
if
(
readIf
(
"DEFAULT"
))
{
values
.
add
(
null
);
}
else
{
values
.
add
(
readExpression
());
}
}
while
(
readIfMore
(
false
));
}
command
.
addRow
(
values
.
toArray
(
new
Expression
[
0
]));
command
.
addRow
(
parseValuesForInsert
());
}
while
(
readIf
(
","
));
}
else
{
command
.
setQuery
(
parseSelect
());
...
...
@@ -1294,13 +1278,7 @@ public class Parser {
}
Column
column
=
table
.
getColumn
(
columnName
);
read
(
"="
);
Expression
expression
;
if
(
readIf
(
"DEFAULT"
))
{
expression
=
ValueExpression
.
getDefault
();
}
else
{
expression
=
readExpression
();
}
command
.
addAssignmentForDuplicate
(
column
,
expression
);
command
.
addAssignmentForDuplicate
(
column
,
readExpressionOrDefault
());
}
while
(
readIf
(
","
));
}
}
...
...
@@ -1334,17 +1312,7 @@ public class Parser {
}
else
if
(
readIf
(
"VALUES"
))
{
read
(
"("
);
do
{
ArrayList
<
Expression
>
values
=
Utils
.
newSmallArrayList
();
if
(!
readIf
(
")"
))
{
do
{
if
(
readIf
(
"DEFAULT"
))
{
values
.
add
(
null
);
}
else
{
values
.
add
(
readExpression
());
}
}
while
(
readIfMore
(
false
));
}
command
.
addRow
(
values
.
toArray
(
new
Expression
[
0
]));
command
.
addRow
(
parseValuesForInsert
());
// the following condition will allow (..),; and (..);
}
while
(
readIf
(
","
)
&&
readIf
(
"("
));
}
else
if
(
readIf
(
"SET"
))
{
...
...
@@ -1356,13 +1324,7 @@ public class Parser {
do
{
columnList
.
add
(
parseColumn
(
table
));
read
(
"="
);
Expression
expression
;
if
(
readIf
(
"DEFAULT"
))
{
expression
=
ValueExpression
.
getDefault
();
}
else
{
expression
=
readExpression
();
}
values
.
add
(
expression
);
values
.
add
(
readExpressionOrDefault
());
}
while
(
readIf
(
","
));
command
.
setColumns
(
columnList
.
toArray
(
new
Column
[
0
]));
command
.
addRow
(
values
.
toArray
(
new
Expression
[
0
]));
...
...
@@ -1392,8 +1354,17 @@ public class Parser {
}
if
(
readIf
(
"VALUES"
))
{
do
{
ArrayList
<
Expression
>
values
=
Utils
.
newSmallArrayList
();
read
(
"("
);
command
.
addRow
(
parseValuesForInsert
());
}
while
(
readIf
(
","
));
}
else
{
command
.
setQuery
(
parseSelect
());
}
return
command
;
}
private
Expression
[]
parseValuesForInsert
()
{
ArrayList
<
Expression
>
values
=
Utils
.
newSmallArrayList
();
if
(!
readIf
(
")"
))
{
do
{
if
(
readIf
(
"DEFAULT"
))
{
...
...
@@ -1403,12 +1374,7 @@ public class Parser {
}
}
while
(
readIfMore
(
false
));
}
command
.
addRow
(
values
.
toArray
(
new
Expression
[
0
]));
}
while
(
readIf
(
","
));
}
else
{
command
.
setQuery
(
parseSelect
());
}
return
command
;
return
values
.
toArray
(
new
Expression
[
0
]);
}
private
TableFilter
readTableFilter
()
{
...
...
@@ -1774,10 +1740,9 @@ public class Parser {
command
.
setSchemaName
(
readUniqueIdentifier
());
ifExists
=
readIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
if
(
readIf
(
"CASCADE"
))
{
command
.
setDropAction
(
ConstraintActionType
.
CASCADE
);
}
else
if
(
readIf
(
"RESTRICT"
))
{
command
.
setDropAction
(
ConstraintActionType
.
RESTRICT
);
ConstraintActionType
dropAction
=
parseCascadeOrRestrict
();
if
(
dropAction
!=
null
)
{
command
.
setDropAction
(
dropAction
);
}
return
command
;
}
else
if
(
readIf
(
"ALL"
))
{
...
...
@@ -1811,10 +1776,9 @@ public class Parser {
command
.
setTypeName
(
readUniqueIdentifier
());
ifExists
=
readIfExists
(
ifExists
);
command
.
setIfExists
(
ifExists
);
if
(
readIf
(
"CASCADE"
))
{
command
.
setDropAction
(
ConstraintActionType
.
CASCADE
);
}
else
if
(
readIf
(
"RESTRICT"
))
{
command
.
setDropAction
(
ConstraintActionType
.
RESTRICT
);
ConstraintActionType
dropAction
=
parseCascadeOrRestrict
();
if
(
dropAction
!=
null
)
{
command
.
setDropAction
(
dropAction
);
}
return
command
;
}
...
...
@@ -1951,10 +1915,9 @@ public class Parser {
if
(
readIf
(
"("
))
{
for
(
int
i
=
0
;;
i
++)
{
command
.
setExpression
(
i
,
readExpression
());
if
(
readIf
(
")"
))
{
if
(
!
readIfMore
(
true
))
{
break
;
}
read
(
","
);
}
}
return
command
;
...
...
@@ -2365,6 +2328,13 @@ public class Parser {
command
.
setSQL
(
sql
);
}
private
Expression
readExpressionOrDefault
()
{
if
(
readIf
(
"DEFAULT"
))
{
return
ValueExpression
.
getDefault
();
}
return
readExpression
();
}
private
Expression
readExpression
()
{
Expression
r
=
readAnd
();
while
(
readIf
(
"OR"
))
{
...
...
@@ -2697,12 +2667,8 @@ public class Parser {
distinct
);
}
read
(
")"
);
if
(
r
!=
null
&&
readIf
(
"FILTER"
))
{
read
(
"("
);
read
(
"WHERE"
);
Expression
condition
=
readExpression
();
read
(
")"
);
r
.
setFilterCondition
(
condition
);
if
(
r
!=
null
)
{
r
.
setFilterCondition
(
readFilterCondition
());
}
return
r
;
}
...
...
@@ -2735,12 +2701,10 @@ public class Parser {
}
Expression
[]
args
;
ArrayList
<
Expression
>
argList
=
Utils
.
newSmallArrayList
();
int
numArgs
=
0
;
while
(!
readIf
(
")"
))
{
if
(
numArgs
++
>
0
)
{
read
(
","
);
}
if
(!
readIf
(
")"
))
{
do
{
argList
.
add
(
readExpression
());
}
while
(
readIfMore
(
true
));
}
args
=
argList
.
toArray
(
new
Expression
[
0
]);
return
new
JavaFunction
(
functionAlias
,
args
);
...
...
@@ -2752,19 +2716,22 @@ public class Parser {
do
{
params
.
add
(
readExpression
());
}
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"
))
{
read
(
"("
);
read
(
"WHERE"
);
filterCondition
=
readExpression
();
Expression
filterCondition
=
readExpression
();
read
(
")"
);
}
else
{
filterCondition
=
null
;
return
filterCondition
;
}
Expression
[]
list
=
params
.
toArray
(
new
Expression
[
0
]);
JavaAggregate
agg
=
new
JavaAggregate
(
aggregate
,
list
,
currentSelect
,
distinct
,
filterCondition
);
currentSelect
.
setGroupQuery
();
return
agg
;
return
null
;
}
private
AggregateType
getAggregateType
(
String
name
)
{
...
...
@@ -3303,12 +3270,10 @@ public class Parser {
if
(
readIfMore
(
true
))
{
ArrayList
<
Expression
>
list
=
Utils
.
newSmallArrayList
();
list
.
add
(
r
);
while
(!
readIf
(
")"
))
{
r
=
readExpression
();
list
.
add
(
r
);
if
(!
readIfMore
(
true
))
{
break
;
}
if
(!
readIf
(
")"
))
{
do
{
list
.
add
(
readExpression
());
}
while
(
readIfMore
(
false
));
}
r
=
new
ExpressionList
(
list
.
toArray
(
new
Expression
[
0
]));
}
...
...
@@ -3584,9 +3549,7 @@ public class Parser {
}
private
boolean
isToken
(
String
token
)
{
boolean
result
=
equalsToken
(
token
,
currentToken
)
&&
!
currentTokenQuoted
;
if
(
result
)
{
if
(!
currentTokenQuoted
&&
equalsToken
(
token
,
currentToken
))
{
return
true
;
}
addExpected
(
token
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论