Power outages or not, that's a handy piece of code to have.
Thank you very much, Albert.

p.s. - need a comma after:  vIncrement DOUBLE = NULL +

On 10/25/2016 10:59 AM, Albert Berry wrote:
I developed this utility for a project where power outages are a bit too frequent. I thought some others might find it useful. (I used to do this by creating an autonum command for each and every table.)

-- UpdateAutonum.eep
-- Albert Berry 2016/10/24
-- Checks the sys_defaults table for columns that are autonumbered and
-- uses a cursor to reset the numbers
----------------------------------------------------------------------------
CLEAR VAR i1,vColName,vTabName,vNext,vIncrement,vCommand
SET VAR i1 INTEGER, +
    vColName TEXT = NULL, +
    vTabName TEXT = NULL, +
    vNext DOUBLE = NULL, +
    vIncrement DOUBLE = NULL +
    vCommand TEXT = NULL
-----------------------------------------------------------------------------
SET ERROR MESSAGE 705 OFF
DROP CURSOR c1
SET ERROR MESSAGE 705 ON
DECLARE c1 CURSOR +
  FOR SELECT t1.sys_increment, t2.sys_column_name, t3.sys_table_name +
    FROM sys_defaults t1, sys_columns t2, sys_tables t3 +
WHERE t1.sys_next IS NOT NULL AND t1.sys_column_id = t2.sys_column_id +
      AND t2.sys_table_id = t3.sys_table_id +
      AND t2.sys_column_name NOT LIKE "SYS%"
------------------------------------------------------------------------------
OPEN c1 RESET
FETCH c1 INTO vIncrement,vColName, vTabName
WHILE SQLCODE <> 100 THEN
  --  SET VAR vCommand =
  SELECT (MAX(&vColName) + .vIncrement) INTO vNext INDICATOR i1 +
    FROM &vTabName
  SET VAR vCommand =  +
      ("AUTONUM" & .vColName & "IN" & .vTabName & "USING"  & +
      CTXT(.vNext) +","+CTXT(.vIncrement))
  PAUSE 2 USING .vcommand
  &vCommand
  FETCH c1 INTO vIncrement,vColName, vTabName
ENDWHILE -- sqlcode
DROP CURSOR c1
LABEL Stop
RETURN



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
You received this message because you are subscribed to the Google Groups 
"RBASE-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to