Delphi-RAG-Lint

drag-lint help

Enum columns to D_BYTETAG: repo alter-table --to-bytetag

Since: 1.65.0-alpha

Plans CHAR(1)/SMALLINT enum columns -> D_BYTETAG as isql scripts with a rollback; byte = enum-gen ordinal; never runs DDL.

Read this to move enum columns to the byte domain. drag-lint repo alter-table --to-bytetag --in candidates.json --map "ORDERS.STATUS" --output plan writes alter.sql (guards, ADD, UPDATE CASE, copy check), rollback.sql and report.txt. The byte of a code is the repo enum-gen ordinal ('A' = 65, -1 = 255) unless --map gives another; dropping the old column and a map that sends two codes to one byte are BLOCKED until their own id is in --select. It opens no database.

How to run it

drag-lint repo alter-table --to-bytetag --in <enum-candidates.json> --map "<T.C>[=<TEnum>][:<CODE>=<BYTE>,...][;...]" [--select <ids|all|file>] --output <folder>

Full flag list: repo in the CLI reference.

Flags

FlagArgumentMeaningDefault
--to-bytetag
--in<enum-candidates.json>
--map"<T.C>[=<TEnum>][:<CODE>=<BYTE>,...][;...]"
--select<ids|all|file>
--output<folder>

Where to click

No IDE surface: this feature runs from the CLI (see How to run it).

Details

Since 1.65.0-alpha. ORM3 enum tool E3: plans the move of CHAR(1) / VARCHAR(1) / SMALLINT / INTEGER enum columns to the byte domain D_BYTETAG (BINARY(1)) and writes it as reviewable isql scripts. drag-lint never runs them: this mode opens no database and refuses --apply and --connection.

drag-lint repo alter-table --to-bytetag --in <enum-candidates.json> --map "<T.C>[=<TEnum>][:<CODE>=<BYTE>,...][;...]"
                           [--select <ids|all|file>] --output <folder>
  • --in is a file saved from repo enum-candidates --json (format enum-candidates/1): it carries each column's SQL type and the database's distinct values with their row counts.
  • --map names the columns to move, separated by ;. Each may name its Delphi enum type (=TStatus; default the column's repository ENUMTYPE, else the enum-gen type name) and codes with explicit bytes (:Z=78,#44=1; #nn is the character nn, for a code that is , ; or :).
  • The byte of a code is the repo enum-gen ordinal: 'A' = 65, an integer is itself, -1 = 255. The bytes the script writes are therefore the ordinals of the generated enum; --map codes override or add (marked (map)).

What is written (--output)

FileContent
alter.sqlSET BAIL ON; a check that D_BYTETAG exists; per selected column: a guard SELECT that stops on a stored value without a byte, ALTER TABLE T ADD C_BT D_BYTETAG, UPDATE T SET C_BT = CASE C WHEN 'A' THEN X'41' ... END WHERE C IS NOT NULL, a check that every non-NULL value got its byte; with drop-old-column selected: ALTER TABLE T DROP C and ALTER TABLE T ALTER COLUMN C_BT TO C
rollback.sqlthe undo, last column first: drop the byte copy, or (after a drop) rebuild the old type in C_CH from the bytes and swap it back
report.txtper column the map, the database values, each change with its state; refusals; what the input does not say; a summary line (also printed on standard output)

The guards are SELECT CAST('E3 STOP: ...' AS INTEGER) statements that fail on purpose when their check fails; with SET BAIL ON isql stops there. NULL stays NULL. Every file is 7-bit ASCII, CRLF, the same bytes for the same inputs.

Changes, BLOCKED and --select (the repo regen-plan convention)

  • bytetag-column:T.C -- add the byte column and copy. Selected by all (the default) unless the map sends two codes to one byte (N,Z -> 78): then it is BLOCKED (the old value cannot be told apart afterwards; the rollback restores the first code of each byte).
  • drop-old-column:T.C -- drop the old column and give the byte column its name. Always BLOCKED; it needs its own id in --select, and it is refused without its bytetag-column.
  • --select takes a comma list of ids and/or all, or a file with one per line.

Refused (exit 2, the column is left out)

A column not in the input; a type other than CHAR(1) / VARCHAR(1) / SMALLINT / INTEGER; a column that is already BINARY / D_BYTETAG; no code map (enum-gen made no enum for it -- low confidence, a multi-character code -- and --map gives no codes); a database value without a byte (Z=1: fix the data or map it); an unknown --select id.

Exit: 0 = scripts written with nothing BLOCKED left out, 1 BLOCKED changes not selected, 2 refused.

Not in the input -- check before running

NOT NULL, DEFAULT, CHECK constraints, the column position and character set; Firebird refuses to DROP a column that a key, index, view, procedure or trigger uses (RDB$DEPENDENCIES). The ORM units read the old type until repo update-orm / repo enum-gen follow (E2b).

Source: src\sql\DRagLint.FieldRepo.EnumAlter.pas (pure), src\cli\DRagLint.CLI.RepoAlter.pas. Test: tests\autotest\run_v165_ORMTC_enum_bytetag.ps1 (the planner harness, then the verb on the fixture).


All features | CLI reference | IDE menus