Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
87e449d9
提交
87e449d9
authored
7月 10, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add separate token types for remaining operators
上级
081d282a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
110 行增加
和
17 行删除
+110
-17
Parser.java
h2/src/main/org/h2/command/Parser.java
+110
-17
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
87e449d9
...
@@ -28,7 +28,6 @@ import static org.h2.util.ParserUtil.INNER;
...
@@ -28,7 +28,6 @@ import static org.h2.util.ParserUtil.INNER;
import
static
org
.
h2
.
util
.
ParserUtil
.
INTERSECT
;
import
static
org
.
h2
.
util
.
ParserUtil
.
INTERSECT
;
import
static
org
.
h2
.
util
.
ParserUtil
.
IS
;
import
static
org
.
h2
.
util
.
ParserUtil
.
IS
;
import
static
org
.
h2
.
util
.
ParserUtil
.
JOIN
;
import
static
org
.
h2
.
util
.
ParserUtil
.
JOIN
;
import
static
org
.
h2
.
util
.
ParserUtil
.
KEYWORD
;
import
static
org
.
h2
.
util
.
ParserUtil
.
LIKE
;
import
static
org
.
h2
.
util
.
ParserUtil
.
LIKE
;
import
static
org
.
h2
.
util
.
ParserUtil
.
LIMIT
;
import
static
org
.
h2
.
util
.
ParserUtil
.
LIMIT
;
import
static
org
.
h2
.
util
.
ParserUtil
.
MINUS
;
import
static
org
.
h2
.
util
.
ParserUtil
.
MINUS
;
...
@@ -325,6 +324,66 @@ public class Parser {
...
@@ -325,6 +324,66 @@ public class Parser {
*/
*/
private
static
final
int
DOT
=
COMMA
+
1
;
private
static
final
int
DOT
=
COMMA
+
1
;
/**
* The token "{".
*/
private
static
final
int
OPEN_BRACE
=
DOT
+
1
;
/**
* The token "}".
*/
private
static
final
int
CLOSE_BRACE
=
OPEN_BRACE
+
1
;
/**
* The token "/".
*/
private
static
final
int
SLASH
=
CLOSE_BRACE
+
1
;
/**
* The token "%".
*/
private
static
final
int
PERCENT
=
SLASH
+
1
;
/**
* The token ";".
*/
private
static
final
int
SEMICOLON
=
PERCENT
+
1
;
/**
* The token ":".
*/
private
static
final
int
COLON
=
SEMICOLON
+
1
;
/**
* The token "[".
*/
private
static
final
int
OPEN_BRACKET
=
COLON
+
1
;
/**
* The token "]".
*/
private
static
final
int
CLOSE_BRACKET
=
OPEN_BRACKET
+
1
;
/**
* The token "~".
*/
private
static
final
int
TILDE
=
CLOSE_BRACKET
+
1
;
/**
* The token "::".
*/
private
static
final
int
COLON_COLON
=
TILDE
+
1
;
/**
* The token ":=".
*/
private
static
final
int
COLON_EQ
=
COLON_COLON
+
1
;
/**
* The token "!~".
*/
private
static
final
int
NOT_TILDE
=
COLON_EQ
+
1
;
private
static
final
String
[]
TOKENS
=
{
private
static
final
String
[]
TOKENS
=
{
// Unused
// Unused
null
,
null
,
...
@@ -448,6 +507,30 @@ public class Parser {
...
@@ -448,6 +507,30 @@ public class Parser {
","
,
","
,
// DOT
// DOT
"."
,
"."
,
// OPEN_BRACE
"{"
,
// CLOSE_BRACE
"}"
,
// SLASH
"/"
,
// PERCENT
"%"
,
// SEMICOLON
";"
,
// COLON
":"
,
// OPEN_BRACKET
"["
,
// CLOSE_BRACKET
"]"
,
// TILDE
"~"
,
// COLON_COLON
"::"
,
// COLON_EQ
":="
,
// NOT_TILDE
"!~"
,
// End
// End
};
};
...
@@ -527,7 +610,7 @@ public class Parser {
...
@@ -527,7 +610,7 @@ public class Parser {
public
Command
prepareCommand
(
String
sql
)
{
public
Command
prepareCommand
(
String
sql
)
{
try
{
try
{
Prepared
p
=
parse
(
sql
);
Prepared
p
=
parse
(
sql
);
boolean
hasMore
=
isToken
(
";"
);
boolean
hasMore
=
isToken
(
SEMICOLON
);
if
(!
hasMore
&&
currentTokenType
!=
END
)
{
if
(!
hasMore
&&
currentTokenType
!=
END
)
{
throw
getSyntaxError
();
throw
getSyntaxError
();
}
}
...
@@ -765,7 +848,7 @@ public class Parser {
...
@@ -765,7 +848,7 @@ public class Parser {
}
}
parameters
=
indexedParameterList
;
parameters
=
indexedParameterList
;
}
}
if
(
readIf
(
"{"
))
{
if
(
readIf
(
OPEN_BRACE
))
{
do
{
do
{
int
index
=
(
int
)
readLong
()
-
1
;
int
index
=
(
int
)
readLong
()
-
1
;
if
(
index
<
0
||
index
>=
parameters
.
size
())
{
if
(
index
<
0
||
index
>=
parameters
.
size
())
{
...
@@ -775,12 +858,12 @@ public class Parser {
...
@@ -775,12 +858,12 @@ public class Parser {
if
(
p
==
null
)
{
if
(
p
==
null
)
{
throw
getSyntaxError
();
throw
getSyntaxError
();
}
}
read
(
":"
);
read
(
COLON
);
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
(
COMMA
));
}
while
(
readIf
(
COMMA
));
read
(
"}"
);
read
(
CLOSE_BRACE
);
for
(
Parameter
p
:
parameters
)
{
for
(
Parameter
p
:
parameters
)
{
p
.
checkSet
();
p
.
checkSet
();
}
}
...
@@ -2797,7 +2880,7 @@ public class Parser {
...
@@ -2797,7 +2880,7 @@ public class Parser {
while
(
true
)
{
while
(
true
)
{
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
(
TILDE
))
{
if
(
readIf
(
ASTERISK
))
{
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"
,
...
@@ -2806,7 +2889,7 @@ public class Parser {
...
@@ -2806,7 +2889,7 @@ public class Parser {
r
=
function
;
r
=
function
;
}
}
r
=
new
CompareLike
(
database
,
r
,
readSum
(),
null
,
true
);
r
=
new
CompareLike
(
database
,
r
,
readSum
(),
null
,
true
);
}
else
if
(
readIf
(
"!~"
))
{
}
else
if
(
readIf
(
NOT_TILDE
))
{
if
(
readIf
(
ASTERISK
))
{
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"
,
...
@@ -2840,9 +2923,9 @@ public class Parser {
...
@@ -2840,9 +2923,9 @@ public class Parser {
while
(
true
)
{
while
(
true
)
{
if
(
readIf
(
ASTERISK
))
{
if
(
readIf
(
ASTERISK
))
{
r
=
new
Operation
(
OpType
.
MULTIPLY
,
r
,
readTerm
());
r
=
new
Operation
(
OpType
.
MULTIPLY
,
r
,
readTerm
());
}
else
if
(
readIf
(
"/"
))
{
}
else
if
(
readIf
(
SLASH
))
{
r
=
new
Operation
(
OpType
.
DIVIDE
,
r
,
readTerm
());
r
=
new
Operation
(
OpType
.
DIVIDE
,
r
,
readTerm
());
}
else
if
(
readIf
(
"%"
))
{
}
else
if
(
readIf
(
PERCENT
))
{
r
=
new
Operation
(
OpType
.
MODULUS
,
r
,
readTerm
());
r
=
new
Operation
(
OpType
.
MODULUS
,
r
,
readTerm
());
}
else
{
}
else
{
return
r
;
return
r
;
...
@@ -3316,7 +3399,7 @@ public class Parser {
...
@@ -3316,7 +3399,7 @@ public class Parser {
case
AT:
case
AT:
read
();
read
();
r
=
new
Variable
(
session
,
readAliasIdentifier
());
r
=
new
Variable
(
session
,
readAliasIdentifier
());
if
(
readIf
(
":="
))
{
if
(
readIf
(
COLON_EQ
))
{
Expression
value
=
readExpression
();
Expression
value
=
readExpression
();
Function
function
=
Function
.
getFunction
(
database
,
"SET"
);
Function
function
=
Function
.
getFunction
(
database
,
"SET"
);
function
.
setParameter
(
0
,
r
);
function
.
setParameter
(
0
,
r
);
...
@@ -3542,7 +3625,7 @@ public class Parser {
...
@@ -3542,7 +3625,7 @@ public class Parser {
default
:
default
:
throw
getSyntaxError
();
throw
getSyntaxError
();
}
}
if
(
readIf
(
"["
))
{
if
(
readIf
(
OPEN_BRACKET
))
{
Function
function
=
Function
.
getFunction
(
database
,
"ARRAY_GET"
);
Function
function
=
Function
.
getFunction
(
database
,
"ARRAY_GET"
);
function
.
setParameter
(
0
,
r
);
function
.
setParameter
(
0
,
r
);
r
=
readExpression
();
r
=
readExpression
();
...
@@ -3550,9 +3633,9 @@ public class Parser {
...
@@ -3550,9 +3633,9 @@ public class Parser {
.
get
(
1
)));
.
get
(
1
)));
function
.
setParameter
(
1
,
r
);
function
.
setParameter
(
1
,
r
);
r
=
function
;
r
=
function
;
read
(
"]"
);
read
(
CLOSE_BRACKET
);
}
}
if
(
readIf
(
"::"
))
{
if
(
readIf
(
COLON_COLON
))
{
// PostgreSQL compatibility
// PostgreSQL compatibility
if
(
isToken
(
"PG_CATALOG"
))
{
if
(
isToken
(
"PG_CATALOG"
))
{
read
(
"PG_CATALOG"
);
read
(
"PG_CATALOG"
);
...
@@ -4375,15 +4458,23 @@ public class Parser {
...
@@ -4375,15 +4458,23 @@ public class Parser {
case
','
:
case
','
:
return
COMMA
;
return
COMMA
;
case
'{'
:
case
'{'
:
return
OPEN_BRACE
;
case
'}'
:
case
'}'
:
return
CLOSE_BRACE
;
case
'/'
:
case
'/'
:
return
SLASH
;
case
'%'
:
case
'%'
:
return
PERCENT
;
case
';'
:
case
';'
:
return
SEMICOLON
;
case
':'
:
case
':'
:
return
COLON
;
case
'['
:
case
'['
:
return
OPEN_BRACKET
;
case
']'
:
case
']'
:
return
CLOSE_BRACKET
;
case
'~'
:
case
'~'
:
return
KEYWORD
;
return
TILDE
;
case
'('
:
case
'('
:
return
OPEN_PAREN
;
return
OPEN_PAREN
;
case
')'
:
case
')'
:
...
@@ -4402,8 +4493,10 @@ public class Parser {
...
@@ -4402,8 +4493,10 @@ public class Parser {
private
int
getSpecialType2
(
char
c0
,
char
c1
)
{
private
int
getSpecialType2
(
char
c0
,
char
c1
)
{
switch
(
c0
)
{
switch
(
c0
)
{
case
':'
:
case
':'
:
if
(
c1
==
':'
||
c1
==
'='
)
{
if
(
c1
==
':'
)
{
return
KEYWORD
;
return
COLON_COLON
;
}
else
if
(
c1
==
'='
)
{
return
COLON_EQ
;
}
}
break
;
break
;
case
'>'
:
case
'>'
:
...
@@ -4422,7 +4515,7 @@ public class Parser {
...
@@ -4422,7 +4515,7 @@ public class Parser {
if
(
c1
==
'='
)
{
if
(
c1
==
'='
)
{
return
NOT_EQUAL
;
return
NOT_EQUAL
;
}
else
if
(
c1
==
'~'
)
{
}
else
if
(
c1
==
'~'
)
{
return
KEYWORD
;
return
NOT_TILDE
;
}
}
break
;
break
;
case
'|'
:
case
'|'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论