(node *pg_query.Node, changed *bool)
| 38 | } |
| 39 | |
| 40 | func (t *VersionTransform) walkAndTransform(node *pg_query.Node, changed *bool) { |
| 41 | if node == nil { |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | switch n := node.Node.(type) { |
| 46 | case *pg_query.Node_FuncCall: |
| 47 | if n.FuncCall != nil { |
| 48 | // version() calls are handled by a macro defined in initPgCatalog |
| 49 | // No AST transformation needed - the deparser outputs version() |
| 50 | // and the macro returns the appropriate version string |
| 51 | |
| 52 | // Recurse into function arguments |
| 53 | for _, arg := range n.FuncCall.Args { |
| 54 | t.walkAndTransform(arg, changed) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | case *pg_query.Node_SelectStmt: |
| 59 | if n.SelectStmt != nil { |
| 60 | t.walkSelectStmt(n.SelectStmt, changed) |
| 61 | } |
| 62 | |
| 63 | case *pg_query.Node_ResTarget: |
| 64 | if n.ResTarget != nil { |
| 65 | // Check if this ResTarget contains a version() call and replace it |
| 66 | if funcCall := t.getFuncCall(n.ResTarget.Val); funcCall != nil { |
| 67 | if t.isVersionCall(funcCall) { |
| 68 | // Replace the FuncCall with a string constant |
| 69 | n.ResTarget.Val = &pg_query.Node{ |
| 70 | Node: &pg_query.Node_AConst{ |
| 71 | AConst: &pg_query.A_Const{ |
| 72 | Val: &pg_query.A_Const_Sval{ |
| 73 | Sval: &pg_query.String{Sval: PostgreSQLVersionString}, |
| 74 | }, |
| 75 | }, |
| 76 | }, |
| 77 | } |
| 78 | // Set alias to "version" if not already set |
| 79 | if n.ResTarget.Name == "" { |
| 80 | n.ResTarget.Name = "version" |
| 81 | } |
| 82 | *changed = true |
| 83 | return |
| 84 | } |
| 85 | } |
| 86 | t.walkAndTransform(n.ResTarget.Val, changed) |
| 87 | } |
| 88 | |
| 89 | case *pg_query.Node_TypeCast: |
| 90 | if n.TypeCast != nil { |
| 91 | t.walkAndTransform(n.TypeCast.Arg, changed) |
| 92 | } |
| 93 | |
| 94 | case *pg_query.Node_AExpr: |
| 95 | if n.AExpr != nil { |
| 96 | t.walkAndTransform(n.AExpr.Lexpr, changed) |
| 97 | t.walkAndTransform(n.AExpr.Rexpr, changed) |
no test coverage detected