Auto Inc Fields in RAD Server with InterBase

by Apr 9, 2020

How to create Auto Incremental Fields in RAD Server with InterBase, FireDAC and TEMSDataSetResource

One key feature when asking a remote server to add a record is to get the new record ID value returned. Thankfully this is easily achieved with InterBase and FireDAC via RAD Server with TEMSDataSetResource

InterBase has a concept of Generators. These provide a unique sequential integer value that can be used to provide a primary key field value. You can create up to 32,767 Generators in an InterBase database, but typically you would create one for the database or create and name one for use per table.

FireDAC Query UpdateOptions AutoInc

Part of the FireDAC framework is the ability to treat database fields as Auto-Incremental Fields. For Databases that do not have an AutoIncremental field data type, you can set the UpdateOptions properties to define the Generator and key fields.

www.youtube.com/watch

The video uses a simple example with a Generator called G_STUDENT (named as it provides the ID to be used for the STUDENT table in the sample database.

With the query selected at design time, select the UpdateOptions property in the Object inspector. There are two properties to set.

  • AutoIncFields – Which you need to set to the field to be incremented.
  • GeneratorName – Which provides a drop down to the database generators for you to select from.

The other option to set is on the TEMSDataSetResource. Here, set the KeyFields to the Primary Key Field (ie for the example, STUDENT_ID)

While you don’t need to add the fields to the query using the FieldEditor (Right-click on the Query and select Fields Editor…), if you do, you will see the field is now set as an TFDAutoIncField, rather than a normal integer field.

To test the setup, you can either use SwaggerUI, or the REST Debugger. As this has been covered before in other posts, I will not repeat it here, but for quick reference, the video below starts at the point where testing of the end point happens using the REST Debugger.

www.youtube.com/watch

The post Auto Inc Fields in RAD Server with InterBase appeared first on Stephen Ball’s Technical Blog.