This function checks for the existence a valid root in the query. * As cypher_parse_result_t can have multiple roots such as comments, * only a query that has a root with type CYPHER_AST_STATEMENT is considered valid. * Comment roots are ignored. */
| 2135 | * only a query that has a root with type CYPHER_AST_STATEMENT is considered valid. |
| 2136 | * Comment roots are ignored. */ |
| 2137 | AST_Validation AST_Validate_ParseResultRoot |
| 2138 | ( |
| 2139 | const cypher_parse_result_t *result, |
| 2140 | int *index |
| 2141 | ) { |
| 2142 | // Check for failures in libcypher-parser |
| 2143 | ASSERT(AST_ContainsErrors(result) == false); |
| 2144 | |
| 2145 | uint nroots = cypher_parse_result_nroots(result); |
| 2146 | for(uint i = 0; i < nroots; i++) { |
| 2147 | const cypher_astnode_t *root = cypher_parse_result_get_root(result, i); |
| 2148 | cypher_astnode_type_t root_type = cypher_astnode_type(root); |
| 2149 | if(root_type == CYPHER_AST_LINE_COMMENT || root_type == CYPHER_AST_BLOCK_COMMENT || |
| 2150 | root_type == CYPHER_AST_COMMENT) { |
| 2151 | continue; |
| 2152 | } else if(root_type != CYPHER_AST_STATEMENT) { |
| 2153 | ErrorCtx_SetError("Encountered unsupported query type '%s'", cypher_astnode_typestr(root_type)); |
| 2154 | return AST_INVALID; |
| 2155 | } else { |
| 2156 | // We got a statement. |
| 2157 | *index = i; |
| 2158 | return AST_VALID; |
| 2159 | } |
| 2160 | } |
| 2161 | |
| 2162 | // query with no roots like ';' |
| 2163 | if(nroots == 0) { |
| 2164 | ErrorCtx_SetError("Error: empty query."); |
| 2165 | } |
| 2166 | |
| 2167 | return AST_INVALID; |
| 2168 | } |
| 2169 | |
| 2170 | // validate a query |
| 2171 | AST_Validation AST_Validate_Query |
no test coverage detected