retrieves constraint returns NULL if constraint was not found
| 647 | // retrieves constraint |
| 648 | // returns NULL if constraint was not found |
| 649 | Constraint 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 |
| 697 | const Constraint *Schema_GetConstraints |
no test coverage detected