#1831 - Update query with maxRows does not include the limit in the generated SQL

This commit is contained in:
rob bygrave
2019-10-11 17:01:30 +13:00
parent 4e74c68603
commit b665d8375c
10 changed files with 280 additions and 191 deletions
+47 -4
View File
@@ -1,5 +1,6 @@
package io.ebean;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.IgnorePlatform;
import io.ebean.annotation.Platform;
import io.ebean.meta.MetaOrmQueryMetric;
@@ -16,7 +17,6 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class UpdateQueryTest extends BaseTestCase {
@Test
@@ -143,12 +143,10 @@ public class UpdateQueryTest extends BaseTestCase {
assertThat(query.getGeneratedSql()).contains("update o_customer cust set status=?, updtime=? where id > ?");
}
@IgnorePlatform(Platform.MYSQL)
@Test
public void withJoin() {
if (isMySql()) {
return;
}
EbeanServer server = server();
Country nz = server.getReference(Country.class, "NZ");
@@ -169,6 +167,51 @@ public class UpdateQueryTest extends BaseTestCase {
assertThat(sqlOf(query)).contains("update o_customer set status=?, updtime=? where id in (select t0.id from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where t0.status = ? and t1.country_code = ? and t0.id > ?)");
}
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void withJoinAndLimit() {
EbeanServer server = server();
Country nz = server.getReference(Country.class, "NZ");
LoggedSqlCollector.start();
server.update(Customer.class)
.set("status", Customer.Status.ACTIVE)
.where()
.eq("billingAddress.country", nz)
.gt("id", 1000)
.setMaxRows(100)
.update();
final List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("update o_customer set status=? where id in (select t0.id from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where t1.country_code = ? and t0.id > ? limit 100)");
}
@ForPlatform({Platform.H2, Platform.POSTGRES, Platform.MYSQL})
@Test
public void simpleWithLimit() {
EbeanServer server = server();
LoggedSqlCollector.start();
server.update(Customer.class)
.set("status", Customer.Status.ACTIVE)
.where()
.gt("id", 1000)
.setMaxRows(100)
.update();
final List<String> sql = LoggedSqlCollector.stop();
if (isMySql() || isH2()) {
assertThat(sql.get(0)).contains("update o_customer set status=? where id > ? limit 100");
} else {
assertThat(sql.get(0)).contains("update o_customer set status=? where id in (select t0.id from o_customer t0 where t0.id > ? limit 100)");
}
}
@Test
public void whereIsEmpty() {
@@ -3,6 +3,8 @@ package org.tests.basic;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.Ebean;
import io.ebean.annotation.IgnorePlatform;
import io.ebean.annotation.Platform;
import org.junit.Test;
import org.tests.model.basic.EDefaultProp;
@@ -11,6 +13,7 @@ import static org.junit.Assert.assertNotNull;
public class TestCreateEntityBean extends BaseTestCase {
@IgnorePlatform(Platform.SQLSERVER)
@Test
public void testDefaultRelation() {
@@ -193,6 +193,6 @@ public class TestQueryFilterMany extends BaseTestCase {
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains(" from o_customer t0");
assertThat(sql.get(1)).contains("from contact t0 where ");
assertThat(sql.get(1)).contains("and (t0.first_name is not null and lower(t0.email) like ? escape'|' )");
assertThat(sql.get(1)).contains("and (t0.first_name is not null and lower(t0.email) like ?");
}
}