#1996 - Fix for MySQLSyntaxErrorException when update in bulk using idIn().

This commit is contained in:
rob bygrave
2020-04-30 21:33:02 +12:00
parent ed0e9e7006
commit dbe473d5a1
3 changed files with 10 additions and 15 deletions
@@ -36,7 +36,6 @@ public final class IdBinderSimple implements IdBinder {
@SuppressWarnings("rawtypes")
private final ScalarType scalarType;
public IdBinderSimple(BeanProperty idProperty, MultiValueBind multiValueBind) {
this.idProperty = idProperty;
this.scalarType = idProperty.getScalarType();
@@ -71,7 +70,6 @@ public final class IdBinderSimple implements IdBinder {
@Override
public void buildRawSqlSelectChain(String prefix, List<String> selectChain) {
idProperty.buildRawSqlSelectChain(prefix, selectChain);
}
@@ -218,7 +216,6 @@ public final class IdBinderSimple implements IdBinder {
@Override
public String getAssocOneIdExpr(String prefix, String operator) {
StringBuilder sb = new StringBuilder();
if (prefix != null) {
sb.append(prefix);
@@ -231,7 +228,6 @@ public final class IdBinderSimple implements IdBinder {
@Override
public String getAssocIdInExpr(String prefix) {
StringBuilder sb = new StringBuilder();
if (prefix != null) {
sb.append(prefix);
@@ -243,7 +239,6 @@ public final class IdBinderSimple implements IdBinder {
@Override
public Object convertId(Object idValue) {
if (!idValue.getClass().equals(expectedType)) {
return scalarType.toBeanType(idValue);
}
@@ -252,12 +247,10 @@ public final class IdBinderSimple implements IdBinder {
@Override
public Object convertSetId(Object idValue, EntityBean bean) {
if (!idValue.getClass().equals(expectedType)) {
idValue = scalarType.toBeanType(idValue);
}
if (bean != null) {
// support PropertyChangeSupport
idProperty.setValueIntercept(bean, idValue);
}
return idValue;
@@ -104,16 +104,18 @@ public class IdInExpression extends NonPrepareExpression {
@Override
public void addSql(SpiExpressionRequest request) {
DefaultExpressionRequest r = (DefaultExpressionRequest) request;
BeanDescriptor<?> descriptor = r.getBeanDescriptor();
BeanDescriptor<?> descriptor = request.getBeanDescriptor();
IdBinder idBinder = descriptor.getIdBinder();
if (idCollection.isEmpty()) {
request.append(SQL_FALSE); // append false for this stage
} else {
request.append(descriptor.getIdBinderInLHSSql());
String inClause = idBinder.getIdInValueExpr(false, idCollection.size());
request.append(inClause);
if (idBinder.isComplexId()) {
request.append(descriptor.getIdBinderInLHSSql());
request.append(idBinder.getIdInValueExpr(false, idCollection.size()));
} else {
request.append(idBinder.getBeanProperty().getName());
request.appendInExpression(false, idCollection);
}
}
}
+2 -2
View File
@@ -106,7 +106,7 @@ public class UpdateQueryTest extends BaseTestCase {
int rows = server().find(Customer.class)
.where()
.in("id", 1000, 1001, 1002)
.idIn(1000, 1001, 1002)
.asUpdate()
.setRaw("status = ?", "A")
.setLabel("asUpdateByIds")
@@ -116,7 +116,7 @@ public class UpdateQueryTest extends BaseTestCase {
assertThat(sql).hasSize(1);
assertThat(rows).isEqualTo(0);
assertSql(sql.get(0)).contains("update o_customer set status = ? where id in (?,?,?)");
assertSql(sql.get(0)).contains("update o_customer set status = ? where id in (?,?,?,?,?)"); // bind padding to 5
}
@Test