mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1296 - where().exampleLike(bean) ... with 'empty bean' produces invalid SQL
This commit is contained in:
@@ -6,13 +6,13 @@ import io.ebean.bean.EntityBean;
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebean.util.SplitName;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.api.SpiExpressionValidation;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -201,9 +201,10 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
if (list.isEmpty()) {
|
||||
request.append("1=1");
|
||||
} else {
|
||||
request.append("(");
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
SpiExpression item = list.get(i);
|
||||
if (i > 0) {
|
||||
@@ -211,7 +212,6 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
|
||||
}
|
||||
item.addSql(request);
|
||||
}
|
||||
|
||||
request.append(") ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,25 @@ public class DefaultExampleExpressionTest extends BaseExpressionTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyExampleBean() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer customer = new Customer();
|
||||
|
||||
Query<Customer> query = server().find(Customer.class)
|
||||
.where()
|
||||
.eq("status", Customer.Status.NEW)
|
||||
.exampleLike(customer)
|
||||
.startsWith("name", "Rob")
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
|
||||
assertThat(sqlOf(query)).contains("and 1=1 and t0.name like");
|
||||
}
|
||||
|
||||
private <T> OrmQueryRequest<T> create(SpiQuery<T> query) {
|
||||
return new OrmQueryRequest<>(null, null, query, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user