MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / replaceTableInStmt

Function replaceTableInStmt

pkg/transform/tables.go:274–288  ·  view source on GitHub ↗

replaceTableInStmt recursively replaces table names in all parts of a statement, including FROM, JOINs, and all expressions (with subquery recursion).

(stmt ast.Statement, old, new string)

Source from the content-addressed store, hash-verified

272// replaceTableInStmt recursively replaces table names in all parts of a statement,
273// including FROM, JOINs, and all expressions (with subquery recursion).
274func replaceTableInStmt(stmt ast.Statement, old, new string) {
275 sel, ok := stmt.(*ast.SelectStatement)
276 if !ok || sel == nil {
277 return
278 }
279 replaceTableInFrom(sel.From, old, new)
280 replaceTableInJoins(sel.Joins, old, new)
281 for i := range sel.Columns {
282 sel.Columns[i] = replaceTableInExpr(sel.Columns[i], old, new)
283 }
284 sel.Where = replaceTableInExpr(sel.Where, old, new)
285 for i := range sel.OrderBy {
286 sel.OrderBy[i].Expression = replaceTableInExpr(sel.OrderBy[i].Expression, old, new)
287 }
288}
289
290func replaceTableInExpr(expr ast.Expression, old, new string) ast.Expression {
291 if expr == nil {

Callers 1

replaceTableInExprFunction · 0.85

Calls 3

replaceTableInFromFunction · 0.85
replaceTableInJoinsFunction · 0.85
replaceTableInExprFunction · 0.85

Tested by

no test coverage detected