FIX: subquery could not not have a where clause

This commit is contained in:
Jonas Pöhler
2021-07-29 17:09:24 +02:00
parent 4aef0ad459
commit 4cebb367de
3 changed files with 26 additions and 3 deletions
@@ -22,6 +22,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -411,7 +412,7 @@ public class CQueryPredicates {
* Return the bind values for the where expression.
*/
public List<Object> getWhereExprBindValues() {
return where.getBindValues();
return where == null ? Collections.emptyList() : where.getBindValues();
}
/**
@@ -4,7 +4,6 @@ import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Query;
import io.ebeantest.LoggedSql;
import org.junit.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.Order;
@@ -111,4 +110,17 @@ public class TestQueryExists extends BaseTestCase {
assertThat(sql).contains("not exists (");
}
@Test
public void testExistsNoWhere() {
ResetBasicData.reset();
Query<Order> subQuery = Ebean.find(Order.class).alias("sq").select("id");
Query<Customer> query = Ebean.find(Customer.class).alias("qt").where().notExists(subQuery).query();
query.findList();
String sql = query.getGeneratedSql();
assertThat(sql).contains("not exists (select sq.id from o_order sq)");
}
}
@@ -44,7 +44,17 @@ public class TestSubQuery extends BaseTestCase {
Query<Order> sq = DB.createQuery(Order.class).select("id").where()
.isIn("details.product.id", productIds).query();
DB.find(Order.class).where().isIn("id", sq).findList();
assertThat(DB.find(Order.class).where().isIn("id", sq).findList()).hasSize(2);
}
@Test
public void test_IsInNoWhere() {
ResetBasicData.reset();
Query<Order> sq = DB.createQuery(Order.class).select("id");
int expectedSize = DB.find(Order.class).findCount(); // expect everything
assertThat(DB.find(Order.class).where().isIn("id", sq).findList()).hasSize(expectedSize);
}
public void testCompositeKey() {