1. Kwadwo Boahene
  2. PowerBuilder
  3. Monday, 2 July 2018 16:22 PM UTC

Any ideas on how to generate a GUID in PB 2017 with DB2 as the database.

 

Thanks,

KB

Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 3 July 2018 20:51 PM UTC
  2. PowerBuilder
  3. # 1

My EmailSMTP uses the Windows API functions mentioned in other answers to generate a UUID.

http://www.topwizprogramming.com/freecode_emailsmtp.html

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Tuesday, 3 July 2018 08:28 AM UTC
  2. PowerBuilder
  3. # 2

Here another way with external functions:

// external functions

Function long UuidCreate ( Ref os_UUID pId ) Library "rpcrt4.dll"

Function long UuidToString ( Ref os_UUID Uuid, Ref ulong StringUuid ) Library "rpcrt4.dll" Alias For "UuidToStringW"

Function long RpcStringFree ( Ref ulong pString ) Library "rpcrt4.dll" Alias For "RpcStringFreeW"

Subroutine CopyMemory ( Ref string Destination, ulong Source, long Length ) Library  "kernel32.dll" Alias For "RtlMoveMemory"

 

// structure

type os_uuid from structure
    unsignedlong        data1
    integer        data2
    integer        data3
    blob        data4
end type

 

//Function of_generate_guid

os_UUID lstr_UUID
Constant Long RPC_S_OK = 0
Constant Long SZ_UUID_LEN = 36
ULong lul_ptrUuid
String ls_Uuid


lstr_UUID.Data4 = Blob(Space(8), EncodingAnsi!)
If UuidCreate(lstr_UUID) = RPC_S_OK Then
    If UuidToString(lstr_UUID, lul_ptrUuid) = RPC_S_OK Then
        ls_Uuid = Space(SZ_UUID_LEN)
        CopyMemory(ls_Uuid, lul_ptrUuid, SZ_UUID_LEN * 2)
        RpcStringFree(lul_ptrUuid)
        ls_Uuid = Upper(ls_Uuid)
    End If
End If

Return ls_Uuid

 

Comment
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Tuesday, 3 July 2018 06:18 AM UTC
  2. PowerBuilder
  3. # 3

1.  Create a global external function

FUNCTION long uuidCreate(ref s_uuid astr_uuid) LIBRARY "Rpcrt4.dll"  ALIAS FOR "UuidCreate"

*********************************************************************************************************************

2.  Create a global function f_generate_uuid

Function f_generate_uuid(String as_type)

Long ll_rc
s_uuid lstr_uuid
string ls_guid = ""
 
constant long RPC_S_OK = 0
constant long RPC_S_UUID_LOCAL_ONLY = 1824
constant long RPC_S_UUID_NO_ADDRESS = 1739
 
ll_rc = uuidCreate(lstr_uuid)
 
//  returns 
//   RPC_S_OK - The call succeeded.
//   RPC_S_UUID_LOCAL_ONLY - 
//     The UUID is guaranteed to be unique to this computer only.
//   RPC_S_UUID_NO_ADDRESS - 
//     Cannot get Ethernet/token-ring hardware address for this computer.
 
IF ll_rc <> RPC_S_OK THEN
    setNull(ls_GUID)
    // MessageBox("", "uuid create not ok ?!?")
ELSE
If as_type = 'F' Then
ls_GUID = right("00000000" + of_hex(lstr_uuid.data1), 8)
ls_GUID += "-" + right("0000" + of_hex(lstr_uuid.data2), 4)
ls_GUID += "-" + right("0000" + of_hex(lstr_uuid.data3), 4)
ls_GUID += "-" + right("0000" + of_hex(lstr_uuid.data4[1]), 4)
ls_GUID += "-" + right("0000" + of_hex(lstr_uuid.data4[2]), 4) &
+ right("0000" + of_hex(lstr_uuid.data4[3]), 4) &
+ right("0000" + of_hex(lstr_uuid.data4[4]), 4)
ls_GUID = upper(ls_GUID)
// MessageBox("", ls_guid)
// output example : 00003B93-2641-477A-C99E-A2FFEBEB214A
Elseif as_type = 'R' Then
ls_GUID = right("00000000" + of_hex(lstr_uuid.data1), 8)
ls_GUID += right("0000" + of_hex(lstr_uuid.data2), 4)
ls_GUID += right("0000" + of_hex(lstr_uuid.data3), 4)
ls_GUID += right("0000" + of_hex(lstr_uuid.data4[1]), 4)
ls_GUID += right("0000" + of_hex(lstr_uuid.data4[2]), 4) &
+ right("0000" + of_hex(lstr_uuid.data4[3]), 4) &
+ right("0000" + of_hex(lstr_uuid.data4[4]), 4)
ls_GUID = upper(ls_GUID)
End If
End If
Return ls_guid
**************************************************************************
 
3.  Call the above function
ls_uuid = f_generate_uuid('R')     // Without hypen in between
OR 
ls_uuid = f_generate_uuid('F')     // With hypen in between
 
Use this resultant value the way you want.
*********************************************************************
HTH
 
Happiness Always
BKR Sivaprakash
 
 
Comment
  1. Sivaprakash BKR
  2. Tuesday, 3 July 2018 06:28 AM UTC
Above code is PB code, which works irrespective of any database.

  1. Helpful
There are no comments made yet.
David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Monday, 2 July 2018 16:27 PM UTC
  2. PowerBuilder
  3. # 4

It seems that there are a number of way to generate GUID in DB2, have you looked at the link below:

https://www.ibm.com/developerworks/community/blogs/SQLTips4DB2LUW/entry/generating_universally_unique_identifiers_uuid63?lang=en

You should be able to utilise any of these methods within PB.

Regards

David

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.