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

Function Schema_GetConstraint

src/schema/schema.c:649–694  ·  view source on GitHub ↗

retrieves constraint returns NULL if constraint was not found

Source from the content-addressed store, hash-verified

647// retrieves constraint
648// returns NULL if constraint was not found
649Constraint Schema_GetConstraint
650(
651 const Schema *s, // schema from which to get constraint
652 ConstraintType t, // constraint type
653 const Attribute_ID *attrs, // constraint attributes
654 uint attr_count // number of attributes
655) {
656 // validations
657 ASSERT(s != NULL);
658 ASSERT(attrs != NULL);
659 ASSERT(attr_count > 0);
660
661 // search for constraint
662 uint n = array_len(s->constraints);
663 for(uint i = 0; i < n; i++) {
664 Constraint c = s->constraints[i];
665
666 // check constraint type
667 if(Constraint_GetType(c) != t) {
668 continue;
669 }
670
671 // make sure constraint attribute count matches
672 const Attribute_ID *c_attrs;
673 uint n = Constraint_GetAttributes(c, &c_attrs, NULL);
674 if(n != attr_count) {
675 continue;
676 }
677
678 // match each attribute
679 bool match = true; // optimistic
680 for(uint j = 0; j < n; j++) {
681 if(c_attrs[j] != attrs[j]) {
682 match = false;
683 break;
684 }
685 }
686
687 if(match == true) {
688 return c;
689 }
690 }
691
692 // no constraint was found
693 return NULL;
694}
695
696// get all constraints in schema
697const Constraint *Schema_GetConstraints

Callers 3

_Constraint_DropFunction · 0.85
_Constraint_CreateFunction · 0.85

Calls 3

array_lenFunction · 0.85
Constraint_GetTypeFunction · 0.85
Constraint_GetAttributesFunction · 0.85

Tested by

no test coverage detected