(buf *strings.Builder, n *ast.UpdateStmt, sql string)
| 344 | } |
| 345 | |
| 346 | func writeUpdateSuffix(buf *strings.Builder, n *ast.UpdateStmt, sql string) error { |
| 347 | // For UPDATE: write "table_refs WHERE ... ORDER BY ... LIMIT ..." |
| 348 | // Use the last table's Loc.End as the boundary — everything from first table |
| 349 | // to last table's end is the table reference list. |
| 350 | if len(n.Tables) > 0 { |
| 351 | start := nodeLocStart(n.Tables[0]) |
| 352 | end := nodeLocEnd(n.Tables[len(n.Tables)-1]) |
| 353 | if start >= 0 && end > start && end <= len(sql) { |
| 354 | if _, err := buf.WriteString(strings.TrimSpace(sql[start:end])); err != nil { |
| 355 | return err |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | // Everything after the last SET assignment is WHERE + ORDER BY + LIMIT. |
| 361 | if len(n.SetList) > 0 { |
| 362 | lastAssign := n.SetList[len(n.SetList)-1] |
| 363 | afterSet := lastAssign.Loc.End |
| 364 | stmtEnd := n.Loc.End |
| 365 | if stmtEnd <= 0 || stmtEnd > len(sql) { |
| 366 | stmtEnd = len(sql) |
| 367 | } |
| 368 | suffix := strings.TrimSpace(sql[afterSet:stmtEnd]) |
| 369 | if suffix != "" { |
| 370 | if _, err := fmt.Fprintf(buf, " %s", suffix); err != nil { |
| 371 | return err |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | return nil |
| 377 | } |
| 378 | |
| 379 | func writeDeleteSuffix(buf *strings.Builder, n *ast.DeleteStmt, sql string) error { |
| 380 | // For single-table DELETE: everything from the table ref to statement end. |
no test coverage detected