mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-12-01 15:37:14 +00:00
#1512 - Invalid SQL with Postgres + order by nulls first/last + where() expression on ManyToMany
This commit is contained in:
1 parent
e06967ff4a
commit
c1a479e1f4
2 files changed
+40
-18
No files matched your search
@@ -7,57 +7,58 @@ import static org.junit.Assert.*;
|
|||||||
public class SqlTreeBuilderTest {
|
public class SqlTreeBuilderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeOnDistinct_equal() throws Exception {
|
public void mergeOnDistinct_equal() {
|
||||||
|
|
||||||
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.id"), "t0.id");
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.id"), "t0.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeOnDistinct_add() throws Exception {
|
public void mergeOnDistinct_add() {
|
||||||
|
|
||||||
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre"), "t0.cre, t0.id");
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre"), "t0.cre, t0.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeOnDistinct_contained() throws Exception {
|
public void mergeOnDistinct_contained() {
|
||||||
|
|
||||||
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre, t0.id"), "t0.cre, t0.id");
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre, t0.id"), "t0.cre, t0.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeOnDistinct_overlap() throws Exception {
|
public void mergeOnDistinct_overlap() {
|
||||||
|
|
||||||
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id, t1.id", "t0.cre, t0.id"), "t0.cre, t0.id, t1.id");
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id, t1.id", "t0.cre, t0.id"), "t0.cre, t0.id, t1.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeOnDistinct_overlapBoth() throws Exception {
|
public void mergeOnDistinct_overlapBoth() {
|
||||||
|
|
||||||
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id, t1.id", "t0.cre, t1.id, t0.id"), "t0.cre, t1.id, t0.id");
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id, t1.id", "t0.cre, t1.id, t0.id"), "t0.cre, t1.id, t0.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeOnDistinct_inlineAscDesc() throws Exception {
|
public void mergeOnDistinct_inlineAscDesc() {
|
||||||
|
|
||||||
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre asc, t1.bb desc, t3.b"), "t0.cre, t1.bb, t3.b, t0.id");
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre asc, t1.bb desc, t3.b"), "t0.cre, t1.bb, t3.b, t0.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeOnDistinct_inlineAscDesc2() throws Exception {
|
public void mergeOnDistinct_inlineAscDesc2() {
|
||||||
|
|
||||||
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre desc, t1.bb asc, t3.b"), "t0.cre, t1.bb, t3.b, t0.id");
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre desc, t1.bb asc, t3.b"), "t0.cre, t1.bb, t3.b, t0.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeOnDistinct_trailingAsc() throws Exception {
|
public void mergeOnDistinct_trailingAsc() {
|
||||||
|
|
||||||
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre asc"), "t0.cre, t0.id");
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre asc"), "t0.cre, t0.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeOnDistinct_trailingDesc() throws Exception {
|
public void mergeOnDistinct_trailingDesc() {
|
||||||
|
|
||||||
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre desc"), "t0.cre, t0.id");
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre desc"), "t0.cre, t0.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mergeOnDistinct_trailingDescNullsFirst() {
|
||||||
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre desc nulls first"), "t0.cre, t0.id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mergeOnDistinct_trailingDescNullsLast() {
|
||||||
|
assertEquals(SqlTreeBuilder.mergeOnDistinct("t0.id", "t0.cre desc nulls last"), "t0.cre, t0.id");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,27 @@ public class TestOrderByWithDistinct extends BaseTestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDistinctOn() {
|
||||||
|
|
||||||
|
MRole role = Ebean.getReference(MRole.class, 1);
|
||||||
|
|
||||||
|
Query<MUser> query = Ebean.find(MUser.class)
|
||||||
|
.where()
|
||||||
|
.eq("roles", role)
|
||||||
|
.orderBy("userName asc nulls first");
|
||||||
|
|
||||||
|
query.findList();
|
||||||
|
|
||||||
|
String sql = sqlOf(query);
|
||||||
|
if (isPostgres()) {
|
||||||
|
assertThat(sql).contains("select distinct on (t0.user_name, t0.userid) t0.userid,");
|
||||||
|
} else if (isH2()) {
|
||||||
|
assertThat(sql).contains("select distinct t0.userid, t0.user_name, t0.user_type_id,");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderByWithDistinct() {
|
public void testOrderByWithDistinct() {
|
||||||
|
|||||||
Reference in new issue
Block a user