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

Function replaceTableInExpr

pkg/transform/tables.go:290–329  ·  view source on GitHub ↗
(expr ast.Expression, old, new string)

Source from the content-addressed store, hash-verified

288}
289
290func replaceTableInExpr(expr ast.Expression, old, new string) ast.Expression {
291 if expr == nil {
292 return nil
293 }
294 // For subquery-containing expressions, recurse into the full statement
295 // so that FROM/JOIN table names are also replaced.
296 switch e := expr.(type) {
297 case *ast.SubqueryExpression:
298 replaceTableInStmt(e.Subquery, old, new)
299 return e
300 case *ast.ExistsExpression:
301 replaceTableInStmt(e.Subquery, old, new)
302 return e
303 case *ast.InExpression:
304 e.Expr = replaceTableInExpr(e.Expr, old, new)
305 for i := range e.List {
306 e.List[i] = replaceTableInExpr(e.List[i], old, new)
307 }
308 if e.Subquery != nil {
309 replaceTableInStmt(e.Subquery, old, new)
310 }
311 return e
312 case *ast.AnyExpression:
313 e.Expr = replaceTableInExpr(e.Expr, old, new)
314 replaceTableInStmt(e.Subquery, old, new)
315 return e
316 case *ast.AllExpression:
317 e.Expr = replaceTableInExpr(e.Expr, old, new)
318 replaceTableInStmt(e.Subquery, old, new)
319 return e
320 }
321 return walkExpr(expr, func(e ast.Expression) ast.Expression {
322 if id, ok := e.(*ast.Identifier); ok {
323 if strings.EqualFold(id.Table, old) {
324 id.Table = new
325 }
326 }
327 return e
328 })
329}
330
331func qualifyExpr(expr ast.Expression, table string) ast.Expression {
332 return walkExpr(expr, func(e ast.Expression) ast.Expression {

Callers 3

ReplaceTableFunction · 0.85
replaceTableInJoinsFunction · 0.85
replaceTableInStmtFunction · 0.85

Calls 2

replaceTableInStmtFunction · 0.85
walkExprFunction · 0.85

Tested by

no test coverage detected