升级jsqlparser至4.10-SNAPSHOT.
https://github.com/baomidou/mybatis-plus/issues/6068
This commit is contained in:
parent
423a99bfbf
commit
253973b9cf
@ -18,7 +18,7 @@ ext {
|
||||
springBootVersion = '2.7.18',
|
||||
springBoot3Version = '3.3.1',
|
||||
springCloudVersion = '3.1.8',
|
||||
jsqlparserVersion = '4.9',
|
||||
jsqlparserVersion = '5.0',
|
||||
junitVersion = '5.10.3',
|
||||
]
|
||||
|
||||
|
@ -20,7 +20,7 @@ class JSqlParserTest {
|
||||
void parser() throws Exception {
|
||||
Select select = (Select) CCJSqlParserUtil.parse("SELECT a,b,c FROM tableName t WHERE t.col = 9 and b=c LIMIT 3, ?");
|
||||
|
||||
PlainSelect ps = (PlainSelect) select.getSelectBody();
|
||||
PlainSelect ps = (PlainSelect) select;
|
||||
|
||||
System.out.println(ps.getWhere().toString());
|
||||
System.out.println(ps.getSelectItems().get(1).toString());
|
||||
@ -47,4 +47,13 @@ class JSqlParserTest {
|
||||
Delete delete = (Delete) CCJSqlParserUtil.parse("delete from tableName t");
|
||||
Assertions.assertNull(delete.getWhere());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSelectForUpdate() throws Exception {
|
||||
Assertions.assertEquals("SELECT * FROM t_demo WHERE a = 1 FOR UPDATE",
|
||||
CCJSqlParserUtil.parse("select * from t_demo where a = 1 for update").toString());
|
||||
Assertions.assertEquals("SELECT * FROM sys_sms_send_record WHERE check_status = 0 ORDER BY submit_time ASC LIMIT 10 FOR UPDATE",
|
||||
CCJSqlParserUtil.parse("select * from sys_sms_send_record where check_status = 0 for update order by submit_time asc limit 10").toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ public class FstFactory {
|
||||
conf.registerClass(net.sf.jsqlparser.expression.ExtractExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.FilterOverImpl.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.Function.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.Function.HavingClause.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.HexValue.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.IntervalExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.JdbcNamedParameter.class);
|
||||
@ -59,6 +60,7 @@ public class FstFactory {
|
||||
conf.registerClass(net.sf.jsqlparser.expression.JsonFunctionExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.JsonKeyValuePair.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.KeepExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.LambdaExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.LongValue.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.MySQLGroupConcat.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.MySQLIndexHint.class);
|
||||
@ -79,6 +81,7 @@ public class FstFactory {
|
||||
conf.registerClass(net.sf.jsqlparser.expression.SQLServerHints.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.SignedExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.StringValue.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.StructType.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.TimeKeyExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.TimeValue.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.TimestampValue.class);
|
||||
@ -113,6 +116,7 @@ public class FstFactory {
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.Contains.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.DoubleAnd.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.EqualsTo.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.ExcludesExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.ExistsExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.ExpressionList.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.FullTextSearch.class);
|
||||
@ -120,6 +124,7 @@ public class FstFactory {
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.GreaterThan.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.InExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.IncludesExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.IsBooleanExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.IsDistinctExpression.class);
|
||||
conf.registerClass(net.sf.jsqlparser.expression.operators.relational.IsNullExpression.class);
|
||||
|
@ -28,6 +28,7 @@ import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
|
||||
import net.sf.jsqlparser.expression.operators.relational.ExistsExpression;
|
||||
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
|
||||
import net.sf.jsqlparser.expression.operators.relational.InExpression;
|
||||
import net.sf.jsqlparser.expression.operators.relational.ParenthesedExpressionList;
|
||||
import net.sf.jsqlparser.schema.Table;
|
||||
import net.sf.jsqlparser.statement.select.*;
|
||||
|
||||
@ -76,7 +77,7 @@ public abstract class BaseMultiTableInnerInterceptor extends JsqlParserSupport i
|
||||
}
|
||||
if (where != null) {
|
||||
if (where instanceof OrExpression) {
|
||||
return new AndExpression(new Parenthesis(where), expression);
|
||||
return new AndExpression(new ParenthesedExpressionList<>(where), expression);
|
||||
} else {
|
||||
return new AndExpression(where, expression);
|
||||
}
|
||||
@ -189,9 +190,9 @@ public abstract class BaseMultiTableInnerInterceptor extends JsqlParserSupport i
|
||||
// not exists
|
||||
NotExpression expression = (NotExpression) where;
|
||||
processWhereSubSelect(expression.getExpression(), whereSegment);
|
||||
} else if (where instanceof Parenthesis) {
|
||||
Parenthesis expression = (Parenthesis) where;
|
||||
processWhereSubSelect(expression.getExpression(), whereSegment);
|
||||
} else if (where instanceof ParenthesedExpressionList) {
|
||||
ParenthesedExpressionList<Expression> expression = (ParenthesedExpressionList) where;
|
||||
processWhereSubSelect(expression.get(0), whereSegment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -406,7 +407,7 @@ public abstract class BaseMultiTableInnerInterceptor extends JsqlParserSupport i
|
||||
return injectExpression;
|
||||
}
|
||||
if (currentExpression instanceof OrExpression) {
|
||||
return new AndExpression(new Parenthesis(currentExpression), injectExpression);
|
||||
return new AndExpression(new ParenthesedExpressionList<>(currentExpression), injectExpression);
|
||||
} else {
|
||||
return new AndExpression(currentExpression, injectExpression);
|
||||
}
|
||||
|
@ -25,12 +25,12 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.parser.JsqlParserSupport;
|
||||
import net.sf.jsqlparser.expression.BinaryExpression;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.Parenthesis;
|
||||
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
|
||||
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
|
||||
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
|
||||
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
|
||||
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
|
||||
import net.sf.jsqlparser.expression.operators.relational.ParenthesedExpressionList;
|
||||
import net.sf.jsqlparser.statement.delete.Delete;
|
||||
import net.sf.jsqlparser.statement.update.Update;
|
||||
import org.apache.ibatis.executor.statement.StatementHandler;
|
||||
@ -113,10 +113,10 @@ public class BlockAttackInnerInterceptor extends JsqlParserSupport implements In
|
||||
|
||||
AndExpression andExpression = (AndExpression) where;
|
||||
return fullMatch(andExpression.getLeftExpression(), logicField) && fullMatch(andExpression.getRightExpression(), logicField);
|
||||
} else if (where instanceof Parenthesis) {
|
||||
} else if (where instanceof ParenthesedExpressionList) {
|
||||
// example: (1 = 1)
|
||||
Parenthesis parenthesis = (Parenthesis) where;
|
||||
return fullMatch(parenthesis.getExpression(), logicField);
|
||||
ParenthesedExpressionList<Expression> parenthesis = (ParenthesedExpressionList<Expression>) where;
|
||||
return fullMatch(parenthesis.get(0), logicField);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -27,11 +27,11 @@ import lombok.Data;
|
||||
import net.sf.jsqlparser.expression.BinaryExpression;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.Function;
|
||||
import net.sf.jsqlparser.expression.Parenthesis;
|
||||
import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction;
|
||||
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
|
||||
import net.sf.jsqlparser.expression.operators.relational.InExpression;
|
||||
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
|
||||
import net.sf.jsqlparser.expression.operators.relational.ParenthesedExpressionList;
|
||||
import net.sf.jsqlparser.schema.Column;
|
||||
import net.sf.jsqlparser.schema.Table;
|
||||
import net.sf.jsqlparser.statement.delete.Delete;
|
||||
@ -155,9 +155,9 @@ public class IllegalSQLInnerInterceptor extends JsqlParserSupport implements Inn
|
||||
* @param expression ignore
|
||||
*/
|
||||
private void validExpression(Expression expression) {
|
||||
while (expression instanceof Parenthesis) {
|
||||
Parenthesis parenthesis = (Parenthesis) expression;
|
||||
expression = parenthesis.getExpression();
|
||||
while (expression instanceof ParenthesedExpressionList) {
|
||||
ParenthesedExpressionList<Expression> parenthesis = (ParenthesedExpressionList) expression;
|
||||
expression = parenthesis.get(0);
|
||||
}
|
||||
//where条件使用了 or 关键字
|
||||
if (expression instanceof OrExpression) {
|
||||
|
@ -21,8 +21,6 @@ import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.PropertyMapper;
|
||||
import lombok.*;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.Parenthesis;
|
||||
import net.sf.jsqlparser.expression.RowConstructor;
|
||||
import net.sf.jsqlparser.expression.StringValue;
|
||||
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
|
||||
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
|
||||
@ -135,12 +133,8 @@ public class TenantLineInnerInterceptor extends BaseMultiTableInnerInterceptor i
|
||||
int len = expressions.size();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Expression expression = expressions.get(i);
|
||||
if (expression instanceof Parenthesis) {
|
||||
ExpressionList rowConstructor = new RowConstructor<>()
|
||||
.withExpressions(new ExpressionList<>(((Parenthesis) expression).getExpression(), tenantId));
|
||||
expressions.set(i, rowConstructor);
|
||||
} else if (expression instanceof ParenthesedExpressionList) {
|
||||
((ParenthesedExpressionList) expression).addExpression(tenantId);
|
||||
if (expression instanceof ParenthesedExpressionList) {
|
||||
((ParenthesedExpressionList<Expression>) expression).addExpression(tenantId);
|
||||
} else {
|
||||
expressions.add(tenantId);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user