mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1694 - findList() with firstRows/maxRows adds "order by id" (even with orderById(false))
This commit is contained in:
@@ -50,8 +50,8 @@ public class TestHistoryOneToMany extends BaseTestCase {
|
||||
|
||||
if (isH2()) {
|
||||
assertThat(sql).hasSize(2);
|
||||
assertThat(sql.get(0)).contains("from hi_tone_with_history t0 where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and lower(t0.name) like ? escape'' order by t0.id limit 10");
|
||||
assertThat(sql.get(1)).contains("from hi_ttwo_with_history t0 left join hi_tthree_with_history t1 on t1.hi_ttwo_id = t0.id and (t1.sys_period_start <= ? and (t1.sys_period_end is null or t1.sys_period_end > ?)) where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and (t0.hi_tone_id) in (? ) order by t0.id");
|
||||
assertThat(sql.get(0)).contains("from hi_tone_with_history t0 where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and lower(t0.name) like ? escape'' limit 10");
|
||||
assertThat(sql.get(1)).contains("from hi_ttwo_with_history t0 left join hi_tthree_with_history t1 on t1.hi_ttwo_id = t0.id and (t1.sys_period_start <= ? and (t1.sys_period_end is null or t1.sys_period_end > ?)) where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and (t0.hi_tone_id) in (? )");
|
||||
}
|
||||
|
||||
assertThat(list).hasSize(1);
|
||||
|
||||
@@ -50,7 +50,9 @@ public class TestAddOrderByWithFirstRowsMaxRows extends BaseTestCase {
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.id");
|
||||
if (isH2()) {
|
||||
assertThat(loggedSql.get(0)).contains("from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id limit 10");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +111,9 @@ public class TestAddOrderByWithFirstRowsMaxRows extends BaseTestCase {
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.id");
|
||||
if (isH2()) {
|
||||
assertThat(loggedSql.get(0)).contains("join o_customer t1 on t1.id = t0.kcustomer_id limit 10");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,7 +132,9 @@ public class TestAddOrderByWithFirstRowsMaxRows extends BaseTestCase {
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(loggedSql).hasSize(1);
|
||||
assertThat(loggedSql.get(0)).contains("order by t0.id");
|
||||
if (isH2()) {
|
||||
assertThat(loggedSql.get(0)).contains(" limit 10 offset 10");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.tests.query;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Query;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import static org.assertj.core.api.StrictAssertions.assertThat;
|
||||
|
||||
public class TestQueryOrderById extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void orderById_default_expectNotOrderById() {
|
||||
|
||||
Query<Customer> query = DB.find(Customer.class)
|
||||
.select("id,name")
|
||||
.setFirstRow(1)
|
||||
.setMaxRows(5);
|
||||
|
||||
query.findList();
|
||||
assertThat(sqlOf(query)).isEqualTo("select t0.id, t0.name from o_customer t0 limit 5 offset 1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void orderById_whenTrue_expectOrderById() {
|
||||
|
||||
Query<Customer> query = DB.find(Customer.class)
|
||||
.select("id,name")
|
||||
.setFirstRow(1)
|
||||
.setMaxRows(5)
|
||||
.orderById(true);
|
||||
|
||||
query.findList();
|
||||
assertThat(sqlOf(query)).isEqualTo("select t0.id, t0.name from o_customer t0 order by t0.id limit 5 offset 1");
|
||||
}
|
||||
}
|
||||
@@ -73,8 +73,9 @@ public class TestOrderByWithDistinct extends BaseTestCase {
|
||||
|
||||
query.setMaxRows(1000);
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("order by t0.userid");
|
||||
|
||||
if (isH2()) {
|
||||
assertThat(query.getGeneratedSql()).contains("from muser t0 limit 1000");
|
||||
}
|
||||
query = Ebean.find(MUser.class)
|
||||
.where()
|
||||
.eq("roles.roleName", "A")
|
||||
@@ -85,7 +86,9 @@ public class TestOrderByWithDistinct extends BaseTestCase {
|
||||
|
||||
query.setMaxRows(1000);
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("order by t0.userid");
|
||||
if (isH2()) {
|
||||
assertThat(query.getGeneratedSql()).contains("where u1.role_name = ? limit 1000");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -258,17 +258,20 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
// hmm - same problem when not using distinct
|
||||
@Test
|
||||
public void findSingleOnIdProperty() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.select("id")
|
||||
.setMaxRows(100);
|
||||
|
||||
List<String> ids = query.findSingleAttributeList();
|
||||
if (isSqlServer()) {
|
||||
assertThat(sqlOf(query)).contains("select top 100 t0.id from o_customer t0 order by t0.id");
|
||||
assertThat(sqlOf(query)).contains("select top 100 t0.id from o_customer t0");
|
||||
} else if (isOracle()) {
|
||||
assertThat(sqlOf(query)).contains("where rownum <= 100");
|
||||
} else {
|
||||
assertThat(sqlOf(query)).contains("select t0.id from o_customer t0 order by t0.id limit 100");
|
||||
assertThat(sqlOf(query)).contains("select t0.id from o_customer t0 limit 100");
|
||||
}
|
||||
assertThat(ids).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -50,9 +50,9 @@ public class TestSoftDeletePagingList extends TransactionalTestCase {
|
||||
|
||||
assertThat(sql.get(1)).contains("where t0.s3_url like ");
|
||||
if (isPlatformBooleanNative()) {
|
||||
assertThat(sql.get(1)).contains("and t0.deleted = false order by t0.id");
|
||||
assertThat(sql.get(1)).contains("and t0.deleted = false");
|
||||
} else {
|
||||
assertThat(sql.get(1)).contains("and t0.deleted = 0 order by t0.id");
|
||||
assertThat(sql.get(1)).contains("and t0.deleted = 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user