MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _AST_Extract_Params

Function _AST_Extract_Params

src/ast/ast.c:91–131  ·  view source on GitHub ↗

this method extracts the query's parameters values, convert them into constant SIValues and store them in a map of in the query context

Source from the content-addressed store, hash-verified

89// constant SIValues and store them in a map of <name, value>
90// in the query context
91static void _AST_Extract_Params
92(
93 const cypher_parse_result_t *parse_result
94) {
95 // retrieve the AST root node from a parsed query
96 const cypher_astnode_t *statement = _AST_parse_result_root(parse_result);
97 uint noptions = cypher_ast_statement_noptions(statement);
98 if(noptions == 0) {
99 return;
100 }
101
102 rax *params = raxNew();
103 for(uint i = 0; i < noptions; i++) {
104 const cypher_astnode_t *option =
105 cypher_ast_statement_get_option(statement, i);
106 uint nparams = cypher_ast_cypher_option_nparams(option);
107
108 for(uint j = 0; j < nparams; j++) {
109 const cypher_astnode_t *param =
110 cypher_ast_cypher_option_get_param(option, j);
111
112 const char *paramName =
113 cypher_ast_string_get_value(
114 cypher_ast_cypher_option_param_get_name(param));
115
116 const cypher_astnode_t *paramValue =
117 cypher_ast_cypher_option_param_get_value(param);
118
119 AR_ExpNode *exp = AR_EXP_FromASTNode(paramValue);
120 SIValue *v = rm_malloc(sizeof(SIValue));
121 SIValue _v = AR_EXP_Evaluate(exp, NULL);
122 *v = SI_CloneValue(_v);
123 raxInsert(params, (unsigned char *)paramName, strlen(paramName),
124 (void *)v, NULL);
125 AR_EXP_Free(exp);
126 }
127 }
128
129 // add the parameters map to the QueryCtx
130 QueryCtx_SetParams(params);
131}
132
133static void AST_IncreaseRefCount
134(

Callers 1

parse_paramsFunction · 0.85

Calls 7

_AST_parse_result_rootFunction · 0.85
AR_EXP_FromASTNodeFunction · 0.85
rm_mallocFunction · 0.85
AR_EXP_EvaluateFunction · 0.85
SI_CloneValueFunction · 0.85
AR_EXP_FreeFunction · 0.85
QueryCtx_SetParamsFunction · 0.85

Tested by

no test coverage detected