Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
0622d70e
提交
0622d70e
authored
8月 25, 2015
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #165 from Myp/master
Fix compatibility postgresql function string_agg
上级
11ef3490
32fa2782
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
88 行增加
和
2 行删除
+88
-2
Parser.java
h2/src/main/org/h2/command/Parser.java
+8
-2
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-0
TestStringAggCompatibility.java
...rc/test/org/h2/test/synth/TestStringAggCompatibility.java
+78
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
0622d70e
...
@@ -2293,8 +2293,9 @@ public class Parser {
...
@@ -2293,8 +2293,9 @@ public class Parser {
}
}
}
else
if
(
aggregateType
==
Aggregate
.
GROUP_CONCAT
)
{
}
else
if
(
aggregateType
==
Aggregate
.
GROUP_CONCAT
)
{
Aggregate
agg
=
null
;
Aggregate
agg
=
null
;
boolean
distinct
=
readIf
(
"DISTINCT"
);
if
(
equalsToken
(
"GROUP_CONCAT"
,
aggregateName
))
{
if
(
equalsToken
(
"GROUP_CONCAT"
,
aggregateName
))
{
boolean
distinct
=
readIf
(
"DISTINCT"
);
agg
=
new
Aggregate
(
Aggregate
.
GROUP_CONCAT
,
agg
=
new
Aggregate
(
Aggregate
.
GROUP_CONCAT
,
readExpression
(),
currentSelect
,
distinct
);
readExpression
(),
currentSelect
,
distinct
);
if
(
readIf
(
"ORDER"
))
{
if
(
readIf
(
"ORDER"
))
{
...
@@ -2308,9 +2309,14 @@ public class Parser {
...
@@ -2308,9 +2309,14 @@ public class Parser {
}
else
if
(
equalsToken
(
"STRING_AGG"
,
aggregateName
))
{
}
else
if
(
equalsToken
(
"STRING_AGG"
,
aggregateName
))
{
// PostgreSQL compatibility: string_agg(expression, delimiter)
// PostgreSQL compatibility: string_agg(expression, delimiter)
agg
=
new
Aggregate
(
Aggregate
.
GROUP_CONCAT
,
agg
=
new
Aggregate
(
Aggregate
.
GROUP_CONCAT
,
readExpression
(),
currentSelect
,
false
);
readExpression
(),
currentSelect
,
distinct
);
read
(
","
);
read
(
","
);
agg
.
setGroupConcatSeparator
(
readExpression
());
agg
.
setGroupConcatSeparator
(
readExpression
());
if
(
readIf
(
"ORDER"
))
{
read
(
"BY"
);
agg
.
setGroupConcatOrder
(
parseSimpleOrderList
());
}
}
}
r
=
agg
;
r
=
agg
;
}
else
{
}
else
{
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
0622d70e
...
@@ -148,6 +148,7 @@ import org.h2.test.synth.TestNestedJoins;
...
@@ -148,6 +148,7 @@ import org.h2.test.synth.TestNestedJoins;
import
org.h2.test.synth.TestOuterJoins
;
import
org.h2.test.synth.TestOuterJoins
;
import
org.h2.test.synth.TestRandomCompare
;
import
org.h2.test.synth.TestRandomCompare
;
import
org.h2.test.synth.TestRandomSQL
;
import
org.h2.test.synth.TestRandomSQL
;
import
org.h2.test.synth.TestStringAggCompatibility
;
import
org.h2.test.synth.TestTimer
;
import
org.h2.test.synth.TestTimer
;
import
org.h2.test.synth.sql.TestSynth
;
import
org.h2.test.synth.sql.TestSynth
;
import
org.h2.test.synth.thread.TestMulti
;
import
org.h2.test.synth.thread.TestMulti
;
...
@@ -759,6 +760,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
...
@@ -759,6 +760,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest
(
new
TestMultiThreaded
());
addTest
(
new
TestMultiThreaded
());
addTest
(
new
TestOuterJoins
());
addTest
(
new
TestOuterJoins
());
addTest
(
new
TestNestedJoins
());
addTest
(
new
TestNestedJoins
());
addTest
(
new
TestStringAggCompatibility
());
runAddedTests
();
runAddedTests
();
...
...
h2/src/test/org/h2/test/synth/TestStringAggCompatibility.java
0 → 100644
浏览文件 @
0622d70e
package
org
.
h2
.
test
.
synth
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
org.h2.test.TestBase
;
/**
* Test for check compatibility with posgresql function string_agg()
*
* */
public
class
TestStringAggCompatibility
extends
TestBase
{
public
static
final
String
STRING_AGG_DB
=
"stringAgg"
;
private
Connection
conn
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
@Override
public
void
test
()
throws
Exception
{
deleteDb
(
STRING_AGG_DB
);
conn
=
getConnection
(
STRING_AGG_DB
);
prepareDb
();
testWhenOrderByMissing
();
testWithOrderBy
();
}
private
void
testWithOrderBy
()
throws
SQLException
{
ResultSet
result
=
query
(
"select string_agg(b, ', ' order by b desc) from stringAgg group by a; "
);
assertTrue
(
result
.
next
());
assertEquals
(
"3, 2, 1"
,
result
.
getString
(
1
));
}
private
void
testWhenOrderByMissing
()
throws
SQLException
{
ResultSet
result
=
query
(
"select string_agg(b, ', ') from stringAgg group by a; "
);
assertTrue
(
result
.
next
());
assertEquals
(
"1, 2, 3"
,
result
.
getString
(
1
));
}
private
ResultSet
query
(
String
q
)
throws
SQLException
{
PreparedStatement
st
=
conn
.
prepareStatement
(
q
);
st
.
execute
();
return
st
.
getResultSet
();
}
private
void
prepareDb
()
throws
SQLException
{
exec
(
"create table stringAgg(\n"
+
" a int not null,\n"
+
" b varchar(50) not null\n"
+
");"
);
exec
(
"insert into stringAgg values(1, '1')"
);
exec
(
"insert into stringAgg values(1, '2')"
);
exec
(
"insert into stringAgg values(1, '3')"
);
}
private
void
exec
(
String
sql
)
throws
SQLException
{
conn
.
prepareStatement
(
sql
).
execute
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论