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 {
for
(
Expression
e
:
list
)
{
buff
.
appendExceptFirst
(
", "
);
if
(
e
!=
null
)
{
buff
.
append
(
e
.
getSQL
());
e
.
getSQL
(
buff
.
builder
());
}
}
return
buff
.
toString
();
...
...
h2/src/main/org/h2/command/dml/Insert.java
浏览文件 @
07154efb
...
...
@@ -421,7 +421,8 @@ public class Insert extends Prepared implements ResultTarget {
for
(
Column
column
:
duplicateKeyAssignmentMap
.
keySet
())
{
buff
.
appendExceptFirst
(
", "
);
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 "
);
Index
foundIndex
=
(
Index
)
de
.
getSource
();
...
...
@@ -429,7 +430,7 @@ public class Insert extends Prepared implements ResultTarget {
throw
DbException
.
getUnsupportedException
(
"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
();
Update
command
=
(
Update
)
session
.
prepare
(
sql
);
command
.
setUpdateToCurrentValuesReturnsZero
(
true
);
...
...
h2/src/main/org/h2/command/dml/Merge.java
浏览文件 @
07154efb
...
...
@@ -248,7 +248,7 @@ public class Merge extends Prepared {
if
(
e
==
null
)
{
buff
.
append
(
"DEFAULT"
);
}
else
{
buff
.
append
(
e
.
getSQL
());
e
.
getSQL
(
buff
.
builder
());
}
}
buff
.
append
(
')'
);
...
...
h2/src/main/org/h2/command/dml/Replace.java
浏览文件 @
07154efb
...
...
@@ -228,7 +228,7 @@ public class Replace extends Prepared {
if
(
e
==
null
)
{
buff
.
append
(
"DEFAULT"
);
}
else
{
buff
.
append
(
e
.
getSQL
());
e
.
getSQL
(
buff
.
builder
());
}
}
buff
.
append
(
')'
);
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
07154efb
...
...
@@ -1327,7 +1327,7 @@ public class Select extends Query {
buff
.
append
(
" ON("
);
for
(
Expression
distinctExpression:
distinctExpressions
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
distinctExpression
.
getSQL
());
distinctExpression
.
getSQL
(
buff
.
builder
());
}
buff
.
append
(
')'
);
buff
.
resetCount
();
...
...
h2/src/main/org/h2/command/dml/SelectOrderBy.java
浏览文件 @
07154efb
...
...
@@ -33,9 +33,10 @@ public class SelectOrderBy {
public
String
getSQL
()
{
StringBuilder
buff
=
new
StringBuilder
();
if
(
expression
!=
null
)
{
buff
.
append
(
'='
).
append
(
expression
.
getSQL
());
buff
.
append
(
'='
);
expression
.
getSQL
(
buff
);
}
else
{
buff
.
append
(
columnIndexExpr
.
getSQL
()
);
columnIndexExpr
.
getSQL
(
buff
);
}
SortOrder
.
typeToString
(
buff
,
sortType
);
return
buff
.
toString
();
...
...
h2/src/main/org/h2/command/dml/Update.java
浏览文件 @
07154efb
...
...
@@ -222,7 +222,8 @@ public class Update extends Prepared {
for
(
Column
c
:
columns
)
{
Expression
e
=
expressionMap
.
get
(
c
);
buff
.
appendExceptFirst
(
",\n "
);
buff
.
append
(
c
.
getName
()).
append
(
" = "
).
append
(
e
.
getSQL
());
buff
.
append
(
c
.
getName
()).
append
(
" = "
);
e
.
getSQL
(
buff
.
builder
());
}
if
(
condition
!=
null
)
{
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 {
}
private
String
getShortDescription
()
{
return
getName
()
+
": "
+
expr
.
getSQL
();
StringBuilder
builder
=
new
StringBuilder
().
append
(
getName
()).
append
(
": "
);
expr
.
getSQL
(
builder
);
return
builder
.
toString
();
}
@Override
...
...
@@ -140,8 +142,11 @@ public class ConstraintCheck extends Constraint {
// don't check at startup
return
;
}
String
sql
=
"SELECT 1 FROM "
+
filter
.
getTable
().
getSQL
()
+
" WHERE NOT("
+
expr
.
getSQL
()
+
")"
;
StringBuilder
builder
=
new
StringBuilder
().
append
(
"SELECT 1 FROM "
)
.
append
(
filter
.
getTable
().
getSQL
())
.
append
(
" WHERE NOT("
);
expr
.
getSQL
(
builder
).
append
(
')'
);
String
sql
=
builder
.
toString
();
ResultInterface
r
=
session
.
prepare
(
sql
).
query
(
1
);
if
(
r
.
next
())
{
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 {
}
@Override
public
String
getSQL
(
)
{
return
expr
.
getSQL
(
)
+
" AS "
+
Parser
.
quoteIdentifier
(
alias
);
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
return
expr
.
getSQL
(
builder
).
append
(
" AS "
).
append
(
Parser
.
quoteIdentifier
(
alias
)
);
}
@Override
...
...
h2/src/main/org/h2/expression/BinaryOperation.java
浏览文件 @
07154efb
...
...
@@ -68,10 +68,12 @@ public class BinaryOperation extends Expression {
}
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
// don't remove the space, otherwise it might end up some thing like
// --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
()
{
...
...
h2/src/main/org/h2/expression/CompareLike.java
浏览文件 @
07154efb
...
...
@@ -76,17 +76,20 @@ public class CompareLike extends Condition {
}
@Override
public
String
getSQL
(
)
{
String
sql
;
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
'('
)
;
if
(
regexp
)
{
sql
=
left
.
getSQL
()
+
" REGEXP "
+
right
.
getSQL
();
left
.
getSQL
(
builder
).
append
(
" REGEXP "
);
right
.
getSQL
(
builder
);
}
else
{
sql
=
left
.
getSQL
()
+
" LIKE "
+
right
.
getSQL
();
left
.
getSQL
(
builder
).
append
(
" LIKE "
);
right
.
getSQL
(
builder
);
if
(
escape
!=
null
)
{
sql
+=
" ESCAPE "
+
escape
.
getSQL
();
builder
.
append
(
" ESCAPE "
);
escape
.
getSQL
(
builder
);
}
}
return
"("
+
sql
+
")"
;
return
builder
.
append
(
')'
)
;
}
@Override
...
...
h2/src/main/org/h2/expression/Comparison.java
浏览文件 @
07154efb
...
...
@@ -126,23 +126,25 @@ public class Comparison extends Condition {
}
@Override
public
String
getSQL
(
)
{
String
sql
;
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
'('
)
;
switch
(
compareType
)
{
case
IS_NULL:
sql
=
left
.
getSQL
()
+
" IS NULL"
;
left
.
getSQL
(
builder
).
append
(
" IS NULL"
)
;
break
;
case
IS_NOT_NULL:
sql
=
left
.
getSQL
()
+
" IS NOT NULL"
;
left
.
getSQL
(
builder
).
append
(
" IS NOT NULL"
)
;
break
;
case
SPATIAL_INTERSECTS:
sql
=
"INTERSECTS("
+
left
.
getSQL
()
+
", "
+
right
.
getSQL
()
+
")"
;
builder
.
append
(
"INTERSECTS("
);
left
.
getSQL
(
builder
).
append
(
", "
);
right
.
getSQL
(
builder
).
append
(
')'
);
break
;
default
:
sql
=
left
.
getSQL
()
+
" "
+
getCompareOperator
(
compareType
)
+
" "
+
right
.
getSQL
(
);
left
.
getSQL
(
builder
).
append
(
' '
).
append
(
getCompareOperator
(
compareType
)).
append
(
' '
);
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 {
}
@Override
public
String
getSQL
()
{
String
sql
;
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
'('
);
left
.
getSQL
(
builder
);
switch
(
andOrType
)
{
case
AND:
sql
=
left
.
getSQL
()
+
"\n AND "
+
right
.
getSQL
(
);
builder
.
append
(
"\n AND "
);
break
;
case
OR:
sql
=
left
.
getSQL
()
+
"\n OR "
+
right
.
getSQL
(
);
builder
.
append
(
"\n OR "
);
break
;
default
:
throw
DbException
.
throwInternalError
(
"andOrType="
+
andOrType
);
}
return
"("
+
sql
+
")"
;
return
right
.
getSQL
(
builder
).
append
(
')'
)
;
}
@Override
...
...
h2/src/main/org/h2/expression/ConditionExists.java
浏览文件 @
07154efb
...
...
@@ -41,8 +41,10 @@ public class ConditionExists extends Condition {
}
@Override
public
String
getSQL
()
{
return
"EXISTS(\n"
+
StringUtils
.
indent
(
query
.
getPlanSQL
(),
4
,
false
)
+
")"
;
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
"EXISTS(\n"
);
builder
.
append
(
StringUtils
.
indent
(
query
.
getPlanSQL
(),
4
,
false
));
return
builder
.
append
(
')'
);
}
@Override
...
...
h2/src/main/org/h2/expression/ConditionIn.java
浏览文件 @
07154efb
...
...
@@ -11,7 +11,6 @@ import org.h2.engine.Session;
import
org.h2.index.IndexCondition
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
import
org.h2.value.ValueBoolean
;
import
org.h2.value.ValueNull
;
...
...
@@ -152,14 +151,16 @@ public class ConditionIn extends Condition {
}
@Override
public
String
getSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
buff
.
append
(
left
.
getSQL
()).
append
(
" IN("
);
for
(
Expression
e
:
valueList
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
'('
);
left
.
getSQL
(
builder
).
append
(
" IN("
);
for
(
int
i
=
0
;
i
<
valueList
.
size
();
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
valueList
.
get
(
i
).
getSQL
(
builder
);
}
return
bu
ff
.
append
(
"))"
).
toString
(
);
return
bu
ilder
.
append
(
"))"
);
}
@Override
...
...
h2/src/main/org/h2/expression/ConditionInConstantSet.java
浏览文件 @
07154efb
...
...
@@ -15,7 +15,6 @@ import org.h2.index.IndexCondition;
import
org.h2.message.DbException
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.ExtTypeInfo
;
import
org.h2.value.Value
;
import
org.h2.value.ValueBoolean
;
...
...
@@ -114,14 +113,16 @@ public class ConditionInConstantSet extends Condition {
}
@Override
public
String
getSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
buff
.
append
(
left
.
getSQL
()).
append
(
" IN("
);
for
(
Expression
e
:
valueList
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
}
return
buff
.
append
(
"))"
).
toString
();
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
'('
);
left
.
getSQL
(
builder
).
append
(
" IN("
);
for
(
int
i
=
0
,
s
=
valueList
.
size
();
i
<
s
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
valueList
.
get
(
i
).
getSQL
(
builder
);
}
return
builder
.
append
(
"))"
);
}
@Override
...
...
h2/src/main/org/h2/expression/ConditionInParameter.java
浏览文件 @
07154efb
...
...
@@ -140,8 +140,10 @@ public class ConditionInParameter extends Condition {
}
@Override
public
String
getSQL
()
{
return
'('
+
left
.
getSQL
()
+
" = ANY("
+
parameter
.
getSQL
()
+
"))"
;
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
'('
);
left
.
getSQL
(
builder
).
append
(
" = ANY("
);
return
parameter
.
getSQL
(
builder
).
append
(
"))"
);
}
@Override
...
...
h2/src/main/org/h2/expression/ConditionInSelect.java
浏览文件 @
07154efb
...
...
@@ -129,23 +129,21 @@ public class ConditionInSelect extends Condition {
}
@Override
public
String
getSQL
(
)
{
StringBuilder
buff
=
new
StringBuilder
(
);
buff
.
append
(
'('
).
append
(
left
.
getSQL
()
).
append
(
' '
);
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
'('
);
left
.
getSQL
(
builder
).
append
(
' '
);
if
(
all
)
{
bu
ff
.
append
(
Comparison
.
getCompareOperator
(
compareType
)).
bu
ilder
.
append
(
Comparison
.
getCompareOperator
(
compareType
)).
append
(
" ALL"
);
}
else
{
if
(
compareType
==
Comparison
.
EQUAL
)
{
bu
ff
.
append
(
"IN"
);
bu
ilder
.
append
(
"IN"
);
}
else
{
bu
ff
.
append
(
Comparison
.
getCompareOperator
(
compareType
)).
bu
ilder
.
append
(
Comparison
.
getCompareOperator
(
compareType
)).
append
(
" ANY"
);
}
}
buff
.
append
(
"(\n"
).
append
(
StringUtils
.
indent
(
query
.
getPlanSQL
(),
4
,
false
)).
append
(
"))"
);
return
buff
.
toString
();
return
builder
.
append
(
"(\n"
).
append
(
StringUtils
.
indent
(
query
.
getPlanSQL
(),
4
,
false
)).
append
(
"))"
);
}
@Override
...
...
h2/src/main/org/h2/expression/ConditionNot.java
浏览文件 @
07154efb
...
...
@@ -65,8 +65,9 @@ public class ConditionNot extends Condition {
}
@Override
public
String
getSQL
()
{
return
"(NOT "
+
condition
.
getSQL
()
+
")"
;
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
"(NOT "
);
return
condition
.
getSQL
(
builder
).
append
(
')'
);
}
@Override
...
...
h2/src/main/org/h2/expression/Expression.java
浏览文件 @
07154efb
...
...
@@ -110,7 +110,22 @@ public abstract class Expression {
*
* @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
...
...
h2/src/main/org/h2/expression/ExpressionColumn.java
浏览文件 @
07154efb
...
...
@@ -55,23 +55,22 @@ public class ExpressionColumn extends Expression {
}
@Override
public
String
getSQL
()
{
String
sql
;
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
boolean
quote
=
database
.
getSettings
().
databaseToUpper
;
if
(
column
!=
null
)
{
sql
=
column
.
getSQL
();
}
else
{
sql
=
quote
?
Parser
.
quoteIdentifier
(
columnName
)
:
columnName
;
if
(
schemaName
!=
null
)
{
String
s
=
quote
?
Parser
.
quoteIdentifier
(
schemaName
)
:
schemaName
;
builder
.
append
(
s
).
append
(
'.'
);
}
if
(
tableAlias
!=
null
)
{
String
a
=
quote
?
Parser
.
quoteIdentifier
(
tableAlias
)
:
tableAlias
;
sql
=
a
+
"."
+
sql
;
builder
.
append
(
a
).
append
(
'.'
)
;
}
if
(
schemaName
!=
null
)
{
String
s
=
quote
?
Parser
.
quoteIdentifier
(
schemaName
)
:
schemaName
;
sql
=
s
+
"."
+
sql
;
if
(
column
!=
null
)
{
builder
.
append
(
column
.
getSQL
());
}
else
{
builder
.
append
(
quote
?
Parser
.
quoteIdentifier
(
columnName
)
:
columnName
);
}
return
sql
;
return
builder
;
}
public
TableFilter
getTableFilter
()
{
...
...
h2/src/main/org/h2/expression/ExpressionList.java
浏览文件 @
07154efb
...
...
@@ -9,7 +9,6 @@ import org.h2.engine.Session;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -85,16 +84,18 @@ public class ExpressionList extends Expression {
}
@Override
public
String
getSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"("
);
for
(
Expression
e:
list
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
'('
);
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
list
[
i
].
getSQL
(
builder
);
}
if
(
list
.
length
==
1
)
{
bu
ff
.
append
(
','
);
bu
ilder
.
append
(
','
);
}
return
bu
ff
.
append
(
')'
).
toString
(
);
return
bu
ilder
.
append
(
')'
);
}
@Override
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
07154efb
...
...
@@ -50,7 +50,6 @@ import org.h2.util.DateTimeUtils;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.ToChar
;
import
org.h2.util.ToDateParser
;
...
...
@@ -2582,36 +2581,41 @@ public class Function extends Expression implements FunctionCall {
}
@Override
public
String
getSQL
(
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
info
.
name
);
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
info
.
name
);
if
(
info
.
type
==
CASE
)
{
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
)
{
buff
.
append
(
" WHEN "
).
append
(
args
[
i
].
getSQL
());
buff
.
append
(
" THEN "
).
append
(
args
[
i
+
1
].
getSQL
());
builder
.
append
(
" WHEN "
);
args
[
i
].
getSQL
(
builder
);
builder
.
append
(
" THEN "
);
args
[
i
+
1
].
getSQL
(
builder
);
}
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
)
{
case
CAST:
{
buff
.
append
(
args
[
0
].
getSQL
()
).
append
(
" AS "
).
args
[
0
].
getSQL
(
builder
).
append
(
" AS "
).
append
(
new
Column
(
null
,
dataType
,
precision
,
scale
,
displaySize
,
extTypeInfo
).
getCreateSQL
());
break
;
}
case
CONVERT:
{
if
(
database
.
getMode
().
swapConvertFunctionParameters
)
{
bu
ff
.
append
(
new
Column
(
null
,
dataType
,
precision
,
bu
ilder
.
append
(
new
Column
(
null
,
dataType
,
precision
,
scale
,
displaySize
).
getCreateSQL
()).
append
(
','
).
append
(
args
[
0
].
getSQL
());
append
(
','
);
args
[
0
].
getSQL
(
builder
);
}
else
{
buff
.
append
(
args
[
0
].
getSQL
()
).
append
(
','
).
args
[
0
].
getSQL
(
builder
).
append
(
','
).
append
(
new
Column
(
null
,
dataType
,
precision
,
scale
,
displaySize
).
getCreateSQL
());
}
...
...
@@ -2619,17 +2623,20 @@ public class Function extends Expression implements FunctionCall {
}
case
EXTRACT:
{
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
;
}
default
:
{
for
(
Expression
e
:
args
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
args
[
i
].
getSQL
(
builder
);
}
}
}
return
bu
ff
.
append
(
')'
).
toString
(
);
return
bu
ilder
.
append
(
')'
);
}
@Override
...
...
h2/src/main/org/h2/expression/IntervalOperation.java
浏览文件 @
07154efb
...
...
@@ -113,8 +113,10 @@ public class IntervalOperation extends Expression {
}
@Override
public
String
getSQL
()
{
return
'('
+
left
.
getSQL
()
+
' '
+
getOperationToken
()
+
' '
+
right
.
getSQL
()
+
')'
;
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
'('
);
left
.
getSQL
(
builder
).
append
(
' '
).
append
(
getOperationToken
()).
append
(
' '
);
return
right
.
getSQL
(
builder
).
append
(
')'
);
}
private
char
getOperationToken
()
{
...
...
h2/src/main/org/h2/expression/JavaFunction.java
浏览文件 @
07154efb
...
...
@@ -11,7 +11,6 @@ import org.h2.engine.FunctionAlias;
import
org.h2.engine.Session
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -89,21 +88,22 @@ public class JavaFunction extends Expression implements FunctionCall {
}
@Override
public
String
getSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
();
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
// TODO always append the schema once FUNCTIONS_IN_SCHEMA is enabled
if
(
functionAlias
.
getDatabase
().
getSettings
().
functionsInSchema
||
!
functionAlias
.
getSchema
().
getName
().
equals
(
Constants
.
SCHEMA_MAIN
))
{
bu
ff
.
append
(
bu
ilder
.
append
(
Parser
.
quoteIdentifier
(
functionAlias
.
getSchema
().
getName
()))
.
append
(
'.'
);
}
buff
.
append
(
Parser
.
quoteIdentifier
(
functionAlias
.
getName
())).
append
(
'('
);
for
(
Expression
e
:
args
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
builder
.
append
(
Parser
.
quoteIdentifier
(
functionAlias
.
getName
())).
append
(
'('
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
args
[
i
].
getSQL
(
builder
);
}
return
bu
ff
.
append
(
')'
).
toString
(
);
return
bu
ilder
.
append
(
')'
);
}
@Override
...
...
h2/src/main/org/h2/expression/Parameter.java
浏览文件 @
07154efb
...
...
@@ -30,8 +30,8 @@ public class Parameter extends Expression implements ParameterInterface {
}
@Override
public
String
getSQL
(
)
{
return
"?"
+
(
index
+
1
);
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
return
builder
.
append
(
'?'
).
append
(
index
+
1
);
}
@Override
...
...
h2/src/main/org/h2/expression/Rownum.java
浏览文件 @
07154efb
...
...
@@ -72,6 +72,11 @@ public class Rownum extends Expression {
return
"ROWNUM()"
;
}
@Override
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
return
builder
.
append
(
"ROWNUM()"
);
}
@Override
public
void
updateAggregate
(
Session
session
,
int
stage
)
{
// nothing to do
...
...
h2/src/main/org/h2/expression/SequenceValue.java
浏览文件 @
07154efb
...
...
@@ -67,8 +67,9 @@ public class SequenceValue extends Expression {
}
@Override
public
String
getSQL
()
{
return
"(NEXT VALUE FOR "
+
sequence
.
getSQL
()
+
")"
;
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
"(NEXT VALUE FOR "
);
return
builder
.
append
(
sequence
.
getSQL
()).
append
(
')'
);
}
@Override
...
...
h2/src/main/org/h2/expression/Subquery.java
浏览文件 @
07154efb
...
...
@@ -89,8 +89,8 @@ public class Subquery extends Expression {
}
@Override
public
String
getSQL
(
)
{
return
"("
+
query
.
getPlanSQL
()
+
")"
;
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
return
builder
.
append
(
'('
).
append
(
query
.
getPlanSQL
()).
append
(
')'
)
;
}
@Override
...
...
h2/src/main/org/h2/expression/TableFunction.java
浏览文件 @
07154efb
...
...
@@ -52,7 +52,8 @@ public class TableFunction extends Function {
int
i
=
0
;
for
(
Expression
e
:
args
)
{
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
();
}
...
...
h2/src/main/org/h2/expression/UnaryOperation.java
浏览文件 @
07154efb
...
...
@@ -24,10 +24,11 @@ public class UnaryOperation extends Expression {
}
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
// don't remove the space, otherwise it might end up some thing like
// --1 which is a line remark
return
"(- "
+
arg
.
getSQL
()
+
')'
;
builder
.
append
(
"(- "
);
return
arg
.
getSQL
(
builder
).
append
(
')'
);
}
@Override
...
...
h2/src/main/org/h2/expression/ValueExpression.java
浏览文件 @
07154efb
...
...
@@ -142,6 +142,16 @@ public class ValueExpression extends Expression {
return
value
.
getSQL
();
}
@Override
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
if
(
this
==
DEFAULT
)
{
builder
.
append
(
"DEFAULT"
);
}
else
{
builder
.
append
(
value
.
getSQL
());
}
return
builder
;
}
@Override
public
void
updateAggregate
(
Session
session
,
int
stage
)
{
// nothing to do
...
...
h2/src/main/org/h2/expression/Variable.java
浏览文件 @
07154efb
...
...
@@ -41,8 +41,8 @@ public class Variable extends Expression {
}
@Override
public
String
getSQL
(
)
{
return
"@"
+
Parser
.
quoteIdentifier
(
name
);
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
return
builder
.
append
(
'@'
).
append
(
Parser
.
quoteIdentifier
(
name
)
);
}
@Override
...
...
h2/src/main/org/h2/expression/Wildcard.java
浏览文件 @
07154efb
...
...
@@ -116,8 +116,7 @@ public class Wildcard extends Expression {
}
@Override
public
String
getSQL
()
{
StringBuilder
builder
=
new
StringBuilder
();
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
if
(
table
!=
null
)
{
builder
.
append
(
StringUtils
.
quoteIdentifier
(
table
)).
append
(
'.'
);
}
...
...
@@ -128,12 +127,11 @@ public class Wildcard extends Expression {
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
ExpressionColumn
ec
=
exceptColumns
.
get
(
i
);
builder
.
append
(
ec
.
getSQL
());
exceptColumns
.
get
(
i
).
getSQL
(
builder
);
}
builder
.
append
(
')'
);
}
return
builder
.
toString
()
;
return
builder
;
}
@Override
...
...
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
07154efb
...
...
@@ -159,7 +159,8 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
@Override
protected
StringBuilder
appendTailConditions
(
StringBuilder
builder
)
{
if
(
filterCondition
!=
null
)
{
builder
.
append
(
" FILTER (WHERE "
).
append
(
filterCondition
.
getSQL
()).
append
(
')'
);
builder
.
append
(
" FILTER (WHERE "
);
filterCondition
.
getSQL
(
builder
).
append
(
')'
);
}
return
super
.
appendTailConditions
(
builder
);
}
...
...
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
07154efb
...
...
@@ -729,39 +729,40 @@ public class Aggregate extends AbstractAggregate {
return
displaySize
;
}
private
String
getSQLGroupConcat
(
)
{
StringBuilder
buff
=
new
StringBuilder
(
"GROUP_CONCAT("
);
private
String
Builder
getSQLGroupConcat
(
StringBuilder
builder
)
{
builder
.
append
(
"GROUP_CONCAT("
);
if
(
distinct
)
{
bu
ff
.
append
(
"DISTINCT "
);
bu
ilder
.
append
(
"DISTINCT "
);
}
buff
.
append
(
on
.
getSQL
()
);
Window
.
appendOrderBy
(
bu
ff
,
orderByList
);
on
.
getSQL
(
builder
);
Window
.
appendOrderBy
(
bu
ilder
,
orderByList
);
if
(
groupConcatSeparator
!=
null
)
{
buff
.
append
(
" SEPARATOR "
).
append
(
groupConcatSeparator
.
getSQL
());
builder
.
append
(
" SEPARATOR "
);
groupConcatSeparator
.
getSQL
(
builder
);
}
bu
ff
.
append
(
')'
);
return
appendTailConditions
(
bu
ff
).
toString
(
);
bu
ilder
.
append
(
')'
);
return
appendTailConditions
(
bu
ilder
);
}
private
String
getSQLArrayAggregate
(
)
{
StringBuilder
buff
=
new
StringBuilder
(
"ARRAY_AGG("
);
private
String
Builder
getSQLArrayAggregate
(
StringBuilder
builder
)
{
builder
.
append
(
"ARRAY_AGG("
);
if
(
distinct
)
{
bu
ff
.
append
(
"DISTINCT "
);
bu
ilder
.
append
(
"DISTINCT "
);
}
buff
.
append
(
on
.
getSQL
()
);
Window
.
appendOrderBy
(
bu
ff
,
orderByList
);
bu
ff
.
append
(
')'
);
return
appendTailConditions
(
bu
ff
).
toString
(
);
on
.
getSQL
(
builder
);
Window
.
appendOrderBy
(
bu
ilder
,
orderByList
);
bu
ilder
.
append
(
')'
);
return
appendTailConditions
(
bu
ilder
);
}
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
String
text
;
switch
(
type
)
{
case
GROUP_CONCAT:
return
getSQLGroupConcat
();
return
getSQLGroupConcat
(
builder
);
case
COUNT_ALL:
return
appendTailConditions
(
new
StringBuilder
().
append
(
"COUNT(*)"
)).
toString
(
);
return
appendTailConditions
(
builder
.
append
(
"COUNT(*)"
)
);
case
COUNT:
text
=
"COUNT"
;
break
;
...
...
@@ -811,7 +812,7 @@ public class Aggregate extends AbstractAggregate {
text
=
"MEDIAN"
;
break
;
case
ARRAY_AGG:
return
getSQLArrayAggregate
();
return
getSQLArrayAggregate
(
builder
);
case
MODE:
text
=
"MODE"
;
break
;
...
...
@@ -821,13 +822,14 @@ public class Aggregate extends AbstractAggregate {
default
:
throw
DbException
.
throwInternalError
(
"type="
+
type
);
}
StringBuilder
builder
=
new
StringBuilder
()
.
append
(
text
);
builder
.
append
(
text
);
if
(
distinct
)
{
builder
.
append
(
"(DISTINCT "
).
append
(
on
.
getSQL
()).
append
(
')'
);
builder
.
append
(
"(DISTINCT "
);
on
.
getSQL
(
builder
).
append
(
')'
);
}
else
{
builder
.
append
(
StringUtils
.
enclose
(
on
.
getSQL
()));
}
return
appendTailConditions
(
builder
)
.
toString
()
;
return
appendTailConditions
(
builder
);
}
private
Index
getMinMaxColumnIndex
()
{
...
...
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
浏览文件 @
07154efb
...
...
@@ -17,7 +17,6 @@ import org.h2.expression.ExpressionVisitor;
import
org.h2.message.DbException
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -68,15 +67,16 @@ public class JavaAggregate extends AbstractAggregate {
}
@Override
public
String
getSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
();
buff
.
append
(
Parser
.
quoteIdentifier
(
userAggregate
.
getName
())).
append
(
'('
);
for
(
Expression
e
:
args
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
builder
.
append
(
Parser
.
quoteIdentifier
(
userAggregate
.
getName
())).
append
(
'('
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
args
[
i
].
getSQL
(
builder
);
}
bu
ff
.
append
(
')'
);
return
appendTailConditions
(
bu
ff
.
builder
()).
toString
(
);
bu
ilder
.
append
(
')'
);
return
appendTailConditions
(
bu
ilder
);
}
@Override
...
...
h2/src/main/org/h2/expression/aggregate/Window.java
浏览文件 @
07154efb
...
...
@@ -49,7 +49,7 @@ public final class Window {
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
builder
.
append
(
o
.
expression
.
getSQL
()
);
o
.
expression
.
getSQL
(
builder
);
SortOrder
.
typeToString
(
builder
,
o
.
sortType
);
}
}
...
...
h2/src/main/org/h2/expression/aggregate/WindowFrameBound.java
浏览文件 @
07154efb
...
...
@@ -62,7 +62,8 @@ public class WindowFrameBound {
*/
public
String
getSQL
(
boolean
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
();
}
...
...
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
浏览文件 @
07154efb
...
...
@@ -515,15 +515,15 @@ public class WindowFunction extends DataAnalysisOperation {
}
@Override
public
String
getSQL
(
)
{
public
String
Builder
getSQL
(
StringBuilder
builder
)
{
String
name
=
type
.
getSQL
();
StringBuilder
builder
=
new
StringBuilder
()
.
append
(
name
).
append
(
'('
);
builder
.
append
(
name
).
append
(
'('
);
if
(
args
!=
null
)
{
for
(
int
i
=
0
,
numArgs
=
args
.
length
;
i
<
numArgs
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
builder
.
append
(
args
[
i
].
getSQL
()
);
args
[
i
].
getSQL
(
builder
);
}
}
builder
.
append
(
')'
);
...
...
@@ -542,7 +542,7 @@ public class WindowFunction extends DataAnalysisOperation {
default
:
}
}
return
appendTailConditions
(
builder
)
.
toString
()
;
return
appendTailConditions
(
builder
);
}
@Override
...
...
h2/src/main/org/h2/index/IndexCondition.java
浏览文件 @
07154efb
...
...
@@ -202,7 +202,7 @@ public class IndexCondition {
buff
.
append
(
" IN("
);
for
(
Expression
e
:
expressionList
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
.
getSQL
());
e
.
getSQL
(
buff
.
builder
());
}
buff
.
append
(
')'
);
break
;
...
...
@@ -218,7 +218,7 @@ public class IndexCondition {
DbException
.
throwInternalError
(
"type="
+
compareType
);
}
if
(
expression
!=
null
)
{
buff
.
append
(
expression
.
getSQL
());
expression
.
getSQL
(
buff
.
builder
());
}
return
buff
.
toString
();
}
...
...
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
07154efb
...
...
@@ -72,11 +72,15 @@ public class RangeTable extends Table {
@Override
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
)
{
sql
+=
", "
+
step
.
getSQL
();
builder
.
append
(
", "
);
step
.
getSQL
(
builder
);
}
return
sql
+
")"
;
return
builder
.
append
(
')'
).
toString
()
;
}
@Override
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论