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

Function writeDeleteSuffix

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

Source from the content-addressed store, hash-verified

750}
751
752func writeDeleteSuffix(buf *strings.Builder, n *ast.DeleteStmt, sql string) error {
753 // Single-table DELETE: from the table ref to statement end.
754 // Multi-table DELETE: from the USING/reference table list to statement end.
755 var start int
756 switch {
757 case len(n.Using) > 0:
758 start = nodeLocStart(n.Using[0])
759 case len(n.Tables) > 0:
760 start = nodeLocStart(n.Tables[0])
761 default:
762 return nil
763 }
764 end := n.Loc.End
765 if end <= 0 || end > len(sql) {
766 end = len(sql)
767 }
768 if start >= 0 && end > start {
769 // omni excludes parentheses wrapping the table-ref list, so the slice can
770 // carry an unmatched ")"; rebalance it before emitting.
771 if _, err := buf.WriteString(balancedTableRefs(sql[start:end])); err != nil {
772 return err
773 }
774 }
775 return nil
776}
777
778// balancedTableRefs returns s (trimmed) with parentheses balanced. omni's
779// JoinClause/TableRef Loc excludes a wrapping "(" or ")", so a sliced table-ref

Callers 1

writeSuffixSelectClauseFunction · 0.70

Calls 2

balancedTableRefsFunction · 0.85
nodeLocStartFunction · 0.70

Tested by

no test coverage detected