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

Function Proc_ConstraintsInvoke

src/procedures/proc_list_constraints.c:171–223  ·  view source on GitHub ↗

CALL db.constraints()

Source from the content-addressed store, hash-verified

169
170// CALL db.constraints()
171ProcedureResult Proc_ConstraintsInvoke
172(
173 ProcedureCtx *ctx,
174 const SIValue *args,
175 const char **yield
176) {
177
178 ASSERT(ctx != NULL);
179 ASSERT(args != NULL);
180 ASSERT(yield != NULL);
181
182 // TODO: introduce invoke validation, similar to arithmetic expressions
183 // expecting no arguments
184 uint arg_count = array_len((SIValue *)args);
185 if(arg_count != 0) return PROCEDURE_ERR;
186
187 GraphContext *gc = QueryCtx_GetGraphCtx();
188
189 ConstraintsContext *pdata = rm_malloc(sizeof(ConstraintsContext));
190
191 pdata->gc = gc;
192 pdata->out = array_new(SIValue, 5);
193 pdata->constraints = array_new(Constraint, 0);
194
195 _process_yield(pdata, yield);
196
197 ctx->privateData = pdata;
198
199 //--------------------------------------------------------------------------
200 // collect constraints
201 //--------------------------------------------------------------------------
202
203 SchemaType schema_types[2] = {SCHEMA_NODE, SCHEMA_EDGE};
204
205 // foreach schema type
206 for(int i = 0; i < 2; i++) {
207 SchemaType schema_type = schema_types[i];
208 ushort n = GraphContext_SchemaCount(gc, schema_type);
209
210 // foreach schema
211 for(ushort j = 0; j < n; j++) {
212 Schema *s = GraphContext_GetSchemaByID(gc, j, schema_type);
213 const Constraint *cs = Schema_GetConstraints(s);
214 // foreach schema's constraint
215
216 for(uint32_t k = 0; k < array_len((Constraint*)cs); k++) {
217 array_append(pdata->constraints, cs[k]);
218 }
219 }
220 }
221
222 return PROCEDURE_OK;
223}
224
225ProcedureResult Proc_ConstraintsFree
226(

Callers

nothing calls this directly

Calls 7

array_lenFunction · 0.85
QueryCtx_GetGraphCtxFunction · 0.85
rm_mallocFunction · 0.85
GraphContext_SchemaCountFunction · 0.85
Schema_GetConstraintsFunction · 0.85
_process_yieldFunction · 0.70

Tested by

no test coverage detected