Auto-increment fields over ODBC (Postgres, MS SQL, Firebird): IsIdentity, EMULATEAUTONUM and the /AUTOINC driver string

Applies to: Clarion 6 (ABC, build 9058 as the poster wrote it; the C6.3 help is cited) with ODBC and DSN-less connections, as reported in 2011; targets named were Postgres, MS SQL 2008 and possibly Firebird.

Problem

A TPS-to-SQL conversion did all auto-incrementing client side. The developer wanted server-side identity fields, kept the dictionary usable for TPS, and had forms with child browses that need the parent's ID before the children are inserted. He asked what is needed in the DCT and whether /AUTOINC strings are driver specific.

Solution

  1. In the DCT, set the column option IsIdentity to true for the auto-increment column.
  2. In Table Properties, Options tab, add the property EMULATEAUTONUM as a boolean (true). Uncheck "Auto Number" on the Clarion primary key definition; the poster who gave this called it confusing.
  3. For Postgres, create the column as serial or bigserial. The sequence is then named like public.fred_id_seq (table fred, column id), and the file's Driver Options get /AUTOINC='SELECT currval(''public.fred_id_seq'')'.
  4. Choose one method: server side (sequence or serial) or client side (max(col)+1), not both.
  5. To keep one dictionary for TPS and SQL, one poster suggested leaving the key's auto-number on and deriving PrimeAutoinc to return for SQL files; CancelAutoinc needs the same treatment (untested idea). The original poster bypassed PrimeAutoinc with RETURN(Level:Benign) and used his own template to append the /autoinc string.

Caveats

  • Client side max(col)+1 has no gaps but two users completing forms at once collide. Server side suits many users, but a failed or cancelled insert leaves a gap in the numbers.
  • Clarion's own method adds a nearly blank row before the form is filled. A poster warned it prevents NOT NULL and foreign key constraints and leaves junk rows visible to reports meanwhile.
  • One poster called the emulate option "kind of obsolete" and preferred /AUTOINC; another recommended a memory table (IMDD) for child items, written to the backend on the parent's insert. The original poster concluded he needed both EMULATEAUTONUM and /AUTOINC. The thread gives no /AUTOINC string for MS SQL or Firebird.
  • Another poster advised choosing one backend, as SQL dialects differ in many small ways.

Today (2026)

Not re-tested. The IsIdentity and server-side options have changed since Clarion 6, so check the current help before copying the exact steps.

Sources: Trevor C. (Jul 2011, the question), Joshua B., Jon W., Sean H., Geoff T., Douglas J. (Jul 2011) in softvelocity.clarion.databasedrivers.