Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
07154efb
提交
07154efb
authored
11月 06, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Expression.getSQL(StringBuilder)
上级
274abf34
显示空白字符变更
内嵌
并排
正在显示
42 个修改的文件
包含
243 行增加
和
174 行删除
+243
-174
Prepared.java
h2/src/main/org/h2/command/Prepared.java
+1
-1
Insert.java
h2/src/main/org/h2/command/dml/Insert.java
+3
-2
Merge.java
h2/src/main/org/h2/command/dml/Merge.java
+1
-1
Replace.java
h2/src/main/org/h2/command/dml/Replace.java
+1
-1
Select.java
h2/src/main/org/h2/command/dml/Select.java
+1
-1
SelectOrderBy.java
h2/src/main/org/h2/command/dml/SelectOrderBy.java
+3
-2
Update.java
h2/src/main/org/h2/command/dml/Update.java
+2
-1
ConstraintCheck.java
h2/src/main/org/h2/constraint/ConstraintCheck.java
+8
-3
Alias.java
h2/src/main/org/h2/expression/Alias.java
+2
-2
BinaryOperation.java
h2/src/main/org/h2/expression/BinaryOperation.java
+4
-2
CompareLike.java
h2/src/main/org/h2/expression/CompareLike.java
+9
-6
Comparison.java
h2/src/main/org/h2/expression/Comparison.java
+10
-8
ConditionAndOr.java
h2/src/main/org/h2/expression/ConditionAndOr.java
+6
-5
ConditionExists.java
h2/src/main/org/h2/expression/ConditionExists.java
+4
-2
ConditionIn.java
h2/src/main/org/h2/expression/ConditionIn.java
+9
-8
ConditionInConstantSet.java
h2/src/main/org/h2/expression/ConditionInConstantSet.java
+9
-8
ConditionInParameter.java
h2/src/main/org/h2/expression/ConditionInParameter.java
+4
-2
ConditionInSelect.java
h2/src/main/org/h2/expression/ConditionInSelect.java
+7
-9
ConditionNot.java
h2/src/main/org/h2/expression/ConditionNot.java
+3
-2
Expression.java
h2/src/main/org/h2/expression/Expression.java
+16
-1
ExpressionColumn.java
h2/src/main/org/h2/expression/ExpressionColumn.java
+10
-11
ExpressionList.java
h2/src/main/org/h2/expression/ExpressionList.java
+9
-8
Function.java
h2/src/main/org/h2/expression/Function.java
+25
-18
IntervalOperation.java
h2/src/main/org/h2/expression/IntervalOperation.java
+4
-2
JavaFunction.java
h2/src/main/org/h2/expression/JavaFunction.java
+9
-9
Parameter.java
h2/src/main/org/h2/expression/Parameter.java
+2
-2
Rownum.java
h2/src/main/org/h2/expression/Rownum.java
+5
-0
SequenceValue.java
h2/src/main/org/h2/expression/SequenceValue.java
+3
-2
Subquery.java
h2/src/main/org/h2/expression/Subquery.java
+2
-2
TableFunction.java
h2/src/main/org/h2/expression/TableFunction.java
+2
-1
UnaryOperation.java
h2/src/main/org/h2/expression/UnaryOperation.java
+3
-2
ValueExpression.java
h2/src/main/org/h2/expression/ValueExpression.java
+10
-0
Variable.java
h2/src/main/org/h2/expression/Variable.java
+2
-2
Wildcard.java
h2/src/main/org/h2/expression/Wildcard.java
+3
-5
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+2
-1
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+24
-22
JavaAggregate.java
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
+9
-9
Window.java
h2/src/main/org/h2/expression/aggregate/Window.java
+1
-1
WindowFrameBound.java
...rc/main/org/h2/expression/aggregate/WindowFrameBound.java
+2
-1
WindowFunction.java
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
+4
-4
IndexCondition.java
h2/src/main/org/h2/index/IndexCondition.java
+2
-2
RangeTable.java
h2/src/main/org/h2/table/RangeTable.java
+7
-3
没有找到文件。
h2/src/main/org/h2/command/Prepared.java
浏览文件 @
07154efb
...
@@ -422,7 +422,7 @@ public abstract class Prepared {
...
@@ -422,7 +422,7 @@ public abstract class Prepared {
for
(
Expression
e
:
list
)
{
for
(
Expression
e
:
list
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
if
(
e
!=
null
)
{
if
(
e
!=
null
)
{
buff
.
append
(
e
.
getSQL
());
e
.
getSQL
(
buff
.
builder
());
}
}
}
}
return
buff
.
toString
();
return
buff
.
toString
();
...
...
h2/src/main/org/h2/command/dml/Insert.java
浏览文件 @
07154efb
...
@@ -421,7 +421,8 @@ public class Insert extends Prepared implements ResultTarget {
...
@@ -421,7 +421,8 @@ public class Insert extends Prepared implements ResultTarget {
for
(
Column
column
:
duplicateKeyAssignmentMap
.
keySet
())
{
for
(
Column
column
:
duplicateKeyAssignmentMap
.
keySet
())
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
Expression
ex
=
duplicateKeyAssignmentMap
.
get
(
column
);
Expression
ex
=
duplicateKeyAssignmentMap
.
get
(
column
);
buff
.
append
(
column
.
getSQL
()).
append
(
'='
).
append
(
ex
.
getSQL
());
buff
.
append
(
column
.
getSQL
()).
append
(
'='
);
ex
.
getSQL
(
buff
.
builder
());
}
}
buff
.
append
(
" WHERE "
);
buff
.
append
(
" WHERE "
);
Index
foundIndex
=
(
Index
)
de
.
getSource
();
Index
foundIndex
=
(
Index
)
de
.
getSource
();
...
@@ -429,7 +430,7 @@ public class Insert extends Prepared implements ResultTarget {
...
@@ -429,7 +430,7 @@ public class Insert extends Prepared implements ResultTarget {
throw
DbException
.
getUnsupportedException
(
throw
DbException
.
getUnsupportedException
(
"Unable to apply ON DUPLICATE KEY UPDATE, no index found!"
);
"Unable to apply ON DUPLICATE KEY UPDATE, no index found!"
);
}
}
buff
.
append
(
prepareUpdateCondition
(
foundIndex
,
row
).
getSQL
());
prepareUpdateCondition
(
foundIndex
,
row
).
getSQL
(
buff
.
builder
());
String
sql
=
buff
.
toString
();
String
sql
=
buff
.
toString
();
Update
command
=
(
Update
)
session
.
prepare
(
sql
);
Update
command
=
(
Update
)
session
.
prepare
(
sql
);
command
.
setUpdateToCurrentValuesReturnsZero
(
true
);
command
.
setUpdateToCurrentValuesReturnsZero
(
true
);
...
...
h2/src/main/org/h2/command/dml/Merge.java
浏览文件 @
07154efb
...
@@ -248,7 +248,7 @@ public class Merge extends Prepared {
...
@@ -248,7 +248,7 @@ public class Merge extends Prepared {
if
(
e
==
null
)
{
if
(
e
==
null
)
{
buff
.
append
(
"DEFAULT"
);
buff
.
append
(
"DEFAULT"
);
}
else
{
}
else
{
buff
.
append
(
e
.
getSQL
());
e
.
getSQL
(
buff
.
builder
());
}
}
}
}
buff
.
append
(
')'
);
buff
.
append
(
')'
);
...
...
h2/src/main/org/h2/command/dml/Replace.java
浏览文件 @
07154efb
...
@@ -228,7 +228,7 @@ public class Replace extends Prepared {
...
@@ -228,7 +228,7 @@ public class Replace extends Prepared {
if
(
e
==
null
)
{
if
(
e
==
null
)
{
buff
.
append
(
"DEFAULT"
);
buff
.
append
(
"DEFAULT"
);
}
else
{
}
else
{
buff
.
append
(
e
.
getSQL
());
e
.
getSQL
(
buff
.
builder
());
}
}
}
}
buff
.
append
(
')'
);
buff
.
append
(
')'
);
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
07154efb
...
@@ -1327,7 +1327,7 @@ public class Select extends Query {
...
@@ -1327,7 +1327,7 @@ public class Select extends Query {
buff
.
append
(
" ON("
);
buff
.
append
(
" ON("
);
for
(
Expression
distinctExpression:
distinctExpressions
)
{
for
(
Expression
distinctExpression:
distinctExpressions
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
distinctExpression
.
getSQL
());
distinctExpression
.
getSQL
(
buff
.
builder
());
}
}
buff
.
append
(
')'
);
buff
.
append
(
')'
);
buff
.
resetCount
();
buff
.
resetCount
();
...
...
h2/src/main/org/h2/command/dml/SelectOrderBy.java
浏览文件 @
07154efb
...
@@ -33,9 +33,10 @@ public class SelectOrderBy {
...
@@ -33,9 +33,10 @@ public class SelectOrderBy {
public
String
getSQL
()
{
public
String
getSQL
()
{
StringBuilder
buff
=
new
StringBuilder
();
StringBuilder
buff
=
new
StringBuilder
();
if
(
expression
!=
null
)
{
if
(
expression
!=
null
)
{
buff
.
append
(
'='
).
append
(
expression
.
getSQL
());
buff
.
append
(
'='
);
expression
.
getSQL
(
buff
);
}
else
{
}
else
{
buff
.
append
(
columnIndexExpr
.
getSQL
()
);
columnIndexExpr
.
getSQL
(
buff
);
}
}
SortOrder
.
typeToString
(
buff
,
sortType
);
SortOrder
.
typeToString
(
buff
,
sortType
);
return
buff
.
toString
();
return
buff
.
toString
();
...
...
h2/src/main/org/h2/command/dml/Update.java
浏览文件 @
07154efb
...
@@ -222,7 +222,8 @@ public class Update extends Prepared {
...
@@ -222,7 +222,8 @@ public class Update extends Prepared {
for
(
Column
c
:
columns
)
{
for
(
Column
c
:
columns
)
{
Expression
e
=
expressionMap
.
get
(
c
);
Expression
e
=
expressionMap
.
get
(
c
);
buff
.
appendExceptFirst
(
",\n "
);
buff
.
appendExceptFirst
(
",\n "
);
buff
.
append
(
c
.
getName
()).
append
(
" = "
).
append
(
e
.
getSQL
());
buff
.
append
(
c
.
getName
()).
append
(
" = "
);
e
.
getSQL
(
buff
.
builder
());
}
}
if
(
condition
!=
null
)
{
if
(
condition
!=
null
)
{
buff
.
append
(
"\nWHERE "
).
append
(
StringUtils
.
unEnclose
(
condition
.
getSQL
()));
buff
.
append
(
"\nWHERE "
).
append
(
StringUtils
.
unEnclose
(
condition
.
getSQL
()));
...
...
h2/src/main/org/h2/constraint/ConstraintCheck.java
浏览文件 @
07154efb
...
@@ -64,7 +64,9 @@ public class ConstraintCheck extends Constraint {
...
@@ -64,7 +64,9 @@ public class ConstraintCheck extends Constraint {
}
}
private
String
getShortDescription
()
{
private
String
getShortDescription
()
{
return
getName
()
+
": "
+
expr
.
getSQL
();
StringBuilder
builder
=
new
StringBuilder
().
append
(
getName
()).
append
(
": "
);
expr
.
getSQL
(
builder
);
return
builder
.
toString
();
}
}
@Override
@Override
...
@@ -140,8 +142,11 @@ public class ConstraintCheck extends Constraint {
...
@@ -140,8 +142,11 @@ public class ConstraintCheck extends Constraint {
// don't check at startup
// don't check at startup
return
;
return
;
}
}
String
sql
=
"SELECT 1 FROM "
+
filter
.
getTable
().
getSQL
()
+
StringBuilder
builder
=
new
StringBuilder
().
append
(
"SELECT 1 FROM "
)
" WHERE NOT("
+
expr
.
getSQL
()
+
")"
;
.
append
(
filter
.
getTable
().
getSQL
())
.
append
(
" WHERE NOT("
);
expr
.
getSQL
(
builder
).
append
(
')'
);
String
sql
=
builder
.
toString
();
ResultInterface
r
=
session
.
prepare
(
sql
).
query
(
1
);
ResultInterface
r
=
session
.
prepare
(
sql
).
query
(
1
);
if
(
r
.
next
())
{
if
(
r
.
next
())
{
throw
DbException
.
get
(
ErrorCode
.
CHECK_CONSTRAINT_VIOLATED_1
,
getName
());
throw
DbException
.
get
(
ErrorCode
.
CHECK_CONSTRAINT_VIOLATED_1
,
getName
());
...
...
h2/src/main/org/h2/expression/Alias.java
浏览文件 @
07154efb
...
@@ -78,8 +78,8 @@ public class Alias extends Expression {
...
@@ -78,8 +78,8 @@ public class Alias extends Expression {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
return
expr
.
getSQL
(
)
+
" AS "
+
Parser
.
quoteIdentifier
(
alias
);
return
expr
.
getSQL
(
builder
).
append
(
" AS "
).
append
(
Parser
.
quoteIdentifier
(
alias
)
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/BinaryOperation.java
浏览文件 @
07154efb
...
@@ -68,10 +68,12 @@ public class BinaryOperation extends Expression {
...
@@ -68,10 +68,12 @@ public class BinaryOperation extends Expression {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
// don't remove the space, otherwise it might end up some thing like
// don't remove the space, otherwise it might end up some thing like
// --1 which is a line remark
// --1 which is a line remark
return
'('
+
left
.
getSQL
()
+
' '
+
getOperationToken
()
+
' '
+
right
.
getSQL
()
+
')'
;
builder
.
append
(
'('
);
left
.
getSQL
(
builder
).
append
(
' '
).
append
(
getOperationToken
()).
append
(
' '
);
return
right
.
getSQL
(
builder
).
append
(
')'
);
}
}
private
String
getOperationToken
()
{
private
String
getOperationToken
()
{
...
...
h2/src/main/org/h2/expression/CompareLike.java
浏览文件 @
07154efb
...
@@ -76,17 +76,20 @@ public class CompareLike extends Condition {
...
@@ -76,17 +76,20 @@ public class CompareLike extends Condition {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
String
sql
;
builder
.
append
(
'('
)
;
if
(
regexp
)
{
if
(
regexp
)
{
sql
=
left
.
getSQL
()
+
" REGEXP "
+
right
.
getSQL
();
left
.
getSQL
(
builder
).
append
(
" REGEXP "
);
right
.
getSQL
(
builder
);
}
else
{
}
else
{
sql
=
left
.
getSQL
()
+
" LIKE "
+
right
.
getSQL
();
left
.
getSQL
(
builder
).
append
(
" LIKE "
);
right
.
getSQL
(
builder
);
if
(
escape
!=
null
)
{
if
(
escape
!=
null
)
{
sql
+=
" ESCAPE "
+
escape
.
getSQL
();
builder
.
append
(
" ESCAPE "
);
escape
.
getSQL
(
builder
);
}
}
}
}
return
"("
+
sql
+
")"
;
return
builder
.
append
(
')'
)
;
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/Comparison.java
浏览文件 @
07154efb
...
@@ -126,23 +126,25 @@ public class Comparison extends Condition {
...
@@ -126,23 +126,25 @@ public class Comparison extends Condition {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
String
sql
;
builder
.
append
(
'('
)
;
switch
(
compareType
)
{
switch
(
compareType
)
{
case
IS_NULL:
case
IS_NULL:
sql
=
left
.
getSQL
()
+
" IS NULL"
;
left
.
getSQL
(
builder
).
append
(
" IS NULL"
)
;
break
;
break
;
case
IS_NOT_NULL:
case
IS_NOT_NULL:
sql
=
left
.
getSQL
()
+
" IS NOT NULL"
;
left
.
getSQL
(
builder
).
append
(
" IS NOT NULL"
)
;
break
;
break
;
case
SPATIAL_INTERSECTS:
case
SPATIAL_INTERSECTS:
sql
=
"INTERSECTS("
+
left
.
getSQL
()
+
", "
+
right
.
getSQL
()
+
")"
;
builder
.
append
(
"INTERSECTS("
);
left
.
getSQL
(
builder
).
append
(
", "
);
right
.
getSQL
(
builder
).
append
(
')'
);
break
;
break
;
default
:
default
:
sql
=
left
.
getSQL
()
+
" "
+
getCompareOperator
(
compareType
)
+
left
.
getSQL
(
builder
).
append
(
' '
).
append
(
getCompareOperator
(
compareType
)).
append
(
' '
);
" "
+
right
.
getSQL
(
);
right
.
getSQL
(
builder
);
}
}
return
"("
+
sql
+
")"
;
return
builder
.
append
(
')'
)
;
}
}
/**
/**
...
...
h2/src/main/org/h2/expression/ConditionAndOr.java
浏览文件 @
07154efb
...
@@ -42,19 +42,20 @@ public class ConditionAndOr extends Condition {
...
@@ -42,19 +42,20 @@ public class ConditionAndOr extends Condition {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
String
sql
;
builder
.
append
(
'('
);
left
.
getSQL
(
builder
);
switch
(
andOrType
)
{
switch
(
andOrType
)
{
case
AND:
case
AND:
sql
=
left
.
getSQL
()
+
"\n AND "
+
right
.
getSQL
(
);
builder
.
append
(
"\n AND "
);
break
;
break
;
case
OR:
case
OR:
sql
=
left
.
getSQL
()
+
"\n OR "
+
right
.
getSQL
(
);
builder
.
append
(
"\n OR "
);
break
;
break
;
default
:
default
:
throw
DbException
.
throwInternalError
(
"andOrType="
+
andOrType
);
throw
DbException
.
throwInternalError
(
"andOrType="
+
andOrType
);
}
}
return
"("
+
sql
+
")"
;
return
right
.
getSQL
(
builder
).
append
(
')'
)
;
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/ConditionExists.java
浏览文件 @
07154efb
...
@@ -41,8 +41,10 @@ public class ConditionExists extends Condition {
...
@@ -41,8 +41,10 @@ public class ConditionExists extends Condition {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
return
"EXISTS(\n"
+
StringUtils
.
indent
(
query
.
getPlanSQL
(),
4
,
false
)
+
")"
;
builder
.
append
(
"EXISTS(\n"
);
builder
.
append
(
StringUtils
.
indent
(
query
.
getPlanSQL
(),
4
,
false
));
return
builder
.
append
(
')'
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/ConditionIn.java
浏览文件 @
07154efb
...
@@ -11,7 +11,6 @@ import org.h2.engine.Session;
...
@@ -11,7 +11,6 @@ import org.h2.engine.Session;
import
org.h2.index.IndexCondition
;
import
org.h2.index.IndexCondition
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueBoolean
;
import
org.h2.value.ValueBoolean
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueNull
;
...
@@ -152,14 +151,16 @@ public class ConditionIn extends Condition {
...
@@ -152,14 +151,16 @@ public class ConditionIn extends Condition {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
builder
.
append
(
'('
);
buff
.
append
(
left
.
getSQL
()).
append
(
" IN("
);
left
.
getSQL
(
builder
).
append
(
" IN("
);
for
(
Expression
e
:
valueList
)
{
for
(
int
i
=
0
;
i
<
valueList
.
size
();
i
++)
{
buff
.
appendExceptFirst
(
", "
);
if
(
i
>
0
)
{
buff
.
append
(
e
.
getSQL
());
builder
.
append
(
", "
);
}
valueList
.
get
(
i
).
getSQL
(
builder
);
}
}
return
bu
ff
.
append
(
"))"
).
toString
(
);
return
bu
ilder
.
append
(
"))"
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/ConditionInConstantSet.java
浏览文件 @
07154efb
...
@@ -15,7 +15,6 @@ import org.h2.index.IndexCondition;
...
@@ -15,7 +15,6 @@ import org.h2.index.IndexCondition;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.ExtTypeInfo
;
import
org.h2.value.ExtTypeInfo
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueBoolean
;
import
org.h2.value.ValueBoolean
;
...
@@ -114,14 +113,16 @@ public class ConditionInConstantSet extends Condition {
...
@@ -114,14 +113,16 @@ public class ConditionInConstantSet extends Condition {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
builder
.
append
(
'('
);
buff
.
append
(
left
.
getSQL
()).
append
(
" IN("
);
left
.
getSQL
(
builder
).
append
(
" IN("
);
for
(
Expression
e
:
valueList
)
{
for
(
int
i
=
0
,
s
=
valueList
.
size
();
i
<
s
;
i
++)
{
buff
.
appendExceptFirst
(
", "
);
if
(
i
>
0
)
{
buff
.
append
(
e
.
getSQL
());
builder
.
append
(
", "
);
}
}
return
buff
.
append
(
"))"
).
toString
();
valueList
.
get
(
i
).
getSQL
(
builder
);
}
return
builder
.
append
(
"))"
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/ConditionInParameter.java
浏览文件 @
07154efb
...
@@ -140,8 +140,10 @@ public class ConditionInParameter extends Condition {
...
@@ -140,8 +140,10 @@ public class ConditionInParameter extends Condition {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
return
'('
+
left
.
getSQL
()
+
" = ANY("
+
parameter
.
getSQL
()
+
"))"
;
builder
.
append
(
'('
);
left
.
getSQL
(
builder
).
append
(
" = ANY("
);
return
parameter
.
getSQL
(
builder
).
append
(
"))"
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/ConditionInSelect.java
浏览文件 @
07154efb
...
@@ -129,23 +129,21 @@ public class ConditionInSelect extends Condition {
...
@@ -129,23 +129,21 @@ public class ConditionInSelect extends Condition {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
StringBuilder
buff
=
new
StringBuilder
(
);
builder
.
append
(
'('
);
buff
.
append
(
'('
).
append
(
left
.
getSQL
()
).
append
(
' '
);
left
.
getSQL
(
builder
).
append
(
' '
);
if
(
all
)
{
if
(
all
)
{
bu
ff
.
append
(
Comparison
.
getCompareOperator
(
compareType
)).
bu
ilder
.
append
(
Comparison
.
getCompareOperator
(
compareType
)).
append
(
" ALL"
);
append
(
" ALL"
);
}
else
{
}
else
{
if
(
compareType
==
Comparison
.
EQUAL
)
{
if
(
compareType
==
Comparison
.
EQUAL
)
{
bu
ff
.
append
(
"IN"
);
bu
ilder
.
append
(
"IN"
);
}
else
{
}
else
{
bu
ff
.
append
(
Comparison
.
getCompareOperator
(
compareType
)).
bu
ilder
.
append
(
Comparison
.
getCompareOperator
(
compareType
)).
append
(
" ANY"
);
append
(
" ANY"
);
}
}
}
}
buff
.
append
(
"(\n"
).
append
(
StringUtils
.
indent
(
query
.
getPlanSQL
(),
4
,
false
)).
return
builder
.
append
(
"(\n"
).
append
(
StringUtils
.
indent
(
query
.
getPlanSQL
(),
4
,
false
)).
append
(
"))"
);
append
(
"))"
);
return
buff
.
toString
();
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/ConditionNot.java
浏览文件 @
07154efb
...
@@ -65,8 +65,9 @@ public class ConditionNot extends Condition {
...
@@ -65,8 +65,9 @@ public class ConditionNot extends Condition {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
return
"(NOT "
+
condition
.
getSQL
()
+
")"
;
builder
.
append
(
"(NOT "
);
return
condition
.
getSQL
(
builder
).
append
(
')'
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/Expression.java
浏览文件 @
07154efb
...
@@ -110,7 +110,22 @@ public abstract class Expression {
...
@@ -110,7 +110,22 @@ public abstract class Expression {
*
*
* @return the SQL statement
* @return the SQL statement
*/
*/
public
abstract
String
getSQL
();
public
String
getSQL
()
{
StringBuilder
builder
=
new
StringBuilder
();
getSQL
(
builder
);
return
builder
.
toString
();
}
/**
* Appends the SQL statement of this expression to the specified builder.
* This may not always be the original SQL statement, specially after
* optimization.
*
* @param builder
* string builder
* @return the specified string builder
*/
public
abstract
StringBuilder
getSQL
(
StringBuilder
builder
);
/**
/**
* Update an aggregate value. This method is called at statement execution
* Update an aggregate value. This method is called at statement execution
...
...
h2/src/main/org/h2/expression/ExpressionColumn.java
浏览文件 @
07154efb
...
@@ -55,23 +55,22 @@ public class ExpressionColumn extends Expression {
...
@@ -55,23 +55,22 @@ public class ExpressionColumn extends Expression {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
String
sql
;
boolean
quote
=
database
.
getSettings
().
databaseToUpper
;
boolean
quote
=
database
.
getSettings
().
databaseToUpper
;
if
(
column
!=
null
)
{
if
(
schemaName
!=
null
)
{
sql
=
column
.
getSQL
();
String
s
=
quote
?
Parser
.
quoteIdentifier
(
schemaName
)
:
schemaName
;
}
else
{
builder
.
append
(
s
).
append
(
'.'
);
sql
=
quote
?
Parser
.
quoteIdentifier
(
columnName
)
:
columnName
;
}
}
if
(
tableAlias
!=
null
)
{
if
(
tableAlias
!=
null
)
{
String
a
=
quote
?
Parser
.
quoteIdentifier
(
tableAlias
)
:
tableAlias
;
String
a
=
quote
?
Parser
.
quoteIdentifier
(
tableAlias
)
:
tableAlias
;
sql
=
a
+
"."
+
sql
;
builder
.
append
(
a
).
append
(
'.'
)
;
}
}
if
(
schemaName
!=
null
)
{
if
(
column
!=
null
)
{
String
s
=
quote
?
Parser
.
quoteIdentifier
(
schemaName
)
:
schemaName
;
builder
.
append
(
column
.
getSQL
());
sql
=
s
+
"."
+
sql
;
}
else
{
builder
.
append
(
quote
?
Parser
.
quoteIdentifier
(
columnName
)
:
columnName
);
}
}
return
sql
;
return
builder
;
}
}
public
TableFilter
getTableFilter
()
{
public
TableFilter
getTableFilter
()
{
...
...
h2/src/main/org/h2/expression/ExpressionList.java
浏览文件 @
07154efb
...
@@ -9,7 +9,6 @@ import org.h2.engine.Session;
...
@@ -9,7 +9,6 @@ import org.h2.engine.Session;
import
org.h2.table.Column
;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueArray
;
...
@@ -85,16 +84,18 @@ public class ExpressionList extends Expression {
...
@@ -85,16 +84,18 @@ public class ExpressionList extends Expression {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
builder
.
append
(
'('
);
for
(
Expression
e:
list
)
{
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
buff
.
appendExceptFirst
(
", "
);
if
(
i
>
0
)
{
buff
.
append
(
e
.
getSQL
());
builder
.
append
(
", "
);
}
list
[
i
].
getSQL
(
builder
);
}
}
if
(
list
.
length
==
1
)
{
if
(
list
.
length
==
1
)
{
bu
ff
.
append
(
','
);
bu
ilder
.
append
(
','
);
}
}
return
bu
ff
.
append
(
')'
).
toString
(
);
return
bu
ilder
.
append
(
')'
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
07154efb
...
@@ -50,7 +50,6 @@ import org.h2.util.DateTimeUtils;
...
@@ -50,7 +50,6 @@ import org.h2.util.DateTimeUtils;
import
org.h2.util.IOUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.ToChar
;
import
org.h2.util.ToChar
;
import
org.h2.util.ToDateParser
;
import
org.h2.util.ToDateParser
;
...
@@ -2582,36 +2581,41 @@ public class Function extends Expression implements FunctionCall {
...
@@ -2582,36 +2581,41 @@ public class Function extends Expression implements FunctionCall {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
info
.
name
);
builder
.
append
(
info
.
name
);
if
(
info
.
type
==
CASE
)
{
if
(
info
.
type
==
CASE
)
{
if
(
args
[
0
]
!=
null
)
{
if
(
args
[
0
]
!=
null
)
{
buff
.
append
(
' '
).
append
(
args
[
0
].
getSQL
());
builder
.
append
(
' '
);
args
[
0
].
getSQL
(
builder
);
}
}
for
(
int
i
=
1
,
len
=
args
.
length
-
1
;
i
<
len
;
i
+=
2
)
{
for
(
int
i
=
1
,
len
=
args
.
length
-
1
;
i
<
len
;
i
+=
2
)
{
buff
.
append
(
" WHEN "
).
append
(
args
[
i
].
getSQL
());
builder
.
append
(
" WHEN "
);
buff
.
append
(
" THEN "
).
append
(
args
[
i
+
1
].
getSQL
());
args
[
i
].
getSQL
(
builder
);
builder
.
append
(
" THEN "
);
args
[
i
+
1
].
getSQL
(
builder
);
}
}
if
(
args
.
length
%
2
==
0
)
{
if
(
args
.
length
%
2
==
0
)
{
buff
.
append
(
" ELSE "
).
append
(
args
[
args
.
length
-
1
].
getSQL
());
builder
.
append
(
" ELSE "
);
args
[
args
.
length
-
1
].
getSQL
(
builder
);
}
}
return
bu
ff
.
append
(
" END"
).
toString
(
);
return
bu
ilder
.
append
(
" END"
);
}
}
bu
ff
.
append
(
'('
);
bu
ilder
.
append
(
'('
);
switch
(
info
.
type
)
{
switch
(
info
.
type
)
{
case
CAST:
{
case
CAST:
{
buff
.
append
(
args
[
0
].
getSQL
()
).
append
(
" AS "
).
args
[
0
].
getSQL
(
builder
).
append
(
" AS "
).
append
(
new
Column
(
null
,
dataType
,
precision
,
append
(
new
Column
(
null
,
dataType
,
precision
,
scale
,
displaySize
,
extTypeInfo
).
getCreateSQL
());
scale
,
displaySize
,
extTypeInfo
).
getCreateSQL
());
break
;
break
;
}
}
case
CONVERT:
{
case
CONVERT:
{
if
(
database
.
getMode
().
swapConvertFunctionParameters
)
{
if
(
database
.
getMode
().
swapConvertFunctionParameters
)
{
bu
ff
.
append
(
new
Column
(
null
,
dataType
,
precision
,
bu
ilder
.
append
(
new
Column
(
null
,
dataType
,
precision
,
scale
,
displaySize
).
getCreateSQL
()).
scale
,
displaySize
).
getCreateSQL
()).
append
(
','
).
append
(
args
[
0
].
getSQL
());
append
(
','
);
args
[
0
].
getSQL
(
builder
);
}
else
{
}
else
{
buff
.
append
(
args
[
0
].
getSQL
()
).
append
(
','
).
args
[
0
].
getSQL
(
builder
).
append
(
','
).
append
(
new
Column
(
null
,
dataType
,
precision
,
append
(
new
Column
(
null
,
dataType
,
precision
,
scale
,
displaySize
).
getCreateSQL
());
scale
,
displaySize
).
getCreateSQL
());
}
}
...
@@ -2619,17 +2623,20 @@ public class Function extends Expression implements FunctionCall {
...
@@ -2619,17 +2623,20 @@ public class Function extends Expression implements FunctionCall {
}
}
case
EXTRACT:
{
case
EXTRACT:
{
ValueString
v
=
(
ValueString
)
((
ValueExpression
)
args
[
0
]).
getValue
(
null
);
ValueString
v
=
(
ValueString
)
((
ValueExpression
)
args
[
0
]).
getValue
(
null
);
buff
.
append
(
v
.
getString
()).
append
(
" FROM "
).
append
(
args
[
1
].
getSQL
());
builder
.
append
(
v
.
getString
()).
append
(
" FROM "
);
args
[
1
].
getSQL
(
builder
);
break
;
break
;
}
}
default
:
{
default
:
{
for
(
Expression
e
:
args
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
buff
.
appendExceptFirst
(
", "
);
if
(
i
>
0
)
{
buff
.
append
(
e
.
getSQL
());
builder
.
append
(
", "
);
}
args
[
i
].
getSQL
(
builder
);
}
}
}
}
}
}
return
bu
ff
.
append
(
')'
).
toString
(
);
return
bu
ilder
.
append
(
')'
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/IntervalOperation.java
浏览文件 @
07154efb
...
@@ -113,8 +113,10 @@ public class IntervalOperation extends Expression {
...
@@ -113,8 +113,10 @@ public class IntervalOperation extends Expression {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
return
'('
+
left
.
getSQL
()
+
' '
+
getOperationToken
()
+
' '
+
right
.
getSQL
()
+
')'
;
builder
.
append
(
'('
);
left
.
getSQL
(
builder
).
append
(
' '
).
append
(
getOperationToken
()).
append
(
' '
);
return
right
.
getSQL
(
builder
).
append
(
')'
);
}
}
private
char
getOperationToken
()
{
private
char
getOperationToken
()
{
...
...
h2/src/main/org/h2/expression/JavaFunction.java
浏览文件 @
07154efb
...
@@ -11,7 +11,6 @@ import org.h2.engine.FunctionAlias;
...
@@ -11,7 +11,6 @@ import org.h2.engine.FunctionAlias;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.DataType
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueArray
;
...
@@ -89,21 +88,22 @@ public class JavaFunction extends Expression implements FunctionCall {
...
@@ -89,21 +88,22 @@ public class JavaFunction extends Expression implements FunctionCall {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
StatementBuilder
buff
=
new
StatementBuilder
();
// TODO always append the schema once FUNCTIONS_IN_SCHEMA is enabled
// TODO always append the schema once FUNCTIONS_IN_SCHEMA is enabled
if
(
functionAlias
.
getDatabase
().
getSettings
().
functionsInSchema
||
if
(
functionAlias
.
getDatabase
().
getSettings
().
functionsInSchema
||
!
functionAlias
.
getSchema
().
getName
().
equals
(
Constants
.
SCHEMA_MAIN
))
{
!
functionAlias
.
getSchema
().
getName
().
equals
(
Constants
.
SCHEMA_MAIN
))
{
bu
ff
.
append
(
bu
ilder
.
append
(
Parser
.
quoteIdentifier
(
functionAlias
.
getSchema
().
getName
()))
Parser
.
quoteIdentifier
(
functionAlias
.
getSchema
().
getName
()))
.
append
(
'.'
);
.
append
(
'.'
);
}
}
buff
.
append
(
Parser
.
quoteIdentifier
(
functionAlias
.
getName
())).
append
(
'('
);
builder
.
append
(
Parser
.
quoteIdentifier
(
functionAlias
.
getName
())).
append
(
'('
);
for
(
Expression
e
:
args
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
buff
.
appendExceptFirst
(
", "
);
if
(
i
>
0
)
{
buff
.
append
(
e
.
getSQL
());
builder
.
append
(
", "
);
}
args
[
i
].
getSQL
(
builder
);
}
}
return
bu
ff
.
append
(
')'
).
toString
(
);
return
bu
ilder
.
append
(
')'
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/Parameter.java
浏览文件 @
07154efb
...
@@ -30,8 +30,8 @@ public class Parameter extends Expression implements ParameterInterface {
...
@@ -30,8 +30,8 @@ public class Parameter extends Expression implements ParameterInterface {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
return
"?"
+
(
index
+
1
);
return
builder
.
append
(
'?'
).
append
(
index
+
1
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/Rownum.java
浏览文件 @
07154efb
...
@@ -72,6 +72,11 @@ public class Rownum extends Expression {
...
@@ -72,6 +72,11 @@ public class Rownum extends Expression {
return
"ROWNUM()"
;
return
"ROWNUM()"
;
}
}
@Override
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
return
builder
.
append
(
"ROWNUM()"
);
}
@Override
@Override
public
void
updateAggregate
(
Session
session
,
int
stage
)
{
public
void
updateAggregate
(
Session
session
,
int
stage
)
{
// nothing to do
// nothing to do
...
...
h2/src/main/org/h2/expression/SequenceValue.java
浏览文件 @
07154efb
...
@@ -67,8 +67,9 @@ public class SequenceValue extends Expression {
...
@@ -67,8 +67,9 @@ public class SequenceValue extends Expression {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
return
"(NEXT VALUE FOR "
+
sequence
.
getSQL
()
+
")"
;
builder
.
append
(
"(NEXT VALUE FOR "
);
return
builder
.
append
(
sequence
.
getSQL
()).
append
(
')'
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/Subquery.java
浏览文件 @
07154efb
...
@@ -89,8 +89,8 @@ public class Subquery extends Expression {
...
@@ -89,8 +89,8 @@ public class Subquery extends Expression {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
return
"("
+
query
.
getPlanSQL
()
+
")"
;
return
builder
.
append
(
'('
).
append
(
query
.
getPlanSQL
()).
append
(
')'
)
;
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/TableFunction.java
浏览文件 @
07154efb
...
@@ -52,7 +52,8 @@ public class TableFunction extends Function {
...
@@ -52,7 +52,8 @@ public class TableFunction extends Function {
int
i
=
0
;
int
i
=
0
;
for
(
Expression
e
:
args
)
{
for
(
Expression
e
:
args
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
columnList
[
i
++].
getCreateSQL
()).
append
(
'='
).
append
(
e
.
getSQL
());
buff
.
append
(
columnList
[
i
++].
getCreateSQL
()).
append
(
'='
);
e
.
getSQL
(
buff
.
builder
());
}
}
return
buff
.
append
(
')'
).
toString
();
return
buff
.
append
(
')'
).
toString
();
}
}
...
...
h2/src/main/org/h2/expression/UnaryOperation.java
浏览文件 @
07154efb
...
@@ -24,10 +24,11 @@ public class UnaryOperation extends Expression {
...
@@ -24,10 +24,11 @@ public class UnaryOperation extends Expression {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
// don't remove the space, otherwise it might end up some thing like
// don't remove the space, otherwise it might end up some thing like
// --1 which is a line remark
// --1 which is a line remark
return
"(- "
+
arg
.
getSQL
()
+
')'
;
builder
.
append
(
"(- "
);
return
arg
.
getSQL
(
builder
).
append
(
')'
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/ValueExpression.java
浏览文件 @
07154efb
...
@@ -142,6 +142,16 @@ public class ValueExpression extends Expression {
...
@@ -142,6 +142,16 @@ public class ValueExpression extends Expression {
return
value
.
getSQL
();
return
value
.
getSQL
();
}
}
@Override
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
if
(
this
==
DEFAULT
)
{
builder
.
append
(
"DEFAULT"
);
}
else
{
builder
.
append
(
value
.
getSQL
());
}
return
builder
;
}
@Override
@Override
public
void
updateAggregate
(
Session
session
,
int
stage
)
{
public
void
updateAggregate
(
Session
session
,
int
stage
)
{
// nothing to do
// nothing to do
...
...
h2/src/main/org/h2/expression/Variable.java
浏览文件 @
07154efb
...
@@ -41,8 +41,8 @@ public class Variable extends Expression {
...
@@ -41,8 +41,8 @@ public class Variable extends Expression {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
return
"@"
+
Parser
.
quoteIdentifier
(
name
);
return
builder
.
append
(
'@'
).
append
(
Parser
.
quoteIdentifier
(
name
)
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/Wildcard.java
浏览文件 @
07154efb
...
@@ -116,8 +116,7 @@ public class Wildcard extends Expression {
...
@@ -116,8 +116,7 @@ public class Wildcard extends Expression {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
StringBuilder
builder
=
new
StringBuilder
();
if
(
table
!=
null
)
{
if
(
table
!=
null
)
{
builder
.
append
(
StringUtils
.
quoteIdentifier
(
table
)).
append
(
'.'
);
builder
.
append
(
StringUtils
.
quoteIdentifier
(
table
)).
append
(
'.'
);
}
}
...
@@ -128,12 +127,11 @@ public class Wildcard extends Expression {
...
@@ -128,12 +127,11 @@ public class Wildcard extends Expression {
if
(
i
>
0
)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
builder
.
append
(
", "
);
}
}
ExpressionColumn
ec
=
exceptColumns
.
get
(
i
);
exceptColumns
.
get
(
i
).
getSQL
(
builder
);
builder
.
append
(
ec
.
getSQL
());
}
}
builder
.
append
(
')'
);
builder
.
append
(
')'
);
}
}
return
builder
.
toString
()
;
return
builder
;
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
07154efb
...
@@ -159,7 +159,8 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
...
@@ -159,7 +159,8 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
@Override
@Override
protected
StringBuilder
appendTailConditions
(
StringBuilder
builder
)
{
protected
StringBuilder
appendTailConditions
(
StringBuilder
builder
)
{
if
(
filterCondition
!=
null
)
{
if
(
filterCondition
!=
null
)
{
builder
.
append
(
" FILTER (WHERE "
).
append
(
filterCondition
.
getSQL
()).
append
(
')'
);
builder
.
append
(
" FILTER (WHERE "
);
filterCondition
.
getSQL
(
builder
).
append
(
')'
);
}
}
return
super
.
appendTailConditions
(
builder
);
return
super
.
appendTailConditions
(
builder
);
}
}
...
...
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
07154efb
...
@@ -729,39 +729,40 @@ public class Aggregate extends AbstractAggregate {
...
@@ -729,39 +729,40 @@ public class Aggregate extends AbstractAggregate {
return
displaySize
;
return
displaySize
;
}
}
private
String
getSQLGroupConcat
(
)
{
private
String
Builder
getSQLGroupConcat
(
StringBuilder
builder
)
{
StringBuilder
buff
=
new
StringBuilder
(
"GROUP_CONCAT("
);
builder
.
append
(
"GROUP_CONCAT("
);
if
(
distinct
)
{
if
(
distinct
)
{
bu
ff
.
append
(
"DISTINCT "
);
bu
ilder
.
append
(
"DISTINCT "
);
}
}
buff
.
append
(
on
.
getSQL
()
);
on
.
getSQL
(
builder
);
Window
.
appendOrderBy
(
bu
ff
,
orderByList
);
Window
.
appendOrderBy
(
bu
ilder
,
orderByList
);
if
(
groupConcatSeparator
!=
null
)
{
if
(
groupConcatSeparator
!=
null
)
{
buff
.
append
(
" SEPARATOR "
).
append
(
groupConcatSeparator
.
getSQL
());
builder
.
append
(
" SEPARATOR "
);
groupConcatSeparator
.
getSQL
(
builder
);
}
}
bu
ff
.
append
(
')'
);
bu
ilder
.
append
(
')'
);
return
appendTailConditions
(
bu
ff
).
toString
(
);
return
appendTailConditions
(
bu
ilder
);
}
}
private
String
getSQLArrayAggregate
(
)
{
private
String
Builder
getSQLArrayAggregate
(
StringBuilder
builder
)
{
StringBuilder
buff
=
new
StringBuilder
(
"ARRAY_AGG("
);
builder
.
append
(
"ARRAY_AGG("
);
if
(
distinct
)
{
if
(
distinct
)
{
bu
ff
.
append
(
"DISTINCT "
);
bu
ilder
.
append
(
"DISTINCT "
);
}
}
buff
.
append
(
on
.
getSQL
()
);
on
.
getSQL
(
builder
);
Window
.
appendOrderBy
(
bu
ff
,
orderByList
);
Window
.
appendOrderBy
(
bu
ilder
,
orderByList
);
bu
ff
.
append
(
')'
);
bu
ilder
.
append
(
')'
);
return
appendTailConditions
(
bu
ff
).
toString
(
);
return
appendTailConditions
(
bu
ilder
);
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
String
text
;
String
text
;
switch
(
type
)
{
switch
(
type
)
{
case
GROUP_CONCAT:
case
GROUP_CONCAT:
return
getSQLGroupConcat
();
return
getSQLGroupConcat
(
builder
);
case
COUNT_ALL:
case
COUNT_ALL:
return
appendTailConditions
(
new
StringBuilder
().
append
(
"COUNT(*)"
)).
toString
(
);
return
appendTailConditions
(
builder
.
append
(
"COUNT(*)"
)
);
case
COUNT:
case
COUNT:
text
=
"COUNT"
;
text
=
"COUNT"
;
break
;
break
;
...
@@ -811,7 +812,7 @@ public class Aggregate extends AbstractAggregate {
...
@@ -811,7 +812,7 @@ public class Aggregate extends AbstractAggregate {
text
=
"MEDIAN"
;
text
=
"MEDIAN"
;
break
;
break
;
case
ARRAY_AGG:
case
ARRAY_AGG:
return
getSQLArrayAggregate
();
return
getSQLArrayAggregate
(
builder
);
case
MODE:
case
MODE:
text
=
"MODE"
;
text
=
"MODE"
;
break
;
break
;
...
@@ -821,13 +822,14 @@ public class Aggregate extends AbstractAggregate {
...
@@ -821,13 +822,14 @@ public class Aggregate extends AbstractAggregate {
default
:
default
:
throw
DbException
.
throwInternalError
(
"type="
+
type
);
throw
DbException
.
throwInternalError
(
"type="
+
type
);
}
}
StringBuilder
builder
=
new
StringBuilder
()
.
append
(
text
);
builder
.
append
(
text
);
if
(
distinct
)
{
if
(
distinct
)
{
builder
.
append
(
"(DISTINCT "
).
append
(
on
.
getSQL
()).
append
(
')'
);
builder
.
append
(
"(DISTINCT "
);
on
.
getSQL
(
builder
).
append
(
')'
);
}
else
{
}
else
{
builder
.
append
(
StringUtils
.
enclose
(
on
.
getSQL
()));
builder
.
append
(
StringUtils
.
enclose
(
on
.
getSQL
()));
}
}
return
appendTailConditions
(
builder
)
.
toString
()
;
return
appendTailConditions
(
builder
);
}
}
private
Index
getMinMaxColumnIndex
()
{
private
Index
getMinMaxColumnIndex
()
{
...
...
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
浏览文件 @
07154efb
...
@@ -17,7 +17,6 @@ import org.h2.expression.ExpressionVisitor;
...
@@ -17,7 +17,6 @@ import org.h2.expression.ExpressionVisitor;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.DataType
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueArray
;
...
@@ -68,15 +67,16 @@ public class JavaAggregate extends AbstractAggregate {
...
@@ -68,15 +67,16 @@ public class JavaAggregate extends AbstractAggregate {
}
}
@Override
@Override
public
String
getSQL
()
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
StatementBuilder
buff
=
new
StatementBuilder
();
builder
.
append
(
Parser
.
quoteIdentifier
(
userAggregate
.
getName
())).
append
(
'('
);
buff
.
append
(
Parser
.
quoteIdentifier
(
userAggregate
.
getName
())).
append
(
'('
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
for
(
Expression
e
:
args
)
{
if
(
i
>
0
)
{
buff
.
appendExceptFirst
(
", "
);
builder
.
append
(
", "
);
buff
.
append
(
e
.
getSQL
());
}
args
[
i
].
getSQL
(
builder
);
}
}
bu
ff
.
append
(
')'
);
bu
ilder
.
append
(
')'
);
return
appendTailConditions
(
bu
ff
.
builder
()).
toString
(
);
return
appendTailConditions
(
bu
ilder
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/aggregate/Window.java
浏览文件 @
07154efb
...
@@ -49,7 +49,7 @@ public final class Window {
...
@@ -49,7 +49,7 @@ public final class Window {
if
(
i
>
0
)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
builder
.
append
(
", "
);
}
}
builder
.
append
(
o
.
expression
.
getSQL
()
);
o
.
expression
.
getSQL
(
builder
);
SortOrder
.
typeToString
(
builder
,
o
.
sortType
);
SortOrder
.
typeToString
(
builder
,
o
.
sortType
);
}
}
}
}
...
...
h2/src/main/org/h2/expression/aggregate/WindowFrameBound.java
浏览文件 @
07154efb
...
@@ -62,7 +62,8 @@ public class WindowFrameBound {
...
@@ -62,7 +62,8 @@ public class WindowFrameBound {
*/
*/
public
String
getSQL
(
boolean
following
)
{
public
String
getSQL
(
boolean
following
)
{
if
(
type
==
WindowFrameBoundType
.
PRECEDING
||
type
==
WindowFrameBoundType
.
FOLLOWING
)
{
if
(
type
==
WindowFrameBoundType
.
PRECEDING
||
type
==
WindowFrameBoundType
.
FOLLOWING
)
{
return
value
.
getSQL
()
+
' '
+
type
.
getSQL
();
StringBuilder
builder
=
new
StringBuilder
();
return
value
.
getSQL
(
builder
).
append
(
' '
).
append
(
type
.
getSQL
()).
toString
();
}
}
return
type
.
getSQL
();
return
type
.
getSQL
();
}
}
...
...
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
浏览文件 @
07154efb
...
@@ -515,15 +515,15 @@ public class WindowFunction extends DataAnalysisOperation {
...
@@ -515,15 +515,15 @@ public class WindowFunction extends DataAnalysisOperation {
}
}
@Override
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
String
name
=
type
.
getSQL
();
String
name
=
type
.
getSQL
();
StringBuilder
builder
=
new
StringBuilder
()
.
append
(
name
).
append
(
'('
);
builder
.
append
(
name
).
append
(
'('
);
if
(
args
!=
null
)
{
if
(
args
!=
null
)
{
for
(
int
i
=
0
,
numArgs
=
args
.
length
;
i
<
numArgs
;
i
++)
{
for
(
int
i
=
0
,
numArgs
=
args
.
length
;
i
<
numArgs
;
i
++)
{
if
(
i
>
0
)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
builder
.
append
(
", "
);
}
}
builder
.
append
(
args
[
i
].
getSQL
()
);
args
[
i
].
getSQL
(
builder
);
}
}
}
}
builder
.
append
(
')'
);
builder
.
append
(
')'
);
...
@@ -542,7 +542,7 @@ public class WindowFunction extends DataAnalysisOperation {
...
@@ -542,7 +542,7 @@ public class WindowFunction extends DataAnalysisOperation {
default
:
default
:
}
}
}
}
return
appendTailConditions
(
builder
)
.
toString
()
;
return
appendTailConditions
(
builder
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/index/IndexCondition.java
浏览文件 @
07154efb
...
@@ -202,7 +202,7 @@ public class IndexCondition {
...
@@ -202,7 +202,7 @@ public class IndexCondition {
buff
.
append
(
" IN("
);
buff
.
append
(
" IN("
);
for
(
Expression
e
:
expressionList
)
{
for
(
Expression
e
:
expressionList
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
e
.
getSQL
(
buff
.
builder
());
}
}
buff
.
append
(
')'
);
buff
.
append
(
')'
);
break
;
break
;
...
@@ -218,7 +218,7 @@ public class IndexCondition {
...
@@ -218,7 +218,7 @@ public class IndexCondition {
DbException
.
throwInternalError
(
"type="
+
compareType
);
DbException
.
throwInternalError
(
"type="
+
compareType
);
}
}
if
(
expression
!=
null
)
{
if
(
expression
!=
null
)
{
buff
.
append
(
expression
.
getSQL
());
expression
.
getSQL
(
buff
.
builder
());
}
}
return
buff
.
toString
();
return
buff
.
toString
();
}
}
...
...
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
07154efb
...
@@ -72,11 +72,15 @@ public class RangeTable extends Table {
...
@@ -72,11 +72,15 @@ public class RangeTable extends Table {
@Override
@Override
public
String
getSQL
()
{
public
String
getSQL
()
{
String
sql
=
NAME
+
"("
+
min
.
getSQL
()
+
", "
+
max
.
getSQL
();
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
NAME
).
append
(
'('
);
min
.
getSQL
(
builder
).
append
(
", "
);
max
.
getSQL
(
builder
);
if
(
step
!=
null
)
{
if
(
step
!=
null
)
{
sql
+=
", "
+
step
.
getSQL
();
builder
.
append
(
", "
);
step
.
getSQL
(
builder
);
}
}
return
sql
+
")"
;
return
builder
.
append
(
')'
).
toString
()
;
}
}
@Override
@Override
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论