FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Unique ID
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Unique ID
Posted: Fri Jun 09, 2017 01:00 AM

Hello,

Is there a function in FWH that creates a unique ID? I need to created a unique ID every time logs in to our system.

Thank you!

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Unique ID
Posted: Fri Jun 09, 2017 01:34 AM
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Unique ID
Posted: Fri Jun 09, 2017 01:10 PM
Darrell

Here is how I create my Sql Primary keys .. this routine creates a unique character .. you can easily adapt to numeric as well.. The process is not elegant but works.

Rick Lipkin

Code (fw): Select all Collapse
//---------------------
Static Func _GenTripsEid()

LOCAL nRAND, cRAND, oRs, cSQL, oERR

cSQL := "SELECT TRIPSEID from TRIPS"

oRs := TOleAuto():New( "ADODB.Recordset" )
oRs:CursorType     := 1        // opendkeyset
oRs:CursorLocation := 3        // local cache
oRs:LockType       := 3        // lockoportunistic

TRY
   oRs:Open( cSQL,oCn )
CATCH oErr
   MsgInfo( "Error in Opening TRIPS table to create TripsEid" )
   RETURN("BOGUS")
END TRY

cRAND := 'BOGUS'

DO WHILE .T.

   nRAND := nRANDOM(10000000000000000)

   // 1 is reserved and 0 is a null key //

   IF nRAND = 1 .or. nRAND = 0 .or. nRAND = NIL
      LOOP
   ENDIF

   cRAND := STR(nRAND,17)

   IF oRs:eof
   ELSE
      oRs:MoveFirst()
      oRs:Find("tripseid = '"+cRAND+"'" )
   ENDIF

   IF oRs:eof
      EXIT
   ELSE
      LOOP
   ENDIF

   EXIT

ENDDO

oRs:CLose()

RETURN( cRAND )

Continue the discussion