I would not do this. I would
begin swl
Select MAX ([table].[field])
from
[table]
into
:$max
end sql

On Wed, Sep 1, 2021 at 7:49 PM Randy Kaempen via 4D_Tech
<[email protected]> wrote:
>
> Paul,
>
> > On Sep 1, 2021, at 6:32 PM, Paul Chernoff via 4D_Tech 
> > <[email protected]> wrote:
> >
> > 4D 17.5
> >
> > Somehow when I create a new record for a table it wants to assign an
> > existing record’s primary key to a new record’s primary key field.
> >
> > How do I get the database to know that this value is already in use for
> > this unique field and to start incrementing primary key values starting at
> > a higher value?
>
> This code will fix the key for any integer or longint key.  Just pass a 
> pointer to the key field.
>
>   // FixAutoincrement  1/28/21
>   //
> C_POINTER($1)  // 1/28/16
> C_LONGINT($MaxValue)  // 1/29/16
>   //
> $FieldPtr:=$1  // 1/28/16
> $TablePtr:=Table(Table($FieldPtr))  // 1/9/21
>   //
> GET FIELD PROPERTIES($FieldPtr;$FieldType)  // 10/19/18
>   //
> If (($FieldType=8) | ($FieldType=9))  // Integer or Longint  10/19/18
>           //
>         $OldMaxValue:=Get database parameter($TablePtr->;Table sequence 
> number)  // 1/4/21
>           //
>         $TablePtr:=Table(Table($FieldPtr))  // 1/28/16
>                   //
>         ALL RECORDS($TablePtr->)  // 4/19/16
>         ORDER BY($TablePtr->;$FieldPtr->;<)  // Get highest value  4/19/16
>           //
>         $MaxValue:=$FieldPtr->  // 4/19/16
>           //
>         If ($MaxValue>$OldMaxValue)  // 1/22/21
>                 SET DATABASE PARAMETER($TablePtr->;Table sequence 
> number;$MaxValue)  // 12/19/16
>         End if   // 1/4/21
>           //
> End if   // Integer or Longint?  10/19/18
>
>
> Randy Kaempen
> Intellex Corporation
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> New Forum: https://discuss.4D.com
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[email protected]
> **********************************************************************



-- 
-----------------------------------------------------------------------------------------
 Chuck Miller Voice: (617) 739-0306 Fax: (617) 232-1064
 Informed Solutions, Inc.
 Brookline, MA 02446 USA Registered 4D Developer
       Providers of 4D, Sybase & SQL Server connectivity
          https://www.informed-solutions.com
-----------------------------------------------------------------------------------------
This message and any attached documents contain information which may
be confidential, subject to privilege or exempt from disclosure under
applicable law.  These materials are intended only for the use of the
intended recipient. If you are not the intended recipient of this
transmission, you are hereby notified that any distribution,
disclosure, printing, copying, storage, modification or the taking of
any action in reliance upon this transmission is strictly prohibited.
Delivery of this message to any person other than the intended
recipient shall not compromise or waive such confidentiality,
privilege or exemption from disclosure as to this communication.
**********************************************************************
4D Internet Users Group (4D iNUG)
New Forum: https://discuss.4D.com
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to