Vanillaxi commented on code in PR #1141:
URL:
https://github.com/apache/incubator-seata-go/pull/1141#discussion_r3843222647
##########
pkg/datasource/sql/exec/at/update_executor.go:
##########
@@ -360,3 +369,20 @@ func (u *updateExecutor) buildBeforeImageSQL(ctx
context.Context, args []driver.
return sql, u.buildSelectArgs(&selStmt, args), nil
}
+
+func (u *updateExecutor) validatePrimaryKeyAssignments(metaData
*types.TableMeta) error {
+ for _, assignment := range u.parserCtx.UpdateStmt.List {
+ for _, primaryKey := range metaData.GetPrimaryKeyOnlyName() {
+ if !strings.EqualFold(assignment.Column.Name.O,
primaryKey) {
+ continue
+ }
+
+ columnExpr, selfAssignment :=
assignment.Expr.(*ast.ColumnNameExpr)
+ if selfAssignment &&
strings.EqualFold(columnExpr.Name.Name.O, primaryKey) {
+ continue
+ }
+ return fmt.Errorf("updating primary key column %q is
not supported", assignment.Column.Name.O)
+ }
+ }
+ return nil
+}
Review Comment:
This is already guarded by a two-result type assertion: columnExpr,
selfAssignment := assignment.Expr.(*ast.ColumnNameExpr). The following &&
short-circuits when selfAssignment is false, so non-column expressions are
never dereferenced and return the unsupported primary-key update error.
TestBuildSelectSQLByUpdateRejectsPrimaryKeyChange covers SET id = ? and a
non-self expression (id = id + 0); go test ./pkg/datasource/sql/exec/at -run
^TestBuildSelectSQLByUpdateRejectsPrimaryKeyChange$ -count=1 passes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]