未验证 提交 efc32868 编写于 作者: J JingShang Lu 提交者: GitHub

fix 6753 (#6915)

上级 6c862b8f
......@@ -29,7 +29,6 @@ import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BitExpr
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BitValueLiteralsContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BooleanLiteralsContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BooleanPrimaryContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CaseExpressionContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CastFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CharFunctionContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ColumnNameContext;
......@@ -392,7 +391,7 @@ public abstract class MySQLVisitor extends MySQLStatementBaseVisitor<ASTNode> {
return new SubqueryExpressionSegment((SubquerySegment) astNode);
}
if (astNode instanceof OtherLiteralValue) {
return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), context.getText());
return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), ((OtherLiteralValue) astNode).getValue());
}
return astNode;
}
......@@ -587,7 +586,9 @@ public abstract class MySQLVisitor extends MySQLStatementBaseVisitor<ASTNode> {
private ASTNode visitRemainSimpleExpr(final SimpleExprContext ctx) {
if (null != ctx.caseExpression()) {
return visit(ctx.caseExpression());
visit(ctx.caseExpression());
String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
return new OtherLiteralValue(text);
}
for (ExprContext each : ctx.expr()) {
visit(each);
......@@ -606,12 +607,6 @@ public abstract class MySQLVisitor extends MySQLStatementBaseVisitor<ASTNode> {
return new CommonExpressionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), text);
}
@Override
public final ASTNode visitCaseExpression(final CaseExpressionContext ctx) {
String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
return new OtherLiteralValue(text);
}
@Override
public final ASTNode visitDataTypeName(final DataTypeNameContext ctx) {
return new KeywordValue(ctx.getText());
......
......@@ -447,4 +447,40 @@
</and-predicate>
</where>
</update>
<update sql-case-id="update_with_case_when" parameters="3, 2, 4, 2, 10, 2, 3, 'll', 4, 'll', 10, 'll', 3, '2020-08-10T17:15:25.979+0800', 'jd'">
<table name="stock_freeze_detail" start-index="7" stop-index="25" />
<set start-index="27" stop-index="230" literal-stop-index="270" literal-start-index="27" >
<assignment start-index="31" stop-index="106" literal-start-index="31" literal-stop-index="107">
<column name="row_status" start-index="31" stop-index="40" />
<assignment-value>
<common-expression text="case WHEN (id=?) THEN ? WHEN (id=?) THEN ? WHEN (id=?) THEN ? end" literal-text="case WHEN (id=3) THEN 2 WHEN (id=4) THEN 2 WHEN (id=10) THEN 2 end" start-index="42" stop-index="106" literal-start-index="42" literal-stop-index="107"/>
</assignment-value>
</assignment>
<assignment start-index="113" stop-index="189" literal-start-index="114" literal-stop-index="200">
<column name="update_user" start-index="113" stop-index="123" literal-start-index="114" literal-stop-index="124"/>
<assignment-value>
<common-expression text="case WHEN (id=?) THEN ? WHEN (id=?) THEN ? WHEN (id=?) THEN ? end" literal-text="case WHEN (id=3) THEN 'll' WHEN (id=4) THEN 'll' WHEN (id=10) THEN 'll' end" start-index="125" stop-index="189" literal-start-index="126" literal-stop-index="200"/>
</assignment-value>
</assignment>
<assignment start-index="192" stop-index="230" literal-start-index="203" literal-stop-index="270">
<column name="update_time" start-index="192" stop-index="202" literal-start-index="203" literal-stop-index="213" />
<assignment-value>
<common-expression text="case WHEN (id=?) THEN ? end" literal-text="case WHEN (id=3) THEN '2020-08-10T17:15:25.979+0800' end" start-index="204" stop-index="230" literal-start-index="215" literal-stop-index="270"/>
</assignment-value>
</assignment>
</set>
<where start-index="232" stop-index="251" literal-start-index="272" literal-stop-index="294">
<and-predicate>
<predicate start-index="239" stop-index="251" literal-start-index="279" literal-stop-index="294">
<column-left-value name="tenant_id" start-index="239" stop-index="247" literal-start-index="279" literal-stop-index="287" />
<operator type="=" />
<compare-right-value>
<parameter-marker-expression value="14" start-index="251" stop-index="251"/>
<literal-expression value="jd" literal-start-index="291" literal-stop-index="294"/>
</compare-right-value>
</predicate>
</and-predicate>
</where>
</update>
</sql-parser-test-cases>
......@@ -29,4 +29,6 @@
<sql-case id="update_with_set_calculation" value="UPDATE t_order SET status = status - ? WHERE order_id = ? AND user_id = ?" />
<sql-case id="update_with_where_calculation" value="UPDATE t_order SET status = ? WHERE order_id = order_id - ? AND user_id = ?" />
<sql-case id="update_with_column_equal_column" value="update t_order set order_id = order_id, status = 'init' where order_id = order_id AND order_id = ?" db-types="MySQL"/>
<sql-case id="update_with_case_when" value="update stock_freeze_detail set row_status=case WHEN (id=?) THEN ? WHEN (id=?) THEN ? WHEN (id=?) THEN ? end,
update_user=case WHEN (id=?) THEN ? WHEN (id=?) THEN ? WHEN (id=?) THEN ? end, update_time=case WHEN (id=?) THEN ? end where tenant_id = ?" db-types="MySQL"/>
</sql-cases>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册