Notes on the IBX “Employee” Example

The project in “examples/employee” is intended to provide a worked example showing several useful IBX techniques. The example uses the “employee” database that is distributed with the Firebird Database Engine and provides an example Firebird Database. As this database is intended to demonstrate Firebird features, it includes many Check constraints and triggers – so many that it is not easy to add/edit or delete entries in the Employee table without falling foul of a check constraint or data integrity trigger. It does, however, make it easy to demonstrate the error handling features of IBX...

The example comprises one main form and two dialogs. The main form includes a TIBDatabase component, that identifies the employee database, a default transaction and a TIBQuery that selects all members of the employee table sorted by their Last Name. The query results set is shown as the contents of a TDBGrid.

The TIBQuery has its active property set to true in the Form's OnShow event handler. This forces the database connection to be opened including the prompt for a user name and password. Note that for a newly installed Firebird database server, the only user defined is the System Administrator (SYSDBA) with the password 'masterkey'.

A TIBDataset is used to provide the link to the “employee” table. This has a singleton select to select the row to be edited. The select query is parameterised and the required value of the primary key is set in the “BeforeOpen” event handler.

This query is supported by Update and Insert queries to allow the values to be edited. Two of the editable fields are implemented as Lookup Combo boxes. Each combo box has its own TIBQuery to select the lookup values.

The Date Picker is not a data aware control and is instead managed through TIBDataset event handlers. Any change to it forces the dataset into edit mode.

When the dialog closes any changes are “posted” and the TIBDataset closed.

Hint: Dept: Software Development and Country: USA are valid combinations for creating a new employee.

Explicit Transaction management is performed in this example. A transaction is started as soon as the database is opened in its “AfterConnect” event handler”. “Save” and “Cancel” buttons are enabled as soon as any changes are made to the dataset and these respectively Commit and Rollback the transaction.

Note that when the transaction ends, an asynchronous call is queued to restart the transaction and reopen the main dataset.

When the application terminates the default action is to commit the current transaction.