Database code events

Add custom code at the database level, with the intent of modifying the behavior of your application's CRUD operations.

Database data events are carried out at the database level, but nevertheless they are implemented in the application layer. The intention is to make sure that data satisfies constraints, and passes referential integrity, etc. Code events allow you to check these before reaching the database engine. This prevents the database engine from returning an error at a later stage.

On generating the application code, the BAM implements by default these constraints that a database table may have:
  • Not null - to ensure that a column cannot have a NULL value
  • Unique - to ensure that all values in a column are different
  • Primary key - to ensure that a column (both not null and unique) uniquely identifies each row in a table
  • Foreign key - to ensure a column uniquely identifies a row/record in another table
  • Default - to set a default value for a column when no value is specified

SQL Check constraint

The SQL Check constraint you must handle in a code event. The Check constraint ensures that all values in a column satisfy a specific condition. This constraint is not part of the database meta-schema file (4dbx) and can not be implemented when the BAM generates code. For example, if you have a SQL CHECK constraint in your database creation/update script, such as:
CONSTRAINT CHK_Person CHECK (Age>=18)
this check is not implemented in your BAM application code. You must therefore code for this in your Check Table Constraints code event.

Otherwise, when the users inserts or updates data that violates this constraint, an error will be raised by the database engine. The recommended option is to check these constraints in code events instead of letting the database engine handle these errors.

Locate the event

Select a table in the diagram of the database meta-schema file (4dbx).

Code events are listed under Database Data Events in the Properties view.