returns the objects and information required for query execution if the query contains error, a ExecutionCtx struct with the AST and Execution plan objects will be NULL and EXECUTION_TYPE_INVALID is returned returns ExecutionCtx populated with the current execution relevant objects
| 95 | // and EXECUTION_TYPE_INVALID is returned |
| 96 | // returns ExecutionCtx populated with the current execution relevant objects |
| 97 | ExecutionCtx *ExecutionCtx_FromQuery |
| 98 | ( |
| 99 | const char *q // string representing the query |
| 100 | ) { |
| 101 | ASSERT(q != NULL); |
| 102 | |
| 103 | ExecutionCtx *ret; |
| 104 | const char *q_str; // query string excluding query parameters |
| 105 | |
| 106 | if(unlikely(strlen(q) == 0)) { |
| 107 | ErrorCtx_SetError("Error: empty query."); |
| 108 | return NULL; |
| 109 | } |
| 110 | |
| 111 | // parse and validate parameters only |
| 112 | // extract query string |
| 113 | // return invalid execution context if failed to parse params |
| 114 | cypher_parse_result_t *params_parse_result = parse_params(q, &q_str); |
| 115 | |
| 116 | // parameter parsing failed, return NULL |
| 117 | if(params_parse_result == NULL) { |
| 118 | return NULL; |
| 119 | } |
| 120 | |
| 121 | // seems like we should be able to free 'params_parse_result' |
| 122 | // at this point but this messes up the parsing of the actual query |
| 123 | |
| 124 | // query included only params e.g. 'cypher a=1' was provided |
| 125 | if(unlikely(strlen(q_str) == 0)) { |
| 126 | parse_result_free(params_parse_result); |
| 127 | ErrorCtx_SetError("Error: empty query."); |
| 128 | return NULL; |
| 129 | } |
| 130 | |
| 131 | // update query context with the query without params |
| 132 | // (here the QueryInfo is created as well, starting the stage timer) |
| 133 | QueryCtx *ctx = QueryCtx_GetQueryCtx(); |
| 134 | ctx->query_data.query_no_params = q_str; |
| 135 | |
| 136 | // get cache |
| 137 | Cache *cache = GraphContext_GetCache(QueryCtx_GetGraphCtx()); |
| 138 | |
| 139 | // see if we already have a cached execution-ctx for given query |
| 140 | ret = Cache_GetValue(cache, q_str); |
| 141 | |
| 142 | //-------------------------------------------------------------------------- |
| 143 | // cache hit |
| 144 | //-------------------------------------------------------------------------- |
| 145 | |
| 146 | if(ret != NULL) { |
| 147 | parse_result_free(params_parse_result); // free parsed params |
| 148 | ret->cached = true; // mark cached execution |
| 149 | return ret; |
| 150 | } |
| 151 | |
| 152 | //-------------------------------------------------------------------------- |
| 153 | // cache miss |
| 154 | //-------------------------------------------------------------------------- |
no test coverage detected