(buf *strings.Builder, n *ast.DeleteStmt, sql string)
| 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. |
| 381 | // For multi-table DELETE: everything from the USING/reference table list to end. |
| 382 | if len(n.Using) > 0 { |
| 383 | start := nodeLocStart(n.Using[0]) |
| 384 | end := n.Loc.End |
| 385 | if end <= 0 || end > len(sql) { |
| 386 | end = len(sql) |
| 387 | } |
| 388 | if start >= 0 && end > start { |
| 389 | if _, err := buf.WriteString(strings.TrimSpace(sql[start:end])); err != nil { |
| 390 | return err |
| 391 | } |
| 392 | } |
| 393 | } else if len(n.Tables) > 0 { |
| 394 | start := nodeLocStart(n.Tables[0]) |
| 395 | end := n.Loc.End |
| 396 | if end <= 0 || end > len(sql) { |
| 397 | end = len(sql) |
| 398 | } |
| 399 | if start >= 0 && end > start { |
| 400 | if _, err := buf.WriteString(strings.TrimSpace(sql[start:end])); err != nil { |
| 401 | return err |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | return nil |
| 406 | } |
| 407 | |
| 408 | func nodeLocStart(expr ast.TableExpr) int { |
| 409 | switch e := expr.(type) { |
no test coverage detected