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

Function parseCTEPrefix

backend/plugin/parser/tidb/backup.go:459–478  ·  view source on GitHub ↗
(fullSQL string, stmtLoc ast.Loc)

Source from the content-addressed store, hash-verified

457}
458
459func parseCTEPrefix(fullSQL string, stmtLoc ast.Loc) []*ast.CommonTableExpr {
460 if stmtLoc.Start <= 0 || stmtLoc.Start > len(fullSQL) {
461 return nil
462 }
463 prefix := strings.TrimSpace(fullSQL[:stmtLoc.Start])
464 if prefix == "" {
465 return nil
466 }
467 // Wrap the prefix with a dummy SELECT so it parses as a complete statement.
468 parsed, err := ParseTiDBOmni(prefix + " SELECT 1")
469 if err != nil || parsed == nil {
470 return nil
471 }
472 for _, item := range parsed.Items {
473 if sel, ok := item.(*ast.SelectStmt); ok && len(sel.CTEs) > 0 {
474 return sel.CTEs
475 }
476 }
477 return nil
478}
479
480func extractStatementText(fullSQL string, loc ast.Loc) string {
481 start := max(0, loc.Start)

Callers 2

collectCTENamesFunction · 0.70
extractCTEFunction · 0.70

Calls 1

ParseTiDBOmniFunction · 0.85

Tested by

no test coverage detected