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

Function writeUpdateSuffix

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

Source from the content-addressed store, hash-verified

344}
345
346func 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
379func writeDeleteSuffix(buf *strings.Builder, n *ast.DeleteStmt, sql string) error {
380 // For single-table DELETE: everything from the table ref to statement end.

Callers 1

writeSuffixSelectClauseFunction · 0.70

Calls 2

nodeLocStartFunction · 0.70
nodeLocEndFunction · 0.70

Tested by

no test coverage detected