Unique ID

Unique ID

Postby cdmmaui » Fri Jun 09, 2017 1: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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Unique ID

Postby hua » Fri Jun 09, 2017 1:34 am

FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1070
Joined: Fri Oct 28, 2005 2:27 am

Re: Unique ID

Postby Rick Lipkin » Fri Jun 09, 2017 1: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: Select all  Expand view

//---------------------
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 )

 
User avatar
Rick Lipkin
 
Posts: 2657
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Cgallegoa and 67 guests