(buf *strings.Builder, n *ast.UpdateStmt, sql string)
| 716 | } |
| 717 | |
| 718 | func 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 | |
| 752 | func writeDeleteSuffix(buf *strings.Builder, n *ast.DeleteStmt, sql string) error { |
| 753 | // Single-table DELETE: from the table ref to statement end. |
no test coverage detected