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

Function writeCTEPrefix

backend/plugin/parser/tidb/backup.go:431–438  ·  view source on GitHub ↗

writeCTEPrefix writes the statement's WITH (CTE) clause before the backup SELECT, so a SELECT whose FROM references a CTE stays valid. omni does not attach UPDATE/DELETE CTEs to the statement node, so the prefix is recovered from the text before the statement Loc.

(buf *strings.Builder, node ast.Node, fullSQL string)

Source from the content-addressed store, hash-verified

429// attach UPDATE/DELETE CTEs to the statement node, so the prefix is recovered
430// from the text before the statement Loc.
431func writeCTEPrefix(buf *strings.Builder, node ast.Node, fullSQL string) error {
432 cte := extractCTE(fullSQL, nodeStmtLoc(node))
433 if cte == "" {
434 return nil
435 }
436 _, err := fmt.Fprintf(buf, "%s ", cte)
437 return err
438}
439
440// extractCTE returns the WITH-clause text preceding the statement, or "".
441func extractCTE(fullSQL string, stmtLoc ast.Loc) string {

Callers 1

generateSQLForMixedDMLFunction · 0.85

Calls 2

extractCTEFunction · 0.70
nodeStmtLocFunction · 0.70

Tested by

no test coverage detected