Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ee230d05
提交
ee230d05
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add few more token types
上级
94d97acd
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
94 行增加
和
71 行删除
+94
-71
Parser.java
h2/src/main/org/h2/command/Parser.java
+94
-71
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
ee230d05
...
@@ -310,6 +310,21 @@ public class Parser {
...
@@ -310,6 +310,21 @@ public class Parser {
*/
*/
private
static
final
int
SPATIAL_INTERSECTS
=
CLOSE_PAREN
+
1
;
private
static
final
int
SPATIAL_INTERSECTS
=
CLOSE_PAREN
+
1
;
/**
* The token "*".
*/
private
static
final
int
ASTERISK
=
SPATIAL_INTERSECTS
+
1
;
/**
* The token ",".
*/
private
static
final
int
COMMA
=
ASTERISK
+
1
;
/**
* The token ".".
*/
private
static
final
int
DOT
=
COMMA
+
1
;
private
static
final
String
[]
TOKENS
=
{
private
static
final
String
[]
TOKENS
=
{
// Unused
// Unused
null
,
null
,
...
@@ -427,6 +442,12 @@ public class Parser {
...
@@ -427,6 +442,12 @@ public class Parser {
")"
,
")"
,
// SPATIAL_INTERSECTS
// SPATIAL_INTERSECTS
"&&"
,
"&&"
,
// ASTERISK
"*"
,
// COMMA
","
,
// DOT
"."
,
// End
// End
};
};
...
@@ -758,7 +779,7 @@ public class Parser {
...
@@ -758,7 +779,7 @@ public class Parser {
Expression
expr
=
readExpression
();
Expression
expr
=
readExpression
();
expr
=
expr
.
optimize
(
session
);
expr
=
expr
.
optimize
(
session
);
p
.
setValue
(
expr
.
getValue
(
session
));
p
.
setValue
(
expr
.
getValue
(
session
));
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
read
(
"}"
);
read
(
"}"
);
for
(
Parameter
p
:
parameters
)
{
for
(
Parameter
p
:
parameters
)
{
p
.
checkSet
();
p
.
checkSet
();
...
@@ -960,14 +981,14 @@ public class Parser {
...
@@ -960,14 +981,14 @@ public class Parser {
private
Column
readTableColumn
(
TableFilter
filter
)
{
private
Column
readTableColumn
(
TableFilter
filter
)
{
String
columnName
=
readColumnIdentifier
();
String
columnName
=
readColumnIdentifier
();
if
(
readIf
(
"."
))
{
if
(
readIf
(
DOT
))
{
String
tableAlias
=
columnName
;
String
tableAlias
=
columnName
;
columnName
=
readColumnIdentifier
();
columnName
=
readColumnIdentifier
();
if
(
readIf
(
"."
))
{
if
(
readIf
(
DOT
))
{
String
schema
=
tableAlias
;
String
schema
=
tableAlias
;
tableAlias
=
columnName
;
tableAlias
=
columnName
;
columnName
=
readColumnIdentifier
();
columnName
=
readColumnIdentifier
();
if
(
readIf
(
"."
))
{
if
(
readIf
(
DOT
))
{
String
catalogName
=
schema
;
String
catalogName
=
schema
;
schema
=
tableAlias
;
schema
=
tableAlias
;
tableAlias
=
columnName
;
tableAlias
=
columnName
;
...
@@ -1033,7 +1054,7 @@ public class Parser {
...
@@ -1033,7 +1054,7 @@ public class Parser {
Column
column
=
readTableColumn
(
filter
);
Column
column
=
readTableColumn
(
filter
);
read
(
EQUAL
);
read
(
EQUAL
);
command
.
setAssignment
(
column
,
readExpressionOrDefault
());
command
.
setAssignment
(
column
,
readExpressionOrDefault
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
}
}
if
(
readIf
(
WHERE
))
{
if
(
readIf
(
WHERE
))
{
Expression
condition
=
readExpression
();
Expression
condition
=
readExpression
();
...
@@ -1168,7 +1189,7 @@ public class Parser {
...
@@ -1168,7 +1189,7 @@ public class Parser {
* @return {@code true} if comma is read, {@code false} if brace is read
* @return {@code true} if comma is read, {@code false} if brace is read
*/
*/
private
boolean
readIfMore
(
boolean
strict
)
{
private
boolean
readIfMore
(
boolean
strict
)
{
if
(
readIf
(
","
))
{
if
(
readIf
(
COMMA
))
{
return
strict
||
!
readIf
(
CLOSE_PAREN
);
return
strict
||
!
readIf
(
CLOSE_PAREN
);
}
}
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
...
@@ -1326,7 +1347,7 @@ public class Parser {
...
@@ -1326,7 +1347,7 @@ public class Parser {
do
{
do
{
read
(
OPEN_PAREN
);
read
(
OPEN_PAREN
);
command
.
addRow
(
parseValuesForInsert
());
command
.
addRow
(
parseValuesForInsert
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
}
else
{
}
else
{
command
.
setQuery
(
parseSelect
());
command
.
setQuery
(
parseSelect
());
}
}
...
@@ -1485,10 +1506,10 @@ public class Parser {
...
@@ -1485,10 +1506,10 @@ public class Parser {
read
(
"UPDATE"
);
read
(
"UPDATE"
);
do
{
do
{
String
columnName
=
readColumnIdentifier
();
String
columnName
=
readColumnIdentifier
();
if
(
readIf
(
"."
))
{
if
(
readIf
(
DOT
))
{
String
schemaOrTableName
=
columnName
;
String
schemaOrTableName
=
columnName
;
String
tableOrColumnName
=
readColumnIdentifier
();
String
tableOrColumnName
=
readColumnIdentifier
();
if
(
readIf
(
"."
))
{
if
(
readIf
(
DOT
))
{
if
(!
table
.
getSchema
().
getName
().
equals
(
schemaOrTableName
))
{
if
(!
table
.
getSchema
().
getName
().
equals
(
schemaOrTableName
))
{
throw
DbException
.
get
(
ErrorCode
.
SCHEMA_NAME_MUST_MATCH
);
throw
DbException
.
get
(
ErrorCode
.
SCHEMA_NAME_MUST_MATCH
);
}
}
...
@@ -1504,7 +1525,7 @@ public class Parser {
...
@@ -1504,7 +1525,7 @@ public class Parser {
Column
column
=
table
.
getColumn
(
columnName
);
Column
column
=
table
.
getColumn
(
columnName
);
read
(
EQUAL
);
read
(
EQUAL
);
command
.
addAssignmentForDuplicate
(
column
,
readExpressionOrDefault
());
command
.
addAssignmentForDuplicate
(
column
,
readExpressionOrDefault
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
}
}
}
}
if
(
database
.
getMode
().
isolationLevelInSelectOrInsertStatement
)
{
if
(
database
.
getMode
().
isolationLevelInSelectOrInsertStatement
)
{
...
@@ -1539,7 +1560,7 @@ public class Parser {
...
@@ -1539,7 +1560,7 @@ public class Parser {
do
{
do
{
command
.
addRow
(
parseValuesForInsert
());
command
.
addRow
(
parseValuesForInsert
());
// the following condition will allow (..),; and (..);
// the following condition will allow (..),; and (..);
}
while
(
readIf
(
","
)
&&
readIf
(
OPEN_PAREN
));
}
while
(
readIf
(
COMMA
)
&&
readIf
(
OPEN_PAREN
));
}
else
if
(
readIf
(
"SET"
))
{
}
else
if
(
readIf
(
"SET"
))
{
if
(
columns
!=
null
)
{
if
(
columns
!=
null
)
{
throw
getSyntaxError
();
throw
getSyntaxError
();
...
@@ -1550,7 +1571,7 @@ public class Parser {
...
@@ -1550,7 +1571,7 @@ public class Parser {
columnList
.
add
(
parseColumn
(
table
));
columnList
.
add
(
parseColumn
(
table
));
read
(
EQUAL
);
read
(
EQUAL
);
values
.
add
(
readExpressionOrDefault
());
values
.
add
(
readExpressionOrDefault
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
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
]));
}
else
{
}
else
{
...
@@ -1581,7 +1602,7 @@ public class Parser {
...
@@ -1581,7 +1602,7 @@ public class Parser {
do
{
do
{
read
(
OPEN_PAREN
);
read
(
OPEN_PAREN
);
command
.
addRow
(
parseValuesForInsert
());
command
.
addRow
(
parseValuesForInsert
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
}
else
{
}
else
{
command
.
setQuery
(
parseSelect
());
command
.
setQuery
(
parseSelect
());
}
}
...
@@ -1665,9 +1686,9 @@ public class Parser {
...
@@ -1665,9 +1686,9 @@ public class Parser {
if
(
equalsToken
(
tableName
,
RangeTable
.
NAME
)
if
(
equalsToken
(
tableName
,
RangeTable
.
NAME
)
||
equalsToken
(
tableName
,
RangeTable
.
ALIAS
))
{
||
equalsToken
(
tableName
,
RangeTable
.
ALIAS
))
{
Expression
min
=
readExpression
();
Expression
min
=
readExpression
();
read
(
","
);
read
(
COMMA
);
Expression
max
=
readExpression
();
Expression
max
=
readExpression
();
if
(
readIf
(
","
))
{
if
(
readIf
(
COMMA
))
{
Expression
step
=
readExpression
();
Expression
step
=
readExpression
();
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
table
=
new
RangeTable
(
mainSchema
,
min
,
max
,
step
,
table
=
new
RangeTable
(
mainSchema
,
min
,
max
,
step
,
...
@@ -1835,7 +1856,7 @@ public class Parser {
...
@@ -1835,7 +1856,7 @@ public class Parser {
ArrayList
<
String
>
list
=
Utils
.
newSmallArrayList
();
ArrayList
<
String
>
list
=
Utils
.
newSmallArrayList
();
do
{
do
{
list
.
add
(
readUniqueIdentifier
());
list
.
add
(
readUniqueIdentifier
());
}
while
(
readIf
(
"."
));
}
while
(
readIf
(
DOT
));
schemaName
=
session
.
getCurrentSchemaName
();
schemaName
=
session
.
getCurrentSchemaName
();
if
(
list
.
size
()
==
4
)
{
if
(
list
.
size
()
==
4
)
{
if
(!
equalsToken
(
database
.
getShortName
(),
list
.
remove
(
0
)))
{
if
(!
equalsToken
(
database
.
getShortName
(),
list
.
remove
(
0
)))
{
...
@@ -1870,7 +1891,7 @@ public class Parser {
...
@@ -1870,7 +1891,7 @@ public class Parser {
String
tableName
=
readIdentifierWithSchema
();
String
tableName
=
readIdentifierWithSchema
();
DropTable
command
=
new
DropTable
(
session
,
getSchema
());
DropTable
command
=
new
DropTable
(
session
,
getSchema
());
command
.
setTableName
(
tableName
);
command
.
setTableName
(
tableName
);
while
(
readIf
(
","
))
{
while
(
readIf
(
COMMA
))
{
tableName
=
readIdentifierWithSchema
();
tableName
=
readIdentifierWithSchema
();
DropTable
next
=
new
DropTable
(
session
,
getSchema
());
DropTable
next
=
new
DropTable
(
session
,
getSchema
());
next
.
setTableName
(
tableName
);
next
.
setTableName
(
tableName
);
...
@@ -2275,7 +2296,7 @@ public class Parser {
...
@@ -2275,7 +2296,7 @@ public class Parser {
}
}
order
.
sortType
=
parseSortType
();
order
.
sortType
=
parseSortType
();
orderList
.
add
(
order
);
orderList
.
add
(
order
);
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
command
.
setOrder
(
orderList
);
command
.
setOrder
(
orderList
);
currentSelect
=
oldSelect
;
currentSelect
=
oldSelect
;
}
}
...
@@ -2314,7 +2335,7 @@ public class Parser {
...
@@ -2314,7 +2335,7 @@ public class Parser {
if
(
readIf
(
OFFSET
))
{
if
(
readIf
(
OFFSET
))
{
Expression
offset
=
readExpression
().
optimize
(
session
);
Expression
offset
=
readExpression
().
optimize
(
session
);
command
.
setOffset
(
offset
);
command
.
setOffset
(
offset
);
}
else
if
(
readIf
(
","
))
{
}
else
if
(
readIf
(
COMMA
))
{
// MySQL: [offset, ] rowcount
// MySQL: [offset, ] rowcount
Expression
offset
=
limit
;
Expression
offset
=
limit
;
limit
=
readExpression
().
optimize
(
session
);
limit
=
readExpression
().
optimize
(
session
);
...
@@ -2332,7 +2353,7 @@ public class Parser {
...
@@ -2332,7 +2353,7 @@ public class Parser {
if
(
readIf
(
"OF"
))
{
if
(
readIf
(
"OF"
))
{
do
{
do
{
readIdentifierWithSchema
();
readIdentifierWithSchema
();
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
}
else
if
(
readIf
(
"NOWAIT"
))
{
}
else
if
(
readIf
(
"NOWAIT"
))
{
// TODO parser: select for update nowait: should not wait
// TODO parser: select for update nowait: should not wait
}
}
...
@@ -2393,7 +2414,7 @@ public class Parser {
...
@@ -2393,7 +2414,7 @@ public class Parser {
do
{
do
{
TableFilter
filter
=
readTableFilter
();
TableFilter
filter
=
readTableFilter
();
parseJoinTableFilter
(
filter
,
command
);
parseJoinTableFilter
(
filter
,
command
);
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
// Parser can reorder joined table filters, need to explicitly sort them
// Parser can reorder joined table filters, need to explicitly sort them
// to get the order as it was in the original query.
// to get the order as it was in the original query.
...
@@ -2462,7 +2483,7 @@ public class Parser {
...
@@ -2462,7 +2483,7 @@ public class Parser {
}
}
ArrayList
<
Expression
>
expressions
=
Utils
.
newSmallArrayList
();
ArrayList
<
Expression
>
expressions
=
Utils
.
newSmallArrayList
();
do
{
do
{
if
(
readIf
(
"*"
))
{
if
(
readIf
(
ASTERISK
))
{
expressions
.
add
(
new
Wildcard
(
null
,
null
));
expressions
.
add
(
new
Wildcard
(
null
,
null
));
}
else
{
}
else
{
Expression
expr
=
readExpression
();
Expression
expr
=
readExpression
();
...
@@ -2474,7 +2495,7 @@ public class Parser {
...
@@ -2474,7 +2495,7 @@ public class Parser {
}
}
expressions
.
add
(
expr
);
expressions
.
add
(
expr
);
}
}
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
command
.
setExpressions
(
expressions
);
command
.
setExpressions
(
expressions
);
}
}
...
@@ -2524,7 +2545,7 @@ public class Parser {
...
@@ -2524,7 +2545,7 @@ public class Parser {
do
{
do
{
Expression
expr
=
readExpression
();
Expression
expr
=
readExpression
();
list
.
add
(
expr
);
list
.
add
(
expr
);
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
command
.
setGroupBy
(
list
);
command
.
setGroupBy
(
list
);
}
}
currentSelect
=
command
;
currentSelect
=
command
;
...
@@ -2591,7 +2612,7 @@ public class Parser {
...
@@ -2591,7 +2612,7 @@ public class Parser {
if
(
readIf
(
"INTERSECTS"
))
{
if
(
readIf
(
"INTERSECTS"
))
{
read
(
OPEN_PAREN
);
read
(
OPEN_PAREN
);
Expression
r1
=
readConcat
();
Expression
r1
=
readConcat
();
read
(
","
);
read
(
COMMA
);
Expression
r2
=
readConcat
();
Expression
r2
=
readConcat
();
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
return
new
Comparison
(
session
,
Comparison
.
SPATIAL_INTERSECTS
,
r1
,
return
new
Comparison
(
session
,
Comparison
.
SPATIAL_INTERSECTS
,
r1
,
...
@@ -2682,7 +2703,7 @@ public class Parser {
...
@@ -2682,7 +2703,7 @@ public class Parser {
do
{
do
{
last
=
readExpression
();
last
=
readExpression
();
v
.
add
(
last
);
v
.
add
(
last
);
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
if
(
v
.
size
()
==
1
&&
(
last
instanceof
Subquery
))
{
if
(
v
.
size
()
==
1
&&
(
last
instanceof
Subquery
))
{
Subquery
s
=
(
Subquery
)
last
;
Subquery
s
=
(
Subquery
)
last
;
Query
q
=
s
.
getQuery
();
Query
q
=
s
.
getQuery
();
...
@@ -2777,7 +2798,7 @@ public class Parser {
...
@@ -2777,7 +2798,7 @@ public class Parser {
if
(
readIf
(
STRING_CONCAT
))
{
if
(
readIf
(
STRING_CONCAT
))
{
r
=
new
Operation
(
OpType
.
CONCAT
,
r
,
readSum
());
r
=
new
Operation
(
OpType
.
CONCAT
,
r
,
readSum
());
}
else
if
(
readIf
(
"~"
))
{
}
else
if
(
readIf
(
"~"
))
{
if
(
readIf
(
"*"
))
{
if
(
readIf
(
ASTERISK
))
{
Function
function
=
Function
.
getFunction
(
database
,
"CAST"
);
Function
function
=
Function
.
getFunction
(
database
,
"CAST"
);
function
.
setDataType
(
new
Column
(
"X"
,
function
.
setDataType
(
new
Column
(
"X"
,
Value
.
STRING_IGNORECASE
));
Value
.
STRING_IGNORECASE
));
...
@@ -2786,7 +2807,7 @@ public class Parser {
...
@@ -2786,7 +2807,7 @@ public class Parser {
}
}
r
=
new
CompareLike
(
database
,
r
,
readSum
(),
null
,
true
);
r
=
new
CompareLike
(
database
,
r
,
readSum
(),
null
,
true
);
}
else
if
(
readIf
(
"!~"
))
{
}
else
if
(
readIf
(
"!~"
))
{
if
(
readIf
(
"*"
))
{
if
(
readIf
(
ASTERISK
))
{
Function
function
=
Function
.
getFunction
(
database
,
"CAST"
);
Function
function
=
Function
.
getFunction
(
database
,
"CAST"
);
function
.
setDataType
(
new
Column
(
"X"
,
function
.
setDataType
(
new
Column
(
"X"
,
Value
.
STRING_IGNORECASE
));
Value
.
STRING_IGNORECASE
));
...
@@ -2817,7 +2838,7 @@ public class Parser {
...
@@ -2817,7 +2838,7 @@ public class Parser {
private
Expression
readFactor
()
{
private
Expression
readFactor
()
{
Expression
r
=
readTerm
();
Expression
r
=
readTerm
();
while
(
true
)
{
while
(
true
)
{
if
(
readIf
(
"*"
))
{
if
(
readIf
(
ASTERISK
))
{
r
=
new
Operation
(
OpType
.
MULTIPLY
,
r
,
readTerm
());
r
=
new
Operation
(
OpType
.
MULTIPLY
,
r
,
readTerm
());
}
else
if
(
readIf
(
"/"
))
{
}
else
if
(
readIf
(
"/"
))
{
r
=
new
Operation
(
OpType
.
DIVIDE
,
r
,
readTerm
());
r
=
new
Operation
(
OpType
.
DIVIDE
,
r
,
readTerm
());
...
@@ -2836,7 +2857,7 @@ public class Parser {
...
@@ -2836,7 +2857,7 @@ public class Parser {
currentSelect
.
setGroupQuery
();
currentSelect
.
setGroupQuery
();
Aggregate
r
;
Aggregate
r
;
if
(
aggregateType
==
AggregateType
.
COUNT
)
{
if
(
aggregateType
==
AggregateType
.
COUNT
)
{
if
(
readIf
(
"*"
))
{
if
(
readIf
(
ASTERISK
))
{
r
=
new
Aggregate
(
AggregateType
.
COUNT_ALL
,
null
,
currentSelect
,
r
=
new
Aggregate
(
AggregateType
.
COUNT_ALL
,
null
,
currentSelect
,
false
);
false
);
}
else
{
}
else
{
...
@@ -2869,7 +2890,7 @@ public class Parser {
...
@@ -2869,7 +2890,7 @@ public class Parser {
// PostgreSQL compatibility: string_agg(expression, delimiter)
// PostgreSQL compatibility: string_agg(expression, delimiter)
r
=
new
Aggregate
(
AggregateType
.
GROUP_CONCAT
,
r
=
new
Aggregate
(
AggregateType
.
GROUP_CONCAT
,
readExpression
(),
currentSelect
,
distinct
);
readExpression
(),
currentSelect
,
distinct
);
read
(
","
);
read
(
COMMA
);
r
.
setGroupConcatSeparator
(
readExpression
());
r
.
setGroupConcatSeparator
(
readExpression
());
if
(
readIf
(
ORDER
))
{
if
(
readIf
(
ORDER
))
{
read
(
"BY"
);
read
(
"BY"
);
...
@@ -2906,7 +2927,7 @@ public class Parser {
...
@@ -2906,7 +2927,7 @@ public class Parser {
order
.
expression
=
readExpression
();
order
.
expression
=
readExpression
();
order
.
sortType
=
parseSortType
();
order
.
sortType
=
parseSortType
();
orderList
.
add
(
order
);
orderList
.
add
(
order
);
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
return
orderList
;
return
orderList
;
}
}
...
@@ -3007,12 +3028,12 @@ public class Parser {
...
@@ -3007,12 +3028,12 @@ public class Parser {
if
(
database
.
getMode
().
swapConvertFunctionParameters
)
{
if
(
database
.
getMode
().
swapConvertFunctionParameters
)
{
Column
type
=
parseColumnWithType
(
null
,
false
);
Column
type
=
parseColumnWithType
(
null
,
false
);
function
.
setDataType
(
type
);
function
.
setDataType
(
type
);
read
(
","
);
read
(
COMMA
);
function
.
setParameter
(
0
,
readExpression
());
function
.
setParameter
(
0
,
readExpression
());
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
}
else
{
}
else
{
function
.
setParameter
(
0
,
readExpression
());
function
.
setParameter
(
0
,
readExpression
());
read
(
","
);
read
(
COMMA
);
Column
type
=
parseColumnWithType
(
null
,
false
);
Column
type
=
parseColumnWithType
(
null
,
false
);
function
.
setDataType
(
type
);
function
.
setDataType
(
type
);
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
...
@@ -3037,9 +3058,9 @@ public class Parser {
...
@@ -3037,9 +3058,9 @@ public class Parser {
}
else
{
}
else
{
function
.
setParameter
(
0
,
readExpression
());
function
.
setParameter
(
0
,
readExpression
());
}
}
read
(
","
);
read
(
COMMA
);
function
.
setParameter
(
1
,
readExpression
());
function
.
setParameter
(
1
,
readExpression
());
read
(
","
);
read
(
COMMA
);
function
.
setParameter
(
2
,
readExpression
());
function
.
setParameter
(
2
,
readExpression
());
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
break
;
break
;
...
@@ -3061,9 +3082,9 @@ public class Parser {
...
@@ -3061,9 +3082,9 @@ public class Parser {
function
.
setParameter
(
1
,
ValueExpression
.
get
(
ValueInt
.
get
(
0
)));
function
.
setParameter
(
1
,
ValueExpression
.
get
(
ValueInt
.
get
(
0
)));
function
.
setParameter
(
2
,
readExpression
());
function
.
setParameter
(
2
,
readExpression
());
}
else
{
}
else
{
read
(
","
);
read
(
COMMA
);
function
.
setParameter
(
1
,
readExpression
());
function
.
setParameter
(
1
,
readExpression
());
if
(
readIf
(
","
))
{
if
(
readIf
(
COMMA
))
{
function
.
setParameter
(
2
,
readExpression
());
function
.
setParameter
(
2
,
readExpression
());
}
}
}
}
...
@@ -3073,7 +3094,7 @@ public class Parser {
...
@@ -3073,7 +3094,7 @@ public class Parser {
case
Function
.
POSITION
:
{
case
Function
.
POSITION
:
{
// can't read expression because IN would be read too early
// can't read expression because IN would be read too early
function
.
setParameter
(
0
,
readConcat
());
function
.
setParameter
(
0
,
readConcat
());
if
(!
readIf
(
","
))
{
if
(!
readIf
(
COMMA
))
{
read
(
"IN"
);
read
(
"IN"
);
}
}
function
.
setParameter
(
1
,
readExpression
());
function
.
setParameter
(
1
,
readExpression
());
...
@@ -3101,7 +3122,7 @@ public class Parser {
...
@@ -3101,7 +3122,7 @@ public class Parser {
}
}
}
}
Expression
p0
=
readExpression
();
Expression
p0
=
readExpression
();
if
(
readIf
(
","
))
{
if
(
readIf
(
COMMA
))
{
space
=
readExpression
();
space
=
readExpression
();
}
else
if
(
readIf
(
FROM
))
{
}
else
if
(
readIf
(
FROM
))
{
space
=
p0
;
space
=
p0
;
...
@@ -3169,7 +3190,7 @@ public class Parser {
...
@@ -3169,7 +3190,7 @@ public class Parser {
private
Expression
readWildcardOrSequenceValue
(
String
schema
,
private
Expression
readWildcardOrSequenceValue
(
String
schema
,
String
objectName
)
{
String
objectName
)
{
if
(
readIf
(
"*"
))
{
if
(
readIf
(
ASTERISK
))
{
return
new
Wildcard
(
schema
,
objectName
);
return
new
Wildcard
(
schema
,
objectName
);
}
}
if
(
schema
==
null
)
{
if
(
schema
==
null
)
{
...
@@ -3209,7 +3230,7 @@ public class Parser {
...
@@ -3209,7 +3230,7 @@ public class Parser {
// this additional check is not required
// this additional check is not required
// if the old style outer joins are not supported
// if the old style outer joins are not supported
return
readFunction
(
s
,
name
);
return
readFunction
(
s
,
name
);
}
else
if
(
readIf
(
"."
))
{
}
else
if
(
readIf
(
DOT
))
{
String
schema
=
objectName
;
String
schema
=
objectName
;
objectName
=
name
;
objectName
=
name
;
expr
=
readWildcardOrSequenceValue
(
schema
,
objectName
);
expr
=
readWildcardOrSequenceValue
(
schema
,
objectName
);
...
@@ -3225,7 +3246,7 @@ public class Parser {
...
@@ -3225,7 +3246,7 @@ public class Parser {
}
}
schema
=
objectName
;
schema
=
objectName
;
return
readFunction
(
database
.
getSchema
(
schema
),
name
);
return
readFunction
(
database
.
getSchema
(
schema
),
name
);
}
else
if
(
readIf
(
"."
))
{
}
else
if
(
readIf
(
DOT
))
{
String
databaseName
=
schema
;
String
databaseName
=
schema
;
if
(!
equalsToken
(
database
.
getShortName
(),
databaseName
))
{
if
(!
equalsToken
(
database
.
getShortName
(),
databaseName
))
{
throw
DbException
.
get
(
ErrorCode
.
DATABASE_NOT_FOUND_1
,
throw
DbException
.
get
(
ErrorCode
.
DATABASE_NOT_FOUND_1
,
...
@@ -3322,14 +3343,14 @@ public class Parser {
...
@@ -3322,14 +3343,14 @@ public class Parser {
read
();
read
();
if
(
readIf
(
OPEN_PAREN
))
{
if
(
readIf
(
OPEN_PAREN
))
{
r
=
readFunction
(
null
,
name
);
r
=
readFunction
(
null
,
name
);
}
else
if
(
readIf
(
"."
))
{
}
else
if
(
readIf
(
DOT
))
{
r
=
readTermObjectDot
(
name
);
r
=
readTermObjectDot
(
name
);
}
else
{
}
else
{
r
=
new
ExpressionColumn
(
database
,
null
,
null
,
name
);
r
=
new
ExpressionColumn
(
database
,
null
,
null
,
name
);
}
}
}
else
{
}
else
{
read
();
read
();
if
(
readIf
(
"."
))
{
if
(
readIf
(
DOT
))
{
r
=
readTermObjectDot
(
name
);
r
=
readTermObjectDot
(
name
);
}
else
if
(
equalsToken
(
"CASE"
,
name
))
{
}
else
if
(
equalsToken
(
"CASE"
,
name
))
{
// CASE must be processed before (,
// CASE must be processed before (,
...
@@ -3548,7 +3569,7 @@ public class Parser {
...
@@ -3548,7 +3569,7 @@ public class Parser {
// PostgreSQL compatibility
// PostgreSQL compatibility
if
(
isToken
(
"PG_CATALOG"
))
{
if
(
isToken
(
"PG_CATALOG"
))
{
read
(
"PG_CATALOG"
);
read
(
"PG_CATALOG"
);
read
(
"."
);
read
(
DOT
);
}
}
if
(
readIf
(
"REGCLASS"
))
{
if
(
readIf
(
"REGCLASS"
))
{
FunctionAlias
f
=
findFunctionAlias
(
Constants
.
SCHEMA_MAIN
,
FunctionAlias
f
=
findFunctionAlias
(
Constants
.
SCHEMA_MAIN
,
...
@@ -3710,7 +3731,7 @@ public class Parser {
...
@@ -3710,7 +3731,7 @@ public class Parser {
String
s
=
currentToken
;
String
s
=
currentToken
;
read
();
read
();
schemaName
=
defaultSchemaName
;
schemaName
=
defaultSchemaName
;
if
(
readIf
(
"."
))
{
if
(
readIf
(
DOT
))
{
schemaName
=
s
;
schemaName
=
s
;
if
(
currentTokenType
!=
IDENTIFIER
)
{
if
(
currentTokenType
!=
IDENTIFIER
)
{
throw
DbException
.
getSyntaxError
(
sqlCommand
,
parseIndex
,
throw
DbException
.
getSyntaxError
(
sqlCommand
,
parseIndex
,
...
@@ -3719,9 +3740,9 @@ public class Parser {
...
@@ -3719,9 +3740,9 @@ public class Parser {
s
=
currentToken
;
s
=
currentToken
;
read
();
read
();
}
}
if
(
equalsToken
(
"."
,
currentToken
)
)
{
if
(
currentTokenType
==
DOT
)
{
if
(
equalsToken
(
schemaName
,
database
.
getShortName
()))
{
if
(
equalsToken
(
schemaName
,
database
.
getShortName
()))
{
read
(
"."
);
read
(
DOT
);
schemaName
=
s
;
schemaName
=
s
;
if
(
currentTokenType
!=
IDENTIFIER
)
{
if
(
currentTokenType
!=
IDENTIFIER
)
{
throw
DbException
.
getSyntaxError
(
sqlCommand
,
parseIndex
,
throw
DbException
.
getSyntaxError
(
sqlCommand
,
parseIndex
,
...
@@ -3954,7 +3975,7 @@ public class Parser {
...
@@ -3954,7 +3975,7 @@ public class Parser {
return
;
return
;
case
CHAR_DOT:
case
CHAR_DOT:
if
(
types
[
i
]
!=
CHAR_VALUE
)
{
if
(
types
[
i
]
!=
CHAR_VALUE
)
{
currentTokenType
=
KEYWORD
;
currentTokenType
=
DOT
;
currentToken
=
"."
;
currentToken
=
"."
;
parseIndex
=
i
;
parseIndex
=
i
;
return
;
return
;
...
@@ -4344,13 +4365,15 @@ public class Parser {
...
@@ -4344,13 +4365,15 @@ public class Parser {
return
PLUS_SIGN
;
return
PLUS_SIGN
;
case
'-'
:
case
'-'
:
return
MINUS_SIGN
;
return
MINUS_SIGN
;
case
'*'
:
return
ASTERISK
;
case
','
:
return
COMMA
;
case
'{'
:
case
'{'
:
case
'}'
:
case
'}'
:
case
'*'
:
case
'/'
:
case
'/'
:
case
'%'
:
case
'%'
:
case
';'
:
case
';'
:
case
','
:
case
':'
:
case
':'
:
case
'['
:
case
'['
:
case
']'
:
case
']'
:
...
@@ -4502,7 +4525,7 @@ public class Parser {
...
@@ -4502,7 +4525,7 @@ public class Parser {
read
(
"START"
);
read
(
"START"
);
readIf
(
WITH
);
readIf
(
WITH
);
start
=
readLong
();
start
=
readLong
();
readIf
(
","
);
readIf
(
COMMA
);
if
(
readIf
(
"INCREMENT"
))
{
if
(
readIf
(
"INCREMENT"
))
{
readIf
(
"BY"
);
readIf
(
"BY"
);
increment
=
readLong
();
increment
=
readLong
();
...
@@ -4550,7 +4573,7 @@ public class Parser {
...
@@ -4550,7 +4573,7 @@ public class Parser {
long
start
=
1
,
increment
=
1
;
long
start
=
1
,
increment
=
1
;
if
(
readIf
(
OPEN_PAREN
))
{
if
(
readIf
(
OPEN_PAREN
))
{
start
=
readLong
();
start
=
readLong
();
if
(
readIf
(
","
))
{
if
(
readIf
(
COMMA
))
{
increment
=
readLong
();
increment
=
readLong
();
}
}
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
...
@@ -4599,7 +4622,7 @@ public class Parser {
...
@@ -4599,7 +4622,7 @@ public class Parser {
if
(
readIf
(
OPEN_PAREN
))
{
if
(
readIf
(
OPEN_PAREN
))
{
originalScale
=
readNonNegativeInt
();
originalScale
=
readNonNegativeInt
();
// Allow non-standard TIMESTAMP(..., ...) syntax
// Allow non-standard TIMESTAMP(..., ...) syntax
if
(
readIf
(
","
))
{
if
(
readIf
(
COMMA
))
{
originalScale
=
readNonNegativeInt
();
originalScale
=
readNonNegativeInt
();
}
}
if
(
originalScale
>
ValueTimestamp
.
MAXIMUM_SCALE
)
{
if
(
originalScale
>
ValueTimestamp
.
MAXIMUM_SCALE
)
{
...
@@ -4721,7 +4744,7 @@ public class Parser {
...
@@ -4721,7 +4744,7 @@ public class Parser {
readIf
(
"BYTE"
);
readIf
(
"BYTE"
);
}
}
if
(
dataType
.
supportsScale
)
{
if
(
dataType
.
supportsScale
)
{
if
(
readIf
(
","
))
{
if
(
readIf
(
COMMA
))
{
scale
=
readInt
();
scale
=
readInt
();
original
+=
", "
+
scale
;
original
+=
", "
+
scale
;
}
else
{
}
else
{
...
@@ -4989,7 +5012,7 @@ public class Parser {
...
@@ -4989,7 +5012,7 @@ public class Parser {
GrantRevoke
command
=
new
GrantRevoke
(
session
);
GrantRevoke
command
=
new
GrantRevoke
(
session
);
command
.
setOperationType
(
operationType
);
command
.
setOperationType
(
operationType
);
boolean
tableClauseExpected
=
addRoleOrRight
(
command
);
boolean
tableClauseExpected
=
addRoleOrRight
(
command
);
while
(
readIf
(
","
))
{
while
(
readIf
(
COMMA
))
{
addRoleOrRight
(
command
);
addRoleOrRight
(
command
);
if
(
command
.
isRightMode
()
&&
command
.
isRoleMode
())
{
if
(
command
.
isRightMode
()
&&
command
.
isRoleMode
())
{
throw
DbException
throw
DbException
...
@@ -5005,7 +5028,7 @@ public class Parser {
...
@@ -5005,7 +5028,7 @@ public class Parser {
do
{
do
{
Table
table
=
readTableOrView
();
Table
table
=
readTableOrView
();
command
.
addTable
(
table
);
command
.
addTable
(
table
);
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
}
}
}
}
}
}
...
@@ -5078,7 +5101,7 @@ public class Parser {
...
@@ -5078,7 +5101,7 @@ public class Parser {
i
++;
i
++;
}
while
(
multiColumn
&&
readIfMore
(
true
));
}
while
(
multiColumn
&&
readIfMore
(
true
));
rows
.
add
(
row
);
rows
.
add
(
row
);
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
int
columnCount
=
columns
.
size
();
int
columnCount
=
columns
.
size
();
int
rowCount
=
rows
.
size
();
int
rowCount
=
rows
.
size
();
for
(
ArrayList
<
Expression
>
row
:
rows
)
{
for
(
ArrayList
<
Expression
>
row
:
rows
)
{
...
@@ -5140,7 +5163,7 @@ public class Parser {
...
@@ -5140,7 +5163,7 @@ public class Parser {
ArrayList
<
String
>
tableEngineParams
=
Utils
.
newSmallArrayList
();
ArrayList
<
String
>
tableEngineParams
=
Utils
.
newSmallArrayList
();
do
{
do
{
tableEngineParams
.
add
(
readUniqueIdentifier
());
tableEngineParams
.
add
(
readUniqueIdentifier
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
return
tableEngineParams
;
return
tableEngineParams
;
}
}
...
@@ -5293,7 +5316,7 @@ public class Parser {
...
@@ -5293,7 +5316,7 @@ public class Parser {
}
else
{
}
else
{
throw
getSyntaxError
();
throw
getSyntaxError
();
}
}
}
while
(
readIf
(
","
)
}
while
(
readIf
(
COMMA
)
||
(
database
.
getMode
().
getEnum
()
==
ModeEnum
.
PostgreSQL
||
(
database
.
getMode
().
getEnum
()
==
ModeEnum
.
PostgreSQL
&&
readIf
(
"OR"
)));
&&
readIf
(
"OR"
)));
read
(
ON
);
read
(
ON
);
...
@@ -5391,7 +5414,7 @@ public class Parser {
...
@@ -5391,7 +5414,7 @@ public class Parser {
do
{
do
{
viewsCreated
.
add
(
parseSingleCommonTableExpression
(
isTemporary
));
viewsCreated
.
add
(
parseSingleCommonTableExpression
(
isTemporary
));
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
Prepared
p
;
Prepared
p
;
// Reverse the order of constructed CTE views - as the destruction order
// Reverse the order of constructed CTE views - as the destruction order
...
@@ -5979,7 +6002,7 @@ public class Parser {
...
@@ -5979,7 +6002,7 @@ public class Parser {
ArrayList
<
String
>
list
=
Utils
.
newSmallArrayList
();
ArrayList
<
String
>
list
=
Utils
.
newSmallArrayList
();
do
{
do
{
list
.
add
(
readAliasIdentifier
());
list
.
add
(
readAliasIdentifier
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
command
.
setStringArray
(
list
.
toArray
(
new
String
[
0
]));
command
.
setStringArray
(
list
.
toArray
(
new
String
[
0
]));
return
command
;
return
command
;
}
else
if
(
readIf
(
"JAVA_OBJECT_SERIALIZER"
))
{
}
else
if
(
readIf
(
"JAVA_OBJECT_SERIALIZER"
))
{
...
@@ -6124,13 +6147,13 @@ public class Parser {
...
@@ -6124,13 +6147,13 @@ public class Parser {
HashSet
<
String
>
schemaNames
=
new
HashSet
<>();
HashSet
<
String
>
schemaNames
=
new
HashSet
<>();
do
{
do
{
schemaNames
.
add
(
readUniqueIdentifier
());
schemaNames
.
add
(
readUniqueIdentifier
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
command
.
setSchemaNames
(
schemaNames
);
command
.
setSchemaNames
(
schemaNames
);
}
else
if
(
readIf
(
"TABLE"
))
{
}
else
if
(
readIf
(
"TABLE"
))
{
ArrayList
<
Table
>
tables
=
Utils
.
newSmallArrayList
();
ArrayList
<
Table
>
tables
=
Utils
.
newSmallArrayList
();
do
{
do
{
tables
.
add
(
readTableOrView
());
tables
.
add
(
readTableOrView
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
command
.
setTables
(
tables
);
command
.
setTables
(
tables
);
}
}
return
command
;
return
command
;
...
@@ -6344,7 +6367,7 @@ public class Parser {
...
@@ -6344,7 +6367,7 @@ public class Parser {
columnsToRemove
.
add
(
column
);
columnsToRemove
.
add
(
column
);
}
}
}
}
}
while
(
readIf
(
","
));
}
while
(
readIf
(
COMMA
));
if
(
openingBracketDetected
)
{
if
(
openingBracketDetected
)
{
// For Oracle compatibility - close bracket
// For Oracle compatibility - close bracket
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
...
@@ -6778,15 +6801,15 @@ public class Parser {
...
@@ -6778,15 +6801,15 @@ public class Parser {
command
.
setComment
(
readCommentIf
());
command
.
setComment
(
readCommentIf
());
read
(
OPEN_PAREN
);
read
(
OPEN_PAREN
);
command
.
setDriver
(
readString
());
command
.
setDriver
(
readString
());
read
(
","
);
read
(
COMMA
);
command
.
setUrl
(
readString
());
command
.
setUrl
(
readString
());
read
(
","
);
read
(
COMMA
);
command
.
setUser
(
readString
());
command
.
setUser
(
readString
());
read
(
","
);
read
(
COMMA
);
command
.
setPassword
(
readString
());
command
.
setPassword
(
readString
());
read
(
","
);
read
(
COMMA
);
String
originalTable
=
readString
();
String
originalTable
=
readString
();
if
(
readIf
(
","
))
{
if
(
readIf
(
COMMA
))
{
command
.
setOriginalSchema
(
originalTable
);
command
.
setOriginalSchema
(
originalTable
);
originalTable
=
readString
();
originalTable
=
readString
();
}
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论