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)
| 272 | // replaceTableInStmt recursively replaces table names in all parts of a statement, |
| 273 | // including FROM, JOINs, and all expressions (with subquery recursion). |
| 274 | func 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 | |
| 290 | func replaceTableInExpr(expr ast.Expression, old, new string) ast.Expression { |
| 291 | if expr == nil { |
no test coverage detected