#1694 - findList() with firstRows/maxRows adds "order by id" (even with orderById(false))

This commit is contained in:
rob bygrave
2019-05-03 14:33:42 +12:00
parent e4569f9362
commit 4aa8a0dc63
11 changed files with 98 additions and 22 deletions
@@ -135,12 +135,12 @@ public class EbeanServer_eqlTest extends BaseTestCase {
query.findList();
if (isSqlServer()) {
assertThat(query.getGeneratedSql()).endsWith("order by t0.id offset 3 rows fetch next 10 rows only");
assertThat(query.getGeneratedSql()).endsWith("from o_customer t0 offset 3 rows fetch next 10 rows only");
} else if (isOracle()) {
assertThat(query.getGeneratedSql()).contains("where rownum <= 13");
assertThat(query.getGeneratedSql()).contains("where rn_ > 3");
} else {
assertThat(query.getGeneratedSql()).endsWith("order by t0.id limit 10 offset 3");
assertThat(query.getGeneratedSql()).endsWith("from o_customer t0 limit 10 offset 3");
}
}
@@ -155,12 +155,10 @@ public class EbeanServer_eqlTest extends BaseTestCase {
if (isSqlServer()) {
assertThat(query.getGeneratedSql()).startsWith("select top 10 ");
assertThat(query.getGeneratedSql()).endsWith("order by t0.id");
} else if (isOracle()) {
assertThat(query.getGeneratedSql()).contains("t0 order by t0.id");
assertThat(query.getGeneratedSql()).contains(" a where rownum <= 10");
} else {
assertThat(query.getGeneratedSql()).endsWith("order by t0.id limit 10");
assertThat(query.getGeneratedSql()).endsWith("limit 10");
}
}
@@ -370,7 +370,7 @@ public class EqlParserTest extends BaseTestCase {
Query<Customer> query = parse("select name fetch billingAddress (line1, city) fetch shippingAddress (line1) limit 10");
query.findList();
assertThat(sqlOf(query, 12)).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city, t2.id, t2.line_1 from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id left join o_address t2 on t2.id = t0.shipping_address_id order by t0.id");
assertThat(sqlOf(query, 12)).contains("select t0.id, t0.name, t1.id, t1.line_1, t1.city, t2.id, t2.line_1 from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id left join o_address t2 on t2.id = t0.shipping_address_id");
}
@Test
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.rawsql;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Query;
import io.ebean.RawSql;
import io.ebean.RawSqlBuilder;
import io.ebean.annotation.ForPlatform;
@@ -29,7 +30,6 @@ public class TestRawSqlParsing extends BaseTestCase {
RawSql rawSql = RawSqlBuilder
.parse(sql)
.columnMapping("order_id", "order.id")
//.columnMapping("sum(order_qty*unit_price)","totalAmount")
.create();
Sql rs = ((SpiRawSql)rawSql).getSql();
@@ -72,4 +72,32 @@ public class TestRawSqlParsing extends BaseTestCase {
assertThat(customers).isNotEmpty();
}
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testUnion() {
ResetBasicData.reset();
String sql =
"select id, name from (" +
" select id, name from o_customer where name <= 'f' " +
" union all " +
" select id, name from o_customer where name > 'f' " +
") all_split";
RawSql rawSql = RawSqlBuilder.parse(sql).create();
Query<Customer> query = Ebean.createQuery(Customer.class)
.setRawSql(rawSql)
.setFirstRow(1)
.setMaxRows(5);
//.orderById(false);
query.findList();
assertThat(sqlOf(query)).contains(") all_split limit 5 offset 1");
}
}