next up previous contents
Next: Using the C++ Binding Up: Getting Started Previous: Adding indexes   Contents


Adding constraints

In the same way, you can add a notnull and an unique constraint on the lastname attribute within the class Person:
  1. add the constraint specification to the class Person within the person.odl file as follows:
    class Person {
      string firstname;
      string lastname;
      int age;
      Address addr;
      ...
    
      index on firstname;
      index on lastname;
      index on age;
      constraint<notnull> on lastname;
      constraint<unique> on lastname;
    };
    
  2. then, use the eyedbodl tool to update the database schema:
    % eyedbodl -U bill -P thekid -d foo -u --package=person person.odl
    Updating 'person' schema in database foo...
    Creating [NULL] notnull_constraint 'constraint<notnull, propagate = on> on Person.lastname' on class 'Person'...
    Creating [NULL] unique_constraint 'constraint<unique, propagate = on> on Person.lastname' on class 'Person'...
    
    Done
    
Now try to create two person instances with the same lastname attribute:
% eyedboql -U bill -P {bill password, i.e. 'thekid'} -d foo -w
? Person(lastname : "curtis");
= 6792.2.881020:oid
? Person(lastname : "curtis");
near line 3: 'Person()' => oql error: new operator <<new<oql\$db> Person()>> : notnull[] constraint error: attribute path 'Person.lastname'.
or with no lastname attribute:
? Person();
near line 3: 'Person()' => oql error: new operator <<new<oql\$db> Person()>> : notnull[] constraint error: attribute path 'Person.lastname'.



EyeDB manual