mirror of
https://gitee.com/dromara/hmily.git
synced 2024-12-01 18:58:03 +08:00
fix WHERE sub clause parse error (#316)
This commit is contained in:
parent
927882c9b2
commit
29a815acef
@ -22,7 +22,6 @@ import org.dromara.hmily.repository.spi.entity.tuple.HmilySQLManipulation;
|
||||
import org.dromara.hmily.repository.spi.entity.tuple.HmilySQLTuple;
|
||||
import org.dromara.hmily.tac.metadata.HmilyMetaDataManager;
|
||||
import org.dromara.hmily.tac.metadata.model.TableMetaData;
|
||||
import org.dromara.hmily.tac.sqlparser.model.common.segment.dml.column.HmilyColumnSegment;
|
||||
import org.dromara.hmily.tac.sqlparser.model.common.segment.dml.expr.HmilyBinaryOperationExpression;
|
||||
import org.dromara.hmily.tac.sqlparser.model.common.segment.dml.expr.HmilyExpressionSegment;
|
||||
import org.dromara.hmily.tac.sqlparser.model.common.segment.dml.expr.simple.HmilyParameterMarkerExpressionSegment;
|
||||
@ -77,15 +76,23 @@ public final class HmilyUpdateSQLComputeEngine extends AbstractHmilySQLComputeEn
|
||||
List<Object> result = new LinkedList<>();
|
||||
sqlStatement.getWhere().ifPresent(whereSegment -> {
|
||||
HmilyExpressionSegment hmilyExpressionSegment = whereSegment.getExpr();
|
||||
if (hmilyExpressionSegment instanceof HmilyBinaryOperationExpression && ((HmilyBinaryOperationExpression) hmilyExpressionSegment).getLeft() instanceof HmilyColumnSegment
|
||||
&& ((HmilyBinaryOperationExpression) hmilyExpressionSegment).getRight() instanceof HmilyParameterMarkerExpressionSegment) {
|
||||
int parameterMarkerIndex = ((HmilyParameterMarkerExpressionSegment) ((HmilyBinaryOperationExpression) hmilyExpressionSegment).getRight()).getParameterMarkerIndex();
|
||||
result.add(parameters.get(parameterMarkerIndex));
|
||||
}
|
||||
getParameters(hmilyExpressionSegment, parameters, result);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private void getParameters(final HmilyExpressionSegment hmilyExpressionSegment, final List<Object> parameters, final List<Object> result) {
|
||||
if (hmilyExpressionSegment instanceof HmilyParameterMarkerExpressionSegment) {
|
||||
int parameterMarkerIndex = ((HmilyParameterMarkerExpressionSegment) hmilyExpressionSegment).getParameterMarkerIndex();
|
||||
result.add(parameters.get(parameterMarkerIndex));
|
||||
return;
|
||||
}
|
||||
if (hmilyExpressionSegment instanceof HmilyBinaryOperationExpression) {
|
||||
getParameters(((HmilyBinaryOperationExpression) hmilyExpressionSegment).getLeft(), parameters, result);
|
||||
getParameters(((HmilyBinaryOperationExpression) hmilyExpressionSegment).getRight(), parameters, result);
|
||||
}
|
||||
}
|
||||
|
||||
private Collection<HmilySQLTuple> doConvert(final Collection<Map<String, Object>> records, final TableMetaData tableMetaData) {
|
||||
Collection<HmilySQLTuple> result = new LinkedList<>();
|
||||
for (Map<String, Object> record : records) {
|
||||
|
@ -124,10 +124,9 @@ public final class UpdateStatementAssembler {
|
||||
|
||||
private static HmilyExpressionSegment assembleHmilyExpressionSegment(final ExpressionSegment expression) {
|
||||
HmilyExpressionSegment result = null;
|
||||
if (expression instanceof BinaryOperationExpression && ((BinaryOperationExpression) expression).getLeft() instanceof ColumnSegment
|
||||
&& ((BinaryOperationExpression) expression).getRight() instanceof ParameterMarkerExpressionSegment) {
|
||||
HmilyColumnSegment hmilyLeft = assembleHmilyColumnSegment((ColumnSegment) ((BinaryOperationExpression) expression).getLeft());
|
||||
HmilyParameterMarkerExpressionSegment hmilyRight = (HmilyParameterMarkerExpressionSegment) assembleHmilyExpressionSegment(((BinaryOperationExpression) expression).getRight());
|
||||
if (expression instanceof BinaryOperationExpression) {
|
||||
HmilyExpressionSegment hmilyLeft = assembleHmilyExpressionSegment(((BinaryOperationExpression) expression).getLeft());
|
||||
HmilyExpressionSegment hmilyRight = assembleHmilyExpressionSegment(((BinaryOperationExpression) expression).getRight());
|
||||
result = new HmilyBinaryOperationExpression(expression.getStartIndex(), expression.getStopIndex(), hmilyLeft, hmilyRight,
|
||||
((BinaryOperationExpression) expression).getOperator(), ((BinaryOperationExpression) expression).getText());
|
||||
} else if (expression instanceof ColumnSegment) {
|
||||
|
Loading…
Reference in New Issue
Block a user