Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6ec2c394
提交
6ec2c394
authored
7 年前
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enum for OpType
上级
66d4ce58
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
54 行增加
和
51 行删除
+54
-51
Parser.java
h2/src/main/org/h2/command/Parser.java
+9
-8
Operation.java
h2/src/main/org/h2/expression/Operation.java
+45
-43
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
6ec2c394
...
...
@@ -122,6 +122,7 @@ import org.h2.expression.FunctionCall;
import
org.h2.expression.JavaAggregate
;
import
org.h2.expression.JavaFunction
;
import
org.h2.expression.Operation
;
import
org.h2.expression.Operation.OpType
;
import
org.h2.expression.Parameter
;
import
org.h2.expression.Rownum
;
import
org.h2.expression.SequenceValue
;
...
...
@@ -2557,7 +2558,7 @@ public class Parser {
Expression
r
=
readSum
();
while
(
true
)
{
if
(
readIf
(
"||"
))
{
r
=
new
Operation
(
Op
eration
.
CONCAT
,
r
,
readSum
());
r
=
new
Operation
(
Op
Type
.
CONCAT
,
r
,
readSum
());
}
else
if
(
readIf
(
"~"
))
{
if
(
readIf
(
"*"
))
{
Function
function
=
Function
.
getFunction
(
database
,
"CAST"
);
...
...
@@ -2587,9 +2588,9 @@ public class Parser {
Expression
r
=
readFactor
();
while
(
true
)
{
if
(
readIf
(
"+"
))
{
r
=
new
Operation
(
Op
eration
.
PLUS
,
r
,
readFactor
());
r
=
new
Operation
(
Op
Type
.
PLUS
,
r
,
readFactor
());
}
else
if
(
readIf
(
"-"
))
{
r
=
new
Operation
(
Op
eration
.
MINUS
,
r
,
readFactor
());
r
=
new
Operation
(
Op
Type
.
MINUS
,
r
,
readFactor
());
}
else
{
return
r
;
}
...
...
@@ -2600,11 +2601,11 @@ public class Parser {
Expression
r
=
readTerm
();
while
(
true
)
{
if
(
readIf
(
"*"
))
{
r
=
new
Operation
(
Op
eration
.
MULTIPLY
,
r
,
readTerm
());
r
=
new
Operation
(
Op
Type
.
MULTIPLY
,
r
,
readTerm
());
}
else
if
(
readIf
(
"/"
))
{
r
=
new
Operation
(
Op
eration
.
DIVIDE
,
r
,
readTerm
());
r
=
new
Operation
(
Op
Type
.
DIVIDE
,
r
,
readTerm
());
}
else
if
(
readIf
(
"%"
))
{
r
=
new
Operation
(
Op
eration
.
MODULUS
,
r
,
readTerm
());
r
=
new
Operation
(
Op
Type
.
MODULUS
,
r
,
readTerm
());
}
else
{
return
r
;
}
...
...
@@ -3194,7 +3195,7 @@ public class Parser {
}
read
();
}
else
{
r
=
new
Operation
(
Op
eration
.
NEGATE
,
readTerm
(),
null
);
r
=
new
Operation
(
Op
Type
.
NEGATE
,
readTerm
(),
null
);
}
break
;
case
PLUS:
...
...
@@ -3258,7 +3259,7 @@ public class Parser {
Function
function
=
Function
.
getFunction
(
database
,
"ARRAY_GET"
);
function
.
setParameter
(
0
,
r
);
r
=
readExpression
();
r
=
new
Operation
(
Op
eration
.
PLUS
,
r
,
ValueExpression
.
get
(
ValueInt
r
=
new
Operation
(
Op
Type
.
PLUS
,
r
,
ValueExpression
.
get
(
ValueInt
.
get
(
1
)));
function
.
setParameter
(
1
,
r
);
r
=
function
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/Operation.java
浏览文件 @
6ec2c394
...
...
@@ -22,48 +22,50 @@ import org.h2.value.ValueString;
*/
public
class
Operation
extends
Expression
{
/**
* This operation represents a string concatenation as in
* 'Hello' || 'World'.
*/
public
static
final
int
CONCAT
=
0
;
public
enum
OpType
{
/**
* This operation represents a string concatenation as in
* 'Hello' || 'World'.
*/
CONCAT
,
/**
* This operation represents an addition as in 1 + 2.
*/
public
static
final
int
PLUS
=
1
;
/**
* This operation represents an addition as in 1 + 2.
*/
PLUS
,
/**
* This operation represents a subtraction as in 2 - 1.
*/
public
static
final
int
MINUS
=
2
;
/**
* This operation represents a subtraction as in 2 - 1.
*/
MINUS
,
/**
* This operation represents a multiplication as in 2 * 3.
*/
public
static
final
int
MULTIPLY
=
3
;
/**
* This operation represents a multiplication as in 2 * 3.
*/
MULTIPLY
,
/**
* This operation represents a division as in 4 * 2.
*/
public
static
final
int
DIVIDE
=
4
;
/**
* This operation represents a division as in 4 * 2.
*/
DIVIDE
,
/**
* This operation represents a negation as in - ID.
*/
public
static
final
int
NEGATE
=
5
;
/**
* This operation represents a negation as in - ID.
*/
NEGATE
,
/**
* This operation represents a modulus as in 5 % 2.
*/
public
static
final
int
MODULUS
=
6
;
/**
* This operation represents a modulus as in 5 % 2.
*/
MODULUS
};
private
int
opType
;
private
OpType
opType
;
private
Expression
left
,
right
;
private
int
dataType
;
private
boolean
convertRight
=
true
;
public
Operation
(
int
opType
,
Expression
left
,
Expression
right
)
{
public
Operation
(
OpType
opType
,
Expression
left
,
Expression
right
)
{
this
.
opType
=
opType
;
this
.
left
=
left
;
this
.
right
=
right
;
...
...
@@ -72,7 +74,7 @@ public class Operation extends Expression {
@Override
public
String
getSQL
()
{
String
sql
;
if
(
opType
==
NEGATE
)
{
if
(
opType
==
OpType
.
NEGATE
)
{
// don't remove the space, otherwise it might end up some thing like
// --1 which is a line remark
sql
=
"- "
+
left
.
getSQL
();
...
...
@@ -205,17 +207,17 @@ public class Operation extends Expression {
(
l
==
Value
.
UNKNOWN
&&
r
==
Value
.
UNKNOWN
))
{
// (? + ?) - use decimal by default (the most safe data type) or
// string when text concatenation with + is enabled
if
(
opType
==
PLUS
&&
session
.
getDatabase
().
if
(
opType
==
OpType
.
PLUS
&&
session
.
getDatabase
().
getMode
().
allowPlusForStringConcat
)
{
dataType
=
Value
.
STRING
;
opType
=
CONCAT
;
opType
=
OpType
.
CONCAT
;
}
else
{
dataType
=
Value
.
DECIMAL
;
}
}
else
if
(
l
==
Value
.
DATE
||
l
==
Value
.
TIMESTAMP
||
l
==
Value
.
TIME
||
r
==
Value
.
DATE
||
r
==
Value
.
TIMESTAMP
||
r
==
Value
.
TIME
)
{
if
(
opType
==
PLUS
)
{
if
(
opType
==
OpType
.
PLUS
)
{
if
(
r
!=
Value
.
getHigherOrder
(
l
,
r
))
{
// order left and right: INT < TIME < DATE < TIMESTAMP
swap
();
...
...
@@ -235,7 +237,7 @@ public class Operation extends Expression {
// Oracle date add
Function
f
=
Function
.
getFunction
(
session
.
getDatabase
(),
"DATEADD"
);
f
.
setParameter
(
0
,
ValueExpression
.
get
(
ValueString
.
get
(
"SECOND"
)));
left
=
new
Operation
(
Op
eration
.
MULTIPLY
,
ValueExpression
.
get
(
ValueInt
left
=
new
Operation
(
Op
Type
.
MULTIPLY
,
ValueExpression
.
get
(
ValueInt
.
get
(
60
*
60
*
24
)),
left
);
f
.
setParameter
(
1
,
left
);
f
.
setParameter
(
2
,
right
);
...
...
@@ -248,12 +250,12 @@ public class Operation extends Expression {
dataType
=
Value
.
TIMESTAMP
;
return
this
;
}
}
else
if
(
opType
==
MINUS
)
{
}
else
if
(
opType
==
OpType
.
MINUS
)
{
if
((
l
==
Value
.
DATE
||
l
==
Value
.
TIMESTAMP
)
&&
r
==
Value
.
INT
)
{
// Oracle date subtract
Function
f
=
Function
.
getFunction
(
session
.
getDatabase
(),
"DATEADD"
);
f
.
setParameter
(
0
,
ValueExpression
.
get
(
ValueString
.
get
(
"DAY"
)));
right
=
new
Operation
(
NEGATE
,
right
,
null
);
right
=
new
Operation
(
OpType
.
NEGATE
,
right
,
null
);
right
=
right
.
optimize
(
session
);
f
.
setParameter
(
1
,
right
);
f
.
setParameter
(
2
,
left
);
...
...
@@ -264,9 +266,9 @@ public class Operation extends Expression {
// Oracle date subtract
Function
f
=
Function
.
getFunction
(
session
.
getDatabase
(),
"DATEADD"
);
f
.
setParameter
(
0
,
ValueExpression
.
get
(
ValueString
.
get
(
"SECOND"
)));
right
=
new
Operation
(
Op
eration
.
MULTIPLY
,
ValueExpression
.
get
(
ValueInt
right
=
new
Operation
(
Op
Type
.
MULTIPLY
,
ValueExpression
.
get
(
ValueInt
.
get
(
60
*
60
*
24
)),
right
);
right
=
new
Operation
(
NEGATE
,
right
,
null
);
right
=
new
Operation
(
OpType
.
NEGATE
,
right
,
null
);
right
=
right
.
optimize
(
session
);
f
.
setParameter
(
1
,
right
);
f
.
setParameter
(
2
,
left
);
...
...
@@ -289,7 +291,7 @@ public class Operation extends Expression {
dataType
=
Value
.
TIME
;
return
this
;
}
}
else
if
(
opType
==
MULTIPLY
)
{
}
else
if
(
opType
==
OpType
.
MULTIPLY
)
{
if
(
l
==
Value
.
TIME
)
{
dataType
=
Value
.
TIME
;
convertRight
=
false
;
...
...
@@ -300,7 +302,7 @@ public class Operation extends Expression {
convertRight
=
false
;
return
this
;
}
}
else
if
(
opType
==
DIVIDE
)
{
}
else
if
(
opType
==
OpType
.
DIVIDE
)
{
if
(
l
==
Value
.
TIME
)
{
dataType
=
Value
.
TIME
;
convertRight
=
false
;
...
...
@@ -315,7 +317,7 @@ public class Operation extends Expression {
dataType
=
Value
.
getHigherOrder
(
l
,
r
);
if
(
DataType
.
isStringType
(
dataType
)
&&
session
.
getDatabase
().
getMode
().
allowPlusForStringConcat
)
{
opType
=
CONCAT
;
opType
=
OpType
.
CONCAT
;
}
}
break
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论