MCPcopy Create free account
hub / github.com/bytebase/bytebase / writeUpdateSuffix

Function writeUpdateSuffix

backend/plugin/parser/tidb/backup.go:718–750  ·  view source on GitHub ↗
(buf *strings.Builder, n *ast.UpdateStmt, sql string)

Source from the content-addressed store, hash-verified

716}
717
718func writeUpdateSuffix(buf *strings.Builder, n *ast.UpdateStmt, sql string) error {
719 // "table_refs": from the first table ref to the last table ref's end.
720 if len(n.Tables) > 0 {
721 start := nodeLocStart(n.Tables[0])
722 end := nodeLocEnd(n.Tables[len(n.Tables)-1])
723 if start >= 0 && end > start && end <= len(sql) {
724 // omni excludes parentheses wrapping the table-ref list, so a
725 // parenthesized join operand can leave the slice unbalanced.
726 if _, err := buf.WriteString(balancedTableRefs(sql[start:end])); err != nil {
727 return err
728 }
729 }
730 }
731
732 // Everything after the last SET assignment is WHERE + ORDER BY + LIMIT.
733 if len(n.SetList) > 0 {
734 lastAssign := n.SetList[len(n.SetList)-1]
735 afterSet := lastAssign.Loc.End
736 stmtEnd := n.Loc.End
737 if stmtEnd <= 0 || stmtEnd > len(sql) {
738 stmtEnd = len(sql)
739 }
740 if afterSet >= 0 && afterSet < stmtEnd {
741 suffix := strings.TrimSpace(sql[afterSet:stmtEnd])
742 if suffix != "" {
743 if _, err := fmt.Fprintf(buf, " %s", suffix); err != nil {
744 return err
745 }
746 }
747 }
748 }
749 return nil
750}
751
752func writeDeleteSuffix(buf *strings.Builder, n *ast.DeleteStmt, sql string) error {
753 // Single-table DELETE: from the table ref to statement end.

Callers 1

writeSuffixSelectClauseFunction · 0.70

Calls 3

balancedTableRefsFunction · 0.85
nodeLocStartFunction · 0.70
nodeLocEndFunction · 0.70

Tested by

no test coverage detected