(expr ast.Expression, old, new string)
| 288 | } |
| 289 | |
| 290 | func 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 | |
| 331 | func qualifyExpr(expr ast.Expression, table string) ast.Expression { |
| 332 | return walkExpr(expr, func(e ast.Expression) ast.Expression { |
no test coverage detected