Delphi-RAG-Lint
← DL (drag-lint) · Field Repository

Your database fields, in one file you can diff.

A Delphi database application repeats every column many times: in the table, in the persistent fields of each form, in MAXLEN constants, in calculated-field and event code. The Field Repository keeps the facts about each field in one place, read from your Firebird database, and lets DL check everything else against it.

DL only reads Firebird. The single exception is a table change you ask for explicitly, and that runs only after a verified backup.

01 — The repository

One file per database

drag-lint repo init creates an empty repository, and repo seed-fb fills it from any Firebird database. The repository is one SQLite file per database, separate from the code index. It holds what the forms and the code need to know about each field: the column’s type and length, field properties, lookup wiring, and the code of calculated fields and field events.

repo backup writes it out as a text file you can keep in version control and compare line by line, so a change to a field shows up in a diff like a change to code. Several projects can point at the same repository with one project setting.

Field repository help

02 — Lint against it

Code that does not fit the table

With a repository in place, schema-aware rules check your code against the columns it talks to. MAXLEN constants, string literals, Copy counts, Size and the string fields of form files are compared with the real column lengths. Fields, SQL columns and accessors that name no column of a known table are reported, and so are type mismatches. An INSERT that leaves out a required column is an opt-in check.

Without a repository these rules stay silent rather than guess. They are part of the lint rules, in the IDE and on the command line alike.

Schema-aware lint · Unknown column, type mismatch, required not set

03 — Forms in, forms out

Read a form, write a form

Read. repo read-dfm reads the persistent fields of a form (data, calculated, lookup and aggregate fields), their lookup wiring and the code of OnCalcFields and OnGetText into the repository, from a text or a binary form file. For a dataset whose SQL joins tables, DL places each field on its own table and column, and lists any field it cannot place with the reason. Whatever the form does not state is reported, never guessed.

Write. repo write-dfm brings the persistent fields of a text form file, and their declarations in the unit, in line with the repository. It is a dry run by default. When you apply it, every byte outside a change stays the same, the new text is checked by Delphi’s own form reader before it is written, and a backup is kept.

Grids. repo read-grid (since 1.60) reads the columns of every TcxGridDBTableView and TDBGrid on a form into the repository: caption, field, width, editor and event names, and the columns bound to no field. Since 1.61 it also reads banded and layout views, with their bands and layout groups and each column’s place in them. repo write-grid adds the columns a grid lacks for its table, and in a banded or layout view puts them in their band or group, creating a missing one. It only adds: an existing column is never changed and nothing is deleted. Both are dry runs by default and keep a backup when you apply them. A real run, step by step.

In RAD Studio. Under drag-lint > Field Repository you can read the fields of one dataset or of every dataset on a form, or select the fields a dataset should have. Each command shows every change, old and new, before anything is written; you tick the ones you want and press Apply.

Generated code. Event code and MAXLEN constants can come from the repository too. DL writes them into marked, hash-checked regions of your existing units; a region edited by hand is reported and never overwritten, and everything outside the regions is kept byte for byte. Since 1.61, repo gen-calc writes a dataset’s calculated fields into its OnCalcFields handler in dependency order, and repo gen-events turns stored column event code into new grid column handlers; both are in the IDE menu too.

repo read-dfm · repo write-dfm · repo read-grid · repo write-grid · Fields of a form in the IDE · Generated handlers · repo gen-calc · repo gen-events · repo fib-readers · repo describe · repo lookup-source · repo gen-lookup-layer

04 — The database

Changing a table, carefully

When a column changes in the repository, repo alter-table makes one Firebird table match it. It prints the exact DDL first and writes nothing without --apply. A change Firebird would refuse, or would accept and lose data on, is blocked before anything runs; an opt-in safe path (add, copy, compare, swap) handles the changes Firebird refuses.

Before its first DDL statement, --apply backs the database up through the Firebird service API, restores the backup into a temporary database and compares it, so the backup is proven, not assumed. repo backup --connection does the same on demand, without gbak, and repo backup list and purge only ever touch the backups DL made.

repo alter-table · Verified database backups

05 — Shipped and planned

What comes next

Shipped in 1.62: repo describe, a read-only description of a table’s fields, with a Pascal reader unit for your own code; repo lookup-source, which finds the component a lookup field should read from, proven from the forms and the index; and repo write-grid --columns, which offers differing attributes of existing columns, written only when you select them.

Shipped in 1.63: repository schema 8, with column facts, index and enum tables and FIB$VERSION (repo migrate --apply takes a schema-7 file to 8; 1.61 and 1.62 cannot open a schema-8 file, so keep the backup it writes); repo gen-fib-consumer, which generates the code that reads one FIB$ table from the repository (help); repo write-grid into FDGridProvider grid views; and a lookup layer SDK with a conformance suite for your own tier-3 layer (help).

Shipped in 1.64: repo enum-candidates, which finds the columns, fields and properties that are really enums, scored from the code, the forms, the repository and the live database (help); repo enum-gen, which turns them into Delphi enums with record helpers and DUnitX round-trip tests, the stored code as the ordinal (help); and eight lint rules that compare forms and code with the repository, one on by default (repo-size-drift), seven off until we have measured them on more code.

Shipped in 1.65: repo adopt-regions, which marks the members of existing ORM units that match the generator for later updates (help); repo alter-table --to-bytetag, an isql script with a rollback that turns enum columns into bytes, never run (help); ORM units that store enums as bytes; and nine more repository rules, off by default.

Still planned, expected within the next two to three weeks; details may change:

  • Field lists for the designer from the repository, with no server running.
  • A one-time import that makes an existing application’s repository the single master.

The plans in more detail

We build and test the repository on HTR Micronite, our own Firebird-based production software.