未验证 提交 39323e37 编写于 作者: H Haoran Meng 提交者: GitHub

Fixes update SQL was rewritten error in encrypt_db with pgsql (#7860)

* Fixes update SQL was rewritten error in encrypt_db with pgsql

* Remove useless import
上级 e4428d6a
......@@ -65,14 +65,12 @@ import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.Wh
import org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.WhereOrCurrentClauseContext;
import org.apache.shardingsphere.sql.parser.postgresql.visitor.PostgreSQLVisitor;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.InsertValuesSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.SetAssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.InsertColumnsSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.complex.CommonExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
......@@ -231,8 +229,7 @@ public final class PostgreSQLDMLVisitor extends PostgreSQLVisitor implements DML
@Override
public ASTNode visitSetClause(final SetClauseContext ctx) {
ColumnSegment columnSegment = (ColumnSegment) visit(ctx.setTarget());
SQLSegment sqlSegment = (SQLSegment) visit(ctx.aExpr());
ExpressionSegment expressionSegment = new CommonExpressionSegment(sqlSegment.getStartIndex(), sqlSegment.getStopIndex(), sqlSegment.toString());
ExpressionSegment expressionSegment = (ExpressionSegment) visit(ctx.aExpr());
return new AssignmentSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), columnSegment, expressionSegment);
}
......
......@@ -522,4 +522,29 @@
<row-count value="10" parameter-index="3" start-index="89" stop-index="89" literal-start-index="96" literal-stop-index="97" />
</limit>
</update>
<update sql-case-id="update_with_number" parameters="1, 1">
<table name="t_order" start-index="7" stop-index="13" />
<set start-index="15" stop-index="30" literal-stop-index="30">
<assignment start-index="19" stop-index="30" literal-stop-index="30">
<column name="order_id" start-index="19" stop-index="26" />
<assignment-value>
<parameter-marker-expression value="0" start-index="30" stop-index="30" />
<literal-expression value="1" start-index="30" stop-index="30" />
</assignment-value>
</assignment>
</set>
<where start-index="32" stop-index="48" literal-start-index="43" literal-stop-index="43">
<and-predicate>
<predicate start-index="38" stop-index="48" literal-start-index="60" literal-stop-index="60">
<column-left-value name="user_id" start-index="38" stop-index="44" literal-start-index="38" literal-stop-index="44" />
<operator type="=" />
<compare-right-value>
<parameter-marker-expression value="1" start-index="48" stop-index="48" />
<literal-expression value="1" start-index="48" stop-index="48" />
</compare-right-value>
</predicate>
</and-predicate>
</where>
</update>
</sql-parser-test-cases>
......@@ -32,4 +32,5 @@
<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-case id="update_with_order_by_row_count" value="UPDATE t_order SET status = ? WHERE order_id = ? AND user_id = ? ORDER BY order_id LIMIT ?" db-types="MySQL"/>
<sql-case id="update_with_number" value="UPDATE t_order SET order_id = ? WHERE user_id = ?" db-types="PostgreSQL" />
</sql-cases>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册