replaces a `WITH` clause, placed in clause_idx within `callsubquery`, with a new `WITH` clause containing projections of `names` to `inter_names`
| 119 | // replaces a `WITH` clause, placed in clause_idx within `callsubquery`, with a |
| 120 | // new `WITH` clause containing projections of `names` to `inter_names` |
| 121 | static void _replace_with_clause |
| 122 | ( |
| 123 | cypher_astnode_t *callsubquery, // call subquery ast-node |
| 124 | uint clause_idx, // index of clause to replace |
| 125 | char **names, // original bound vars |
| 126 | char **inter_names // internal representation of bound vars |
| 127 | ) { |
| 128 | cypher_astnode_t *query = |
| 129 | cypher_ast_call_subquery_get_query(callsubquery); |
| 130 | const cypher_astnode_t *clause = cypher_ast_query_get_clause(query, |
| 131 | clause_idx); |
| 132 | |
| 133 | uint existing_projections_count = cypher_ast_with_nprojections(clause); |
| 134 | uint n_projections = array_len(inter_names) + existing_projections_count; |
| 135 | uint proj_idx = 0; |
| 136 | cypher_astnode_t *projections[n_projections]; |
| 137 | |
| 138 | //-------------------------------------------------------------------------- |
| 139 | // create projections for bound vars |
| 140 | //-------------------------------------------------------------------------- |
| 141 | |
| 142 | proj_idx = _add_projections(projections, proj_idx, names, inter_names, |
| 143 | true); |
| 144 | |
| 145 | //-------------------------------------------------------------------------- |
| 146 | // introduce explicit projections |
| 147 | //-------------------------------------------------------------------------- |
| 148 | |
| 149 | // clone explicit projections into projections array |
| 150 | for(uint i = 0; i < existing_projections_count; i++) { |
| 151 | const cypher_astnode_t *projection = |
| 152 | cypher_ast_with_get_projection(clause, i); |
| 153 | projections[proj_idx++] = cypher_ast_clone(projection); |
| 154 | } |
| 155 | |
| 156 | // copy projections to the children array |
| 157 | cypher_astnode_t *children[n_projections + 4]; |
| 158 | for(uint i = 0; i < n_projections; i++) { |
| 159 | children[i] = projections[i]; |
| 160 | } |
| 161 | |
| 162 | //-------------------------------------------------------------------------- |
| 163 | // prepare additional arguments |
| 164 | //-------------------------------------------------------------------------- |
| 165 | |
| 166 | bool distinct = false; |
| 167 | const cypher_astnode_t *skip = NULL; |
| 168 | const cypher_astnode_t *limit = NULL; |
| 169 | const cypher_astnode_t *order_by = NULL; |
| 170 | const cypher_astnode_t *pred = NULL; |
| 171 | |
| 172 | skip = cypher_ast_with_get_skip(clause); |
| 173 | limit = cypher_ast_with_get_limit(clause); |
| 174 | distinct = cypher_ast_with_is_distinct(clause); |
| 175 | order_by = cypher_ast_with_get_order_by(clause); |
| 176 | pred = cypher_ast_with_get_predicate(clause); |
| 177 | |
| 178 | // clone any ORDER BY, SKIP, LIMIT, and WHERE modifiers to |
no test coverage detected