Fix platform specific asserts with TestQuerySingleAttribute using limit/offset

This commit is contained in:
Rob Bygrave
2022-08-01 09:37:34 +12:00
parent 5f689dee1b
commit d12dc9bfed
2 changed files with 15 additions and 6 deletions
@@ -171,6 +171,14 @@ public abstract class BaseTestCase {
return spiEbeanServer().databasePlatform().isCaseSensitiveCollation();
}
public boolean isLimitOffset() {
return isH2() || isPostgresCompatible() || isMySql() || isMariaDB();
}
public boolean isAnsiSqlLimit() {
return isOracle() || isDb2();
}
/**
* MS SQL Server does not allow setting explicit values on identity columns
* so tests that do this need to be skipped for SQL Server.
@@ -798,12 +798,13 @@ class TestQuerySingleAttribute extends BaseTestCase {
.setMaxRows(2);
List<Order.Status> statusList = query.findSingleAttributeList();
assertSql(query)
.contains("select t1.status from o_customer t0 "
+ "left join o_order t1 on t1.kcustomer_id = t0.id and t1.order_date is not null limit 2")
.doesNotContain("order by");
// Results in java.lang.AssertionError: selectSql was null
// at io.ebeaninternal.server.query.SqlTree.getSelectSql(SqlTree.java:99)
if (isSqlServer()) {
assertThat(sqlOf(query)).isEqualTo("select top 2 t1.status from o_customer t0 left join o_order t1 on t1.kcustomer_id = t0.id and t1.order_date is not null");
} else if (isLimitOffset()) {
assertThat(sqlOf(query)).isEqualTo("select t1.status from o_customer t0 left join o_order t1 on t1.kcustomer_id = t0.id and t1.order_date is not null limit 2");
} else if (isAnsiSqlLimit()) {
assertThat(sqlOf(query)).isEqualTo("select t1.status from o_customer t0 left join o_order t1 on t1.kcustomer_id = t0.id and t1.order_date is not null fetch next 100 rows only");
}
assertThat(statusList).hasSize(2);
}