Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e0880fbd
提交
e0880fbd
authored
4月 28, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use shared code for sort types parsing and formatting
上级
3321a9f9
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
61 行增加
和
84 行删除
+61
-84
Parser.java
h2/src/main/org/h2/command/Parser.java
+21
-31
Query.java
h2/src/main/org/h2/command/dml/Query.java
+7
-8
SelectOrderBy.java
h2/src/main/org/h2/command/dml/SelectOrderBy.java
+4
-20
Aggregate.java
h2/src/main/org/h2/expression/Aggregate.java
+3
-8
SortOrder.java
h2/src/main/org/h2/result/SortOrder.java
+17
-9
IndexColumn.java
h2/src/main/org/h2/table/IndexColumn.java
+1
-8
StatementBuilder.java
h2/src/main/org/h2/util/StatementBuilder.java
+8
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
e0880fbd
...
...
@@ -882,24 +882,30 @@ public class Parser {
do
{
IndexColumn
column
=
new
IndexColumn
();
column
.
columnName
=
readColumnIdentifier
();
column
.
sortType
=
parseSortType
();
columns
.
add
(
column
);
if
(
readIf
(
"ASC"
))
{
// ignore
}
else
if
(
readIf
(
"DESC"
))
{
column
.
sortType
=
SortOrder
.
DESCENDING
;
}
if
(
readIf
(
"NULLS"
))
{
if
(
readIf
(
"FIRST"
))
{
column
.
sortType
|=
SortOrder
.
NULLS_FIRST
;
}
else
{
read
(
"LAST"
);
column
.
sortType
|=
SortOrder
.
NULLS_LAST
;
}
}
}
while
(
readIfMore
(
true
));
return
columns
.
toArray
(
new
IndexColumn
[
0
]);
}
private
int
parseSortType
()
{
int
sortType
=
0
;
if
(
readIf
(
"ASC"
))
{
// ignore
}
else
if
(
readIf
(
"DESC"
))
{
sortType
=
SortOrder
.
DESCENDING
;
}
if
(
readIf
(
"NULLS"
))
{
if
(
readIf
(
"FIRST"
))
{
sortType
|=
SortOrder
.
NULLS_FIRST
;
}
else
{
read
(
"LAST"
);
sortType
|=
SortOrder
.
NULLS_LAST
;
}
}
return
sortType
;
}
private
String
[]
parseColumnList
()
{
ArrayList
<
String
>
columns
=
Utils
.
newSmallArrayList
();
do
{
...
...
@@ -2029,19 +2035,7 @@ public class Parser {
}
else
{
order
.
expression
=
expr
;
}
if
(
readIf
(
"DESC"
))
{
order
.
descending
=
true
;
}
else
{
readIf
(
"ASC"
);
}
if
(
readIf
(
"NULLS"
))
{
if
(
readIf
(
"FIRST"
))
{
order
.
nullsFirst
=
true
;
}
else
{
read
(
"LAST"
);
order
.
nullsLast
=
true
;
}
}
order
.
sortType
=
parseSortType
();
orderList
.
add
(
order
);
}
while
(
readIf
(
","
));
command
.
setOrder
(
orderList
);
...
...
@@ -2701,11 +2695,7 @@ public class Parser {
do
{
SelectOrderBy
order
=
new
SelectOrderBy
();
order
.
expression
=
readExpression
();
if
(
readIf
(
"DESC"
))
{
order
.
descending
=
true
;
}
else
{
readIf
(
"ASC"
);
}
order
.
sortType
=
parseSortType
();
orderList
.
add
(
order
);
}
while
(
readIf
(
","
));
return
orderList
;
...
...
h2/src/main/org/h2/command/dml/Query.java
浏览文件 @
e0880fbd
...
...
@@ -524,15 +524,14 @@ public abstract class Query extends Prepared {
}
}
index
[
i
]
=
idx
;
boolean
desc
=
o
.
descending
;
int
type
=
o
.
sortType
;
if
(
reverse
)
{
desc
=
!
desc
;
}
int
type
=
desc
?
SortOrder
.
DESCENDING
:
SortOrder
.
ASCENDING
;
if
(
o
.
nullsFirst
)
{
type
+=
SortOrder
.
NULLS_FIRST
;
}
else
if
(
o
.
nullsLast
)
{
type
+=
SortOrder
.
NULLS_LAST
;
// TODO NULLS FIRST / LAST should be inverted too?
if
((
type
&
SortOrder
.
DESCENDING
)
!=
0
)
{
type
&=
~
SortOrder
.
DESCENDING
;
}
else
{
type
|=
SortOrder
.
DESCENDING
;
}
}
sortType
[
i
]
=
type
;
}
...
...
h2/src/main/org/h2/command/dml/SelectOrderBy.java
浏览文件 @
e0880fbd
...
...
@@ -6,6 +6,7 @@
package
org
.
h2
.
command
.
dml
;
import
org.h2.expression.Expression
;
import
org.h2.result.SortOrder
;
/**
* Describes one element of the ORDER BY clause of a query.
...
...
@@ -25,19 +26,9 @@ public class SelectOrderBy {
public
Expression
columnIndexExpr
;
/**
*
If the column should be sorted descending
.
*
Sort type for this column
.
*/
public
boolean
descending
;
/**
* If NULL should be appear first.
*/
public
boolean
nullsFirst
;
/**
* If NULL should be appear at the end.
*/
public
boolean
nullsLast
;
public
int
sortType
;
public
String
getSQL
()
{
StringBuilder
buff
=
new
StringBuilder
();
...
...
@@ -46,14 +37,7 @@ public class SelectOrderBy {
}
else
{
buff
.
append
(
columnIndexExpr
.
getSQL
());
}
if
(
descending
)
{
buff
.
append
(
" DESC"
);
}
if
(
nullsFirst
)
{
buff
.
append
(
" NULLS FIRST"
);
}
else
if
(
nullsLast
)
{
buff
.
append
(
" NULLS LAST"
);
}
SortOrder
.
typeToString
(
buff
,
sortType
);
return
buff
.
toString
();
}
...
...
h2/src/main/org/h2/expression/Aggregate.java
浏览文件 @
e0880fbd
...
...
@@ -252,8 +252,7 @@ public class Aggregate extends Expression {
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
SelectOrderBy
o
=
orderByList
.
get
(
i
);
index
[
i
]
=
i
+
1
;
int
order
=
o
.
descending
?
SortOrder
.
DESCENDING
:
SortOrder
.
ASCENDING
;
sortType
[
i
]
=
order
;
sortType
[
i
]
=
o
.
sortType
;
}
return
new
SortOrder
(
session
.
getDatabase
(),
index
,
sortType
,
null
);
}
...
...
@@ -590,9 +589,7 @@ public class Aggregate extends Expression {
for
(
SelectOrderBy
o
:
orderByList
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
o
.
expression
.
getSQL
());
if
(
o
.
descending
)
{
buff
.
append
(
" DESC"
);
}
SortOrder
.
typeToString
(
buff
.
builder
(),
o
.
sortType
);
}
}
if
(
groupConcatSeparator
!=
null
)
{
...
...
@@ -616,9 +613,7 @@ public class Aggregate extends Expression {
for
(
SelectOrderBy
o
:
orderByList
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
o
.
expression
.
getSQL
());
if
(
o
.
descending
)
{
buff
.
append
(
" DESC"
);
}
SortOrder
.
typeToString
(
buff
.
builder
(),
o
.
sortType
);
}
}
buff
.
append
(
')'
);
...
...
h2/src/main/org/h2/result/SortOrder.java
浏览文件 @
e0880fbd
...
...
@@ -127,19 +127,27 @@ public class SortOrder implements Comparator<Value[]> {
}
else
{
buff
.
append
(
'='
).
append
(
StringUtils
.
unEnclose
(
list
[
idx
].
getSQL
()));
}
int
type
=
sortTypes
[
i
++];
if
((
type
&
DESCENDING
)
!=
0
)
{
buff
.
append
(
" DESC"
);
}
if
((
type
&
NULLS_FIRST
)
!=
0
)
{
buff
.
append
(
" NULLS FIRST"
);
}
else
if
((
type
&
NULLS_LAST
)
!=
0
)
{
buff
.
append
(
" NULLS LAST"
);
}
typeToString
(
buff
.
builder
(),
sortTypes
[
i
++]);
}
return
buff
.
toString
();
}
/**
* Appends type information (DESC, NULLS FIRST, NULLS LAST) to the specified statement builder.
* @param builder statement builder
* @param type sort type
*/
public
static
void
typeToString
(
StringBuilder
builder
,
int
type
)
{
if
((
type
&
DESCENDING
)
!=
0
)
{
builder
.
append
(
" DESC"
);
}
if
((
type
&
NULLS_FIRST
)
!=
0
)
{
builder
.
append
(
" NULLS FIRST"
);
}
else
if
((
type
&
NULLS_LAST
)
!=
0
)
{
builder
.
append
(
" NULLS LAST"
);
}
}
/**
* Compare two expressions where one of them is NULL.
*
...
...
h2/src/main/org/h2/table/IndexColumn.java
浏览文件 @
e0880fbd
...
...
@@ -36,14 +36,7 @@ public class IndexColumn {
*/
public
String
getSQL
()
{
StringBuilder
buff
=
new
StringBuilder
(
column
.
getSQL
());
if
((
sortType
&
SortOrder
.
DESCENDING
)
!=
0
)
{
buff
.
append
(
" DESC"
);
}
if
((
sortType
&
SortOrder
.
NULLS_FIRST
)
!=
0
)
{
buff
.
append
(
" NULLS FIRST"
);
}
else
if
((
sortType
&
SortOrder
.
NULLS_LAST
)
!=
0
)
{
buff
.
append
(
" NULLS LAST"
);
}
SortOrder
.
typeToString
(
buff
,
sortType
);
return
buff
.
toString
();
}
...
...
h2/src/main/org/h2/util/StatementBuilder.java
浏览文件 @
e0880fbd
...
...
@@ -127,4 +127,12 @@ public class StatementBuilder {
return
builder
.
length
();
}
/**
* Return underlying builder.
* @return underlying builder
*/
public
StringBuilder
builder
()
{
return
builder
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论