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!
Unique ID
Re: Unique ID
FWH 11.08/FWH 19.03
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
- Rick Lipkin
- Posts: 2397
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
Re: Unique ID
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
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
//---------------------
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 )