- DBCONSTRAINTTYPE_UNIQUE - A unique constraint.
- DBCONSTRAINTTYPE_FOREIGNKEY - A foreign key constraint.
- DBCONSTRAINTTYPE_PRIMARYKEY - A primary key constraint.
- DBCONSTRAINTTYPE_CHECK - A check constraint (not supported by the current SQL Compact versions)
- DBCONSTRAINTTYPE_SSCE_DEFAULT - Apparently this is a default value constraint. I have found no documentation about this constant and will investigate it later.
A foreign key definition is stored in the new CForeignKey class. You can see these classes being built from the array of DBCONSTRAINTDESC structures in the new CTableDefinition::FillForeignKeyArray function, where each array item is tested for the correct type and then fed to the CForeignKey class constructor, where all thework takes place. Each foreign key contains a list of matched columns from the reference table and the base table (each pair is stored in an instance of the CForeignKeyPair class).
Displaying these in the schema tree is quite straightforward and follows the same rules I have used for columns and indexes. Please note that there are new accessors for foreign keys on the CTableSchema class.
On my next post I will also enumerate primary keys and unique constraints, put them all under the same folder and start moving towards an on-device SQL Compact editor. I already got a name suggestion from Alberto Silva: SQL Explorer. More names, anyone?
Sample code: SchemaTree3.zip (1.2 MB)